bzoj 2083: [Poi2010]Intelligence test——vecto+二分

时间:2022-11-26 17:51:13

Description

霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列。Lyx很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算做很多练习,所以他希望你写一个程序来快速判断他的答案是否正确。

Input

第一行为一个整数m(1<=m<=1000000)第二行包括m个用空格分开的整数ai(1<=ai<=1000000),组成了最初的序列,第三行为一个整数n(1<=n<=1000000),表示n个Lyx经过一系列删除得到的序列,每个序列两行,第一行给出长度L(1<=L<=m),然后下一行为L个由空格分开的整数bi(1<=bi<=1000000)。

Output

共n行,如果Lyx的序列确实是由最初的序列删除一些数得到,就输出TAK,否则输出NIE。

Sample Input

7
1 5 4 5 7 8 6
4
5
1 5 5 8 6
3
2 2 2
3
5 7 8
4
1 5 7 4

Sample Output

TAK
NIE
TAK
NIE
—————————————————————————————
这道题我们就直接算每个数离当前位置最近的位置在哪就好了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using std::lower_bound;
std::vector<int>::iterator ly;
const int M=2e6+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
std::vector<int>q[M];
int n,m,k,p;
int main(){
n=read();
for(int i=;i<=n;i++) k=read(),q[k].push_back(i);
m=read();
for(int i=;i<=m;i++){
int now=;
bool flag=true;
k=read();
for(int j=;j<=k;j++){
p=read();
if(!flag) continue;
if(q[p].empty()){flag=false; continue;}
ly=upper_bound(q[p].begin(),q[p].end(),now);
if(ly==q[p].end()) flag=false;
else now=*ly;
}
if(flag) printf("TAK\n");
else printf("NIE\n");
}
return ;
}