답안 #858064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858064 2023-10-07T11:28:45 Z boris_mihov Brperm (RMI20_brperm) C++17
컴파일 오류
0 ms 0 KB
#include "brperm.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 500000 + 10;
const int MOD = 998244353;
const int MAXLOG = 20;

int n;
char s1[MAXN];
int base[3 * MAXN];

struct Sparse
{
    int normalHash[MAXN][MAXLOG];
    int danceHash[MAXN][MAXLOG][MAXLOG];

    void build()
    {
        for (int i = 0 ; i < n ; ++i)
        {
            normalHash[i][0] = s1[i] - 'a' + 1;
            for (int lgH = 0 ; lgH < MAXLOG ; ++lgH)
            {
                danceHash[i][0][lgH] = s1[i] - 'a' + 1;
            }
        }

        for (int lgLen = 1 ; (1 << lgLen) <= n ; ++lgLen)
        {
            for (int i = 0 ; i + (1 << lgLen) <= n ; ++i)
            {
                normalHash[i][lgLen] = (1LL * base[(1 << (lgLen - 1))] * normalHash[i][(lgLen - 1)] + 1LL * normalHash[i + (1 << (lgLen - 1))][(lgLen - 1)]) % MOD;
                for (int lgH = 0 ; lgH + 1 < MAXLOG ; ++lgH)
                {
                    danceHash[i][lgLen][lgH] = (1LL * base[1 << lgH] * danceHash[i][(lgLen - 1)][lgH + 1] + 1LL * danceHash[i + (1 << (lgLen - 1))][(lgLen - 1)][lgH + 1]) % MOD;
                }
            }        
        }
    }

    int query(int idx, int log)
    {
        assert(normalHash[idx][log][0] != 0);
        return normalHash[idx][log] == danceHash[idx][log][0];
    }
};

Sparse sparse;
void init(int N, const char S[]) 
{
    n = N;
    for (int i = 0 ; i < n ; ++i)
    {
        s1[i] = S[i];
    }

    base[0] = 1;
    for (int i = 1 ; i < 3 * MAXN ; ++i)
    {
        base[i] = (27LL * base[i - 1]) % MOD;
    }

    sparse.build();
}

int query(int idx, int log) 
{
    return sparse.query(idx, log);
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from brperm.cpp:5:
brperm.cpp: In member function 'int Sparse::query(int, int)':
brperm.cpp:48:36: error: invalid types 'int[int]' for array subscript
   48 |         assert(normalHash[idx][log][0] != 0);
      |                                    ^