Since the length of the inquiry is deterministic, we can get a hash of all strings of length k so that the string exists and the hash value exists.
Naturally overflow hash, base=107 relatively good.
Sequence length n=>n-k+1
Enquiry interval [x,y]=>[x,y-k+1]
Pay attention to the special x whether >y-k+1
Then we notice that there is no modification, so the hash value is discretized and the team is good.
#include <cstdio> #include <cmath> #include <algorithm>using namespace std;typedef unsigned long long Ull;int f,c;inline void R (int &x) {c=0;f=1; for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') f=-1; for (x=0; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) (x*=10) + = (c ' 0 '); X*=f;} #define N 200001#define seed 107ull seedk=1;int n,m,k,a[n<<1],c[n],en,en2,x;int Num[n],b[n<<1],sum=1;bool Anss[n];struct point{ull v;int p;} T[n<<1];struct ask{int l,r,x,p;} Q[n];bool operator < (const point &a,const point &b) {return A.V<B.V;} BOOL operator < (const ask &a,const ask &b) {return NUM[A.L]!=NUM[B.L]? NUM[A.L]<NUM[B.L]: A.R<B.R;} void Mo_make_block () {int sum=1,sz=sqrt (n); if (!sz) sz=1; for (; sum*sz<n;++sum) {int r=sum*sz; for (int i= (sum-1) *sz+1;i<=r;++i) num[i]=sum; } for (int i= (sum-1) *sz+1;i<=n;++i) num[i]=sum;} int main () {R (n); R (m); R (K); for (int i=1;i<=k;++i) seedk=seedk*seed;for (int i=1;i<=n;++i) R (C[i]), ull hs=0;for (int i=1;i<=k;++i) hs=hs*seed+ (ull) c[i];for (int i=k+1;i<=n;++i) {T[++EN].V =HS; t[en].p=en; Hs=hs*seed+ (ull) c[i]; HS-=C[EN]*SEEDK; }T[++EN].V=HS; T[en].p=en;int record=en;for (int i=1;i<=m;++i) {R (Q[I].L); R (Q[I].R); Q[i].p=i; q[i].r=q[i].r-k+1; hs=0; for (int j=1;j<=k;++j) {R (X); Hs=hs*seed+ (ull) X; } t[++en].v=hs; t[en].p=en; }sort (t+1,t+en+1); a[t[1].p]=++en2; for (int i=2;i<=en;++i) {if (T[I].V!=T[I-1].V) ++en2; A[t[i].p]=en2; } En=record; for (int i=1;i<=m;++i) Q[i].x=a[++en]; Mo_make_block (); sort (q+1,q+m+1); for (int i=q[1].l;i<=q[1].r;++i) ++b[a[i]]; if (Q[1].L<=Q[1].R) anss[q[1].p]=b[q[1].x]; else anss[q[1].p]=0; for (int. i=2;i<=m;++i) {if (Q[I].L<Q[I-1].L) for (int j=q[i-1].l-1;j>=q[i].l;--j) ++B[A[J]; else for (int j=q[i-1].l;j<q[i].l;++j)--b[a[j]]; if (Q[I].R<Q[I-1].R) for (int j=q[i-1].r;j>q[i].r;--j)--b[a[j]]; else for (int j=q[i-1].r+1;j<=q[i].r;++j) ++b[a[j]]; if (Q[I].L<=Q[I].R) anss[q[i].p]=b[q[i].x]; else anss[q[i].p]=0; } for (int i=1;i<=m;++i) puts (Anss[i]? " No ":" Yes "); return 0;}
"String Hash" "Mo Team Algorithm" bzoj3207 flower God's taunt plan Ⅰ