当前位置:网站首页>P3500 [POI2010]TES-Intelligence Test(二分&离线)
P3500 [POI2010]TES-Intelligence Test(二分&离线)
2022-07-06 04:11:00 【Harris-H】
P3500 [POI2010]TES-Intelligence Test(二分&离线)
法1
vector 存每个数对应的位置。
然后对于每个查询串的每个位置,二分找到最小> l a s t last last 的。其实序列自动机的本质就是寻找下一个最小的位置,只不过序列自动机限制了字符集大小。
时间复杂度: O ( T m l o g m ) O(Tmlogm) O(Tmlogm)
#include <cstdio>
#include <vector>
using namespace std;
int poi;
bool yes;
vector <int> a[1000010];
int b[1000010];
int dd(int now,int l,int r)
{
int ans=-1;
while (l<=r)
{
int m=(l+r)/2;
if (a[now][m]>poi)
{
ans=a[now][m];
yes=true;
r=m-1;
}
else
l=m+1;
}
return ans;
}
int main()
{
int m;
scanf("%d",&m);
for (int i=1;i<=m;i++)
{
int t;
scanf("%d",&t);
a[t].push_back(i);
}
int T;
scanf("%d",&T);
while (T--)
{
bool flag=true;
int n;
poi=0;
scanf("%d",&n);
for (int j=1;j<=n;j++)
scanf("%d",&b[j]);
for (int j=1;j<=n;j++)
{
int now=b[j];
int l=0,r=a[now].size();
if (r==0)
{
flag=false;
break;
}
r--;
yes=false;
int ttt=dd(now,l,r);
if (yes)
poi=ttt;
else
{
flag=false;
break;
}
}
if (flag)
printf("TAK\n");
else
printf("NIE\n");
}
return 0;
}
法2
可以离线做,考虑建图做,先将对应数与查询串的第一个位置连边。
然后按顺序遍历模板串的位置 i i i ,对其下一个位置进行建边。
注意要去掉前面的连边,直接 h [ i ] = 0 h[i]=0 h[i]=0。
时间复杂度: O ( n + ∑ m ) O(n+\sum m) O(n+∑m)
// SeptEtavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#define re register
#define ll long long
#define il inline
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define pt(ch) putchar(ch)
#define pti(x) printf("%d",x)
using namespace std;
// c_ints
il int ci(){
re char ch;
while(!isdigit(ch=getchar()));
re int x= ch^'0';
while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
return x;
}
enum{
N=1000024};
class node{
public:
int nxt,pos;//pos是所属的序列id
}bow[N];
int tot;
int head[N];
il void add(int x,int y){
bow[++tot].nxt= head[x];
bow[tot].pos= y;
head[x]= tot;
}//邻接表,bow[x]表示数字x上的询问
int a[N];
int k[N],*p[N];
int d[N*2],*last=d;//指针存储
int cur[N];//询问序列当前位置
bool ok[N];//答案
int main(){
int m= ci();
rep(i,1,m) a[i]= ci();
int n= ci();
rep(i,1,n){
k[i]= ci();
//p[i]= last;
p[i] = new int[k[i]+1];
rep(j,1,k[i]) p[i][j]= ci();
//last+= k[i]+1;
add(p[i][1],i);//加入首项
}
rep(i,1,m){
int u= a[i];
int j= head[u];
head[u]= 0;//清除邻接表
for(;j;j=bow[j].nxt){
int t= bow[j].pos;
if( ++cur[t] == k[t] ) ok[t]= 1;//成功匹配
else add(p[t][cur[t]+1],t);//加入下一位
}
}
rep(i,1,n) puts(ok[i]?"TAK":"NIE");
return 0;
//end面()
}
边栏推荐
- Several important classes in unity
- ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
- C mouse event and keyboard event of C (XXVIII)
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- Explain in simple terms node template parsing error escape is not a function
- Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
- 【leetcode】22. bracket-generating
- Record the pit of NETCORE's memory surge
- 【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
- MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
猜你喜欢

颠覆你的认知?get和post请求的本质

MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0

Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)

C (XXIX) C listbox CheckedListBox Imagelist
![[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)](/img/8a/068faf3e8de642c9e3c4118e6084aa.jpg)
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)

Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM

About some basic DP -- those things about coins (the basic introduction of DP)

Fundamentals of SQL database operation

math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
![[adjustable delay network] development of FPGA based adjustable delay network system Verilog](/img/82/7ff7f99f5164f91fab7713978cf720.png)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
随机推荐
Data processing methods - smote series and adasyn
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
Stable Huawei micro certification, stable Huawei cloud database service practice
使用JS完成一个LRU缓存
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
Thread sleep, thread sleep application scenarios
Custom event of C (31)
hashlimit速率控制
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
查询mysql数据库中各表记录数大小
Leetcode32 longest valid bracket (dynamic programming difficult problem)
Basic use of MySQL (it is recommended to read and recite the content)
MySql數據庫root賬戶無法遠程登陸解决辦法
Conditionally [jsonignore]
Brief tutorial for soft exam system architecture designer | general catalog
MySql数据库root账户无法远程登陆解决办法
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
About some basic DP -- those things about coins (the basic introduction of DP)
Fundamentals of SQL database operation
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization