Submission #401623

#TimeUsernameProblemLanguageResultExecution timeMemory
401623maximath_1Brperm (RMI20_brperm)C++17
100 / 100
1710 ms64352 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...