听说正解是链表,然而被我暴力水过了

先开vector记录每个数在原串中出现的位置

之后对于每个匹配串的每一位,找比当前位置大的第一个当前元素是哪个,有就更新,没有就“NIE”

bzoj2083【Poi2010】Intelligence test

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int Mx=1000010;
vector <int> v[Mx];
int n,m,c[Mx],num[Mx];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
        v[c[i]].push_back(i);
    }
    scanf("%d",&m);
    while(m--)
    {
        int len,jud=1,p=-1;scanf("%d",&len);
        for(int i=1;i<=len;i++)
        {
            int a;scanf("%d",&a);
            if(jud==0) continue;
            vector<int>::iterator V=upper_bound(v[a].begin(),v[a].end(),p);
            if(V!=v[a].end()) p=*V;
            else jud=0;
        }
        if(jud==0) puts("NIE");
        else puts("TAK");
    }
    return 0;
}

 

相关文章:

  • 2021-08-04
  • 2021-12-13
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2021-05-17
  • 2022-02-05
  • 2021-09-06
猜你喜欢
  • 2022-03-06
  • 2021-08-29
  • 2021-06-21
  • 2021-07-06
  • 2021-10-25
  • 2021-11-11
  • 2021-09-07
相关资源
相似解决方案