This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |