답안 #1070259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070259 2024-08-22T12:32:25 Z AdamGS Brperm (RMI20_brperm) C++17
100 / 100
2316 ms 163628 KB
#include "brperm.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll MOD=694202137, PI=2137;
const int LIM=5e5+7, LG=20;
int hsh[LIM][LG], hshp[LIM][LG], tmp[LIM][LG], tmp2[LIM][LG], pot[2*LG], n;
void init(int _n, const char s[]) {
	n=_n;
	pot[0]=PI;
	rep(i, 2*LG-1) pot[i+1]=((ll)pot[i]*(ll)pot[i])%MOD;
	rep(i, n) hsh[i][0]=hshp[i][0]=s[i];
	for(int i=1; i<LG; ++i) {
		rep(j, n) if(j+(1<<i)<=n) {
			hsh[j][i]=((ll)hsh[j][i-1]+(ll)hsh[j+(1<<(i-1))][i-1]*(ll)pot[i-1])%MOD;
		}
	}
	rep(i, n) rep(j, LG) tmp[i][j]=s[i];
	for(int i=1; i<LG; ++i) {
		for(int j=0; j<LG-1; ++j) {
			rep(l, n) if(l+(1<<i)<=n) {
				tmp2[l][j]=((ll)tmp[l][j+1]+(ll)tmp[l+(1<<(i-1))][j+1]*(ll)pot[j])%MOD;
			}
		}
		rep(l, n) hshp[l][i]=tmp2[l][0];
		rep(l, LG) rep(j, n) {
			tmp[j][l]=tmp2[j][l];
			tmp2[j][l]=0;
		}
	}
}
int query(int i, int k) {
	if(i+(1<<k)>n) return 0;
	return hsh[i][k]==hshp[i][k];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 256 ms 35620 KB Output is correct
4 Correct 240 ms 35620 KB Output is correct
5 Correct 231 ms 35624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2316 ms 162856 KB Output is correct
2 Correct 2216 ms 163628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 256 ms 35620 KB Output is correct
4 Correct 240 ms 35620 KB Output is correct
5 Correct 231 ms 35624 KB Output is correct
6 Correct 2316 ms 162856 KB Output is correct
7 Correct 2216 ms 163628 KB Output is correct
8 Correct 2213 ms 163228 KB Output is correct
9 Correct 2267 ms 163220 KB Output is correct
10 Correct 2259 ms 163404 KB Output is correct