답안 #493628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493628 2021-12-12T12:14:18 Z Jeff12345121 Brperm (RMI20_brperm) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "brperm.h"
using namespace std;



const int nmax = 500005;
int n;
char c[nmax];
int revpre[nmax][20];
int rev(int x, int k) {
    int res = 0,cnt = 0;
    for (int i = k - 1; i >= 0; i--) {
        if (x & (1 << i)) res += (1 << cnt);
        cnt++;
    }
    return res;
}
void init(int N, const char C[]) {
    n = N;
    for (int k = 0; k < 20; k++) {
        for (int i = 0; i < n; i++) {
            revpre[i][k] = rev(i,k);
        }
    }
    for (int i = 0; i < N; i++) {
        c[i] = C[i];
    }
}

int qpre[nmax][20];
int query(int i, int k) {
    if (i + (1 << k) - 1 >= n) return 0;
    if (qpre[i][k] != 0) return qpre[i][k] - 1;

    int limit = i + (1 << (k - 1) - 1;
    for (int j = i; j <= limit; j++) {
        if (c[j] != c[revpre[j - i][k] + i]) return (qpre[i][k] = 1) - 1;
    }
    return (qpre[i][k] = 2) - 1;
}

Compilation message

brperm.cpp: In function 'int query(int, int)':
brperm.cpp:36:35: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   36 |     int limit = i + (1 << (k - 1) - 1;
      |                           ~~~~~~~~^~~
brperm.cpp:36:38: error: expected ')' before ';' token
   36 |     int limit = i + (1 << (k - 1) - 1;
      |                     ~                ^
      |                                      )