fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int od[1000006];
  5. vector<int> tab[1000006];
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(0);
  10. int n,m,x;
  11. cin >> n;
  12. for(int i = 0;i < n;++i)
  13. {
  14. cin >> x;
  15. tab[x].push_back(i);
  16. }
  17. cin >> m;
  18. for(int i = 0;i < m;++i)
  19. {
  20. cin >> n; vector<int> tab1;
  21. for(int j = 1;j <= 1000000;++j)
  22. {
  23. od[j] = 0;
  24. }
  25. for(int j = 1;j <= n;++j)
  26. {
  27. cin >> x;
  28. tab1.push_back(x);
  29. }
  30. //vector<int> tab1;
  31. bool p = 0;
  32. for(int j = 0;j < n;++j)
  33. {
  34. auto k = lower_bound(od[tab1[j]]+tab[tab1[j]].begin(),tab[tab1[j]].end(),j);
  35. //cout << k-tab[tab1[j]].begin() << ' ' << od[tab1[j]] << endl;
  36. if(k == tab[tab1[j]].end())
  37. {
  38. cout << "NIE" << endl;
  39. p = 1;
  40. break;
  41. }
  42. od[tab1[j]] = k-tab[tab1[j]].begin()+1;
  43. //cout << od[j] << ' ';
  44. }
  45. if(!p)
  46. cout << "TAK" << endl;
  47.  
  48. }
  49. }
Success #stdin #stdout 0.01s 30960KB
stdin
20
1 1 2 4 2 1 3 3 4 2 3 5 2 1 1 4 2 1 1 3
1
6
3 3 5 4 4 4
stdout
TAK