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 <bits/stdc++.h>
#include "brperm.h"
using namespace std;
const int MX = 500005;
int n;
char ss[MX];
int cnt[MX][27];
pair<int, int> pc[MX];
void init(int N, const char s[]){
n = N;
for(int i = 0; i < n; i ++)
ss[i] = s[i];
for(int i = 0, j, cnt, rs; i < n; i ++){
j = i; cnt = rs = 0;
for(; j > 0; j /= 2, cnt ++)
rs = (rs << 1) + (j % 2);
pc[i] = make_pair(rs, cnt);
}
for(int i = 0; i < n; i ++){
if(i > 0){
for(int j = 0; j < 26; j ++)
cnt[i][j] = cnt[i - 1][j];
}
cnt[i][s[i] - 'a'] ++;
}
}
inline int get(int x, int k){
return pc[x].first * (1 << (k - pc[x].second));
}
int query(int i, int k){
if(i + (1 << k) - 1 >= n) return 0;
for(int j = 0; j < 26; j ++)
if(cnt[i + (1 << k) - 1][j] - (i == 0 ? 0 : cnt[i - 1][j]) == (1 << k))
return 1;
for(int j = i; j < i + (1 << k); j ++)
if(ss[j] != ss[i + get(j - i, k)]) return 0;
return 1;
}
# | 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... |