Submission #494403

# Submission time Handle Problem Language Result Execution time Memory
494403 2021-12-15T11:57:10 Z jasen_penchev Brperm (RMI20_brperm) C++14
0 / 100
248 ms 262148 KB
#include "brperm.h"
#include <iostream>
#define endl '\n'
using namespace std;

const int MAXN = 500000;
const int LOG = 20;
const int BASE = 26;
const int MOD1 = 1000000007;
const int MOD2 = 1000000009;

int n;
int pw[MAXN + 5][2];

struct Hash
{
    int len;
    int num1, num2;
};

Hash operator + (Hash h1, Hash h2)
{
    Hash ret;
    ret.len = h1.len + h2.len;
    ret.num1 = (1ll * h1.num1 * pw[h2.len][0] + h2.num1) % MOD1;
    ret.num2 = (1ll * h1.num2 * pw[h2.len][1] + h2.num2) % MOD2;
    return ret;
}

bool operator == (Hash h1, Hash h2)
{
    return (h1.len == h2.len and h1.num1 == h2.num1 and h1.num2 == h2.num2);
}

Hash h1[MAXN + 5][LOG + 5];
Hash h2[MAXN + 5][LOG + 5];

void init(int n0, const char s[])
{
    n = n0;

    pw[0][0] = pw[0][1] = 1;
    for (int i = 1; i <= MAXN; ++ i)
    {
        pw[i][0] = (1ll * pw[i - 1][0] * BASE) % MOD1;
        pw[i][1] = (1ll * pw[i - 1][1] * BASE) % MOD2;
    }

    for (int i = 0; i < n; ++ i)
    {
        h1[i][0].len = 1;
        h1[i][0].num1 = h1[i][0].num2 = s[i] - 'a';
    }

    for (int j = 1; j <= LOG; ++ j)
    {
        for (int i = 0; i < n - (1ll << (j - 1)); ++ i)
        {
            h1[i][j] = h1[i][j - 1] + h1[i + (1ll << (j - 1))][j - 1];
        }
    }

    for (int j = 0; j <= LOG; ++ j)
    {
        for (int i = 0; i < n; ++ i)
        {
            h2[i][j].len = 1;
            h2[i][j].num1 = h2[i][j].num2 = s[i] - 'a';
        }
        for (int k = j - 1; k >= 0; -- k)
        {
            for (int i = 0; i < n - (1ll << k); ++ i)
            {
                //h2[i][j] = h2[i][j] + h2[i + (1ll << k)][j];
            }
        }
    }

    return;
}

int query(int pos, int k)
{
    if (pos + (1ll << k) > n) return 0;
    return (h1[pos][k] == h2[pos][k]);
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4812 KB Output isn't correct
2 Halted 0 ms 0 KB -