用vector,二分。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #define maxn 1005000 using namespace std; int n,a[maxn],t,m,b[maxn]; vector <int> v[maxn]; int read() { char ch;int data=0; while (ch<'0' || ch>'9') ch=getchar(); while (ch>='0' && ch<='9') { data=data*10+ch-'0'; ch=getchar(); } return data; } int find(int x,int y) { int l=0,r=v[x].size()-1,ans=-1; while (l<=r) { int mid=l+r>>1; if (v[x][mid]>y) {ans=v[x][mid];r=mid-1;} else l=mid+1; } return ans; } void work() { m=read();int ret=0; for (int i=1;i<=m;i++) b[i]=read(); for (int i=1;i<=m;i++) { ret=find(b[i],ret); if (ret==-1) {printf("NIE ");return;} } printf("TAK "); } int main() { n=read(); for (int i=1;i<=n;i++) { a[i]=read(); v[a[i]].push_back(i); } t=read(); for (int i=1;i<=t;i++) work(); return 0; }