답안 #857182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857182 2023-10-05T13:55:41 Z lolismek Brperm (RMI20_brperm) C++14
13 / 100
36 ms 262144 KB
#include "brperm.h"

#include <iostream>

using namespace std;

const long long NMAX = 5e5;
const long long LOGMAX = 19;

const long long B = 29;
const long long MOD = 1e9 + 7;

long long dp[NMAX + 1][LOGMAX + 1][LOGMAX + 1];
long long powB[NMAX + 1];

long long h[NMAX + 1];

void init(int n, const char s[]){
    powB[0] = 1;
    for(long long i = 1; i <= NMAX; i++){
        powB[i] = (1ll * powB[i - 1] * B) % MOD;
    }
    for(long long i = 1; i <= n; i++){
        h[i] = ((1ll * h[i - 1] * B) % MOD + (s[i - 1] - 'a' + 1)) % MOD;
    }
    long long pw = 1, pwind = 0;
    while(pw * 2 <= n){
        pw *= 2;
        pwind++;
    }
    for(long long k = pwind; k >= 0; k--){
        for(long long i = 1; i <= n; i++){
            dp[i][0][k] = (s[i - 1] - 'a' + 1);
        }
    }
    for(long long k = pwind; k >= 0; k--){
        for(long long j = 1; (1 << j) <= n; j++){
            for(long long i = 1; i <= n; i++){
                if(i + ((1 << j) - 1) * (1 << k) <= n){
                    dp[i][j][k] = ((1ll * dp[i][j - 1][k + 1] * powB[(1 << (j - 1))]) % MOD + dp[i + (1 << k)][j - 1][k + 1]) % MOD;
                }
            }
        }
    }

    return;
}

int query(int i, int k){
    ++i;
    long long H1 = dp[i][k][0];
    long long H2 = (1ll * h[i + (1 << k) - 1] + MOD - ((1l * h[i - 1] * powB[(1 << k)]) % MOD)) % MOD;
    return (H1 == H2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 5 ms 10724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 5 ms 10724 KB Output is correct
3 Runtime error 34 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 36 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 5 ms 10724 KB Output is correct
3 Runtime error 34 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -