bzoj hash+map+set
先对原串分组hash,查询就是看某一区间内是否出现某值.
可以每个值存一个集合,保存这个值出现的位置.(也可以建可持久化值域线段树)
map<int,set<int> >很省事...
(Yes写成了YES,狂WA)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <map> 3 #include <set> 4 #define N 1000010 5 #define Mod 9999990000001LL 6 #define Base 100000007LL 7 using namespace std; 8 9 typedef unsigned long long dnt; 10 11 int n, m, k; 12 int buf[N]; 13 map<dnt,set<int> > mst; 14 15 dnt hash( int *a ) { 16 dnt rt=0; 17 for( int i=0; i<k; i++ ) 18 rt = (rt*Base + a[i]) % Mod; 19 return rt; 20 } 21 int main() { 22 scanf( "%d%d%d", &n, &m, &k ); 23 for( int i=1; i<=n; i++ ) 24 scanf( "%d", buf+i ); 25 for( int i=1; i<=n; i++ ) { 26 mst[hash(buf+i)].insert(i); 27 } 28 for( int t=1; t<=m; t++ ) { 29 int l, r; 30 scanf( "%d%d", &l, &r ); 31 for( int i=0; i<k; i++ ) 32 scanf( "%d", buf+i ); 33 r = r-k+1; 34 dnt v = hash(buf); 35 map<dnt,set<int> >::iterator it = mst.find(v); 36 if( it==mst.end() || it->second.lower_bound(l)==it->second.upper_bound(r) ) 37 printf( "Yes\n" ); 38 else 39 printf( "No\n" ); 40 } 41 }