#include "brperm.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 1004535809
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
#define N 500005
int BASE=13131;
int base[20],h1[N][20],h2[N][20],b[N][20],t[N],n;
void init(int _n, const char s[])
{
n=_n;
base[19]=BASE; for(int i=18;i>=0;i--) base[i]=mul(base[i+1],base[i+1]);
for(int i=0;i<20;i++)
{
b[0][i]=1;
for(int j=1;j<N;j++) b[j][i]=mul(b[j-1][i],base[i]);
}
for(int i=0;i<=19;i++)
{
t[0]=s[0]; for(int j=1;j<n;j++) t[j]=add(mul(t[j-1],base[i]),s[j]);
h1[0][i]=t[(1<<i)-1];
for(int j=1;j+(1<<i)-1<n;j++) h1[j][i]=sub(t[j+(1<<i)-1],mul(t[j-1],b[1<<i][i]));
}
for(int i=0;i<n;i++) h2[i][0]=s[i];
for(int j=1;j<20;j++) for(int i=0;i+(1<<j)-1<n;i++) h2[i][j]=add(mul(h2[i][j-1],base[j]),h2[i+(1<<(j-1))][j-1]);
}
int query(int i, int k) {return i+(1<<k)-1<n&&h1[i][k]==h2[i][k];}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
39620 KB |
Output is correct |
2 |
Correct |
83 ms |
39636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
39620 KB |
Output is correct |
2 |
Correct |
83 ms |
39636 KB |
Output is correct |
3 |
Correct |
166 ms |
56828 KB |
Output is correct |
4 |
Correct |
149 ms |
56652 KB |
Output is correct |
5 |
Correct |
153 ms |
56648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
547 ms |
126436 KB |
Output is correct |
2 |
Correct |
539 ms |
126080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
39620 KB |
Output is correct |
2 |
Correct |
83 ms |
39636 KB |
Output is correct |
3 |
Correct |
166 ms |
56828 KB |
Output is correct |
4 |
Correct |
149 ms |
56652 KB |
Output is correct |
5 |
Correct |
153 ms |
56648 KB |
Output is correct |
6 |
Correct |
547 ms |
126436 KB |
Output is correct |
7 |
Correct |
539 ms |
126080 KB |
Output is correct |
8 |
Correct |
536 ms |
126144 KB |
Output is correct |
9 |
Correct |
520 ms |
126020 KB |
Output is correct |
10 |
Correct |
519 ms |
126068 KB |
Output is correct |