#include "brperm.h"
#include <map>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int rvs_pos(int i, int k) {
int ans = 0;
for (int bt = 0; bt < k; ++bt) if (i & (1 << bt)) {
ans += 1 << (k - bt - 1);
}
return ans;
}
int n;
string s;
vector<int> blocks[20];
struct segment {
int layer;
int mod;
int l;
segment() {}
segment(int layer_, int mod_, int l_): layer(layer_), mod(mod_), l(l_) {}
int to_int() {
return blocks[layer][mod] + l;
}
segment operator+(const int& x) const {
return {layer, mod, l + x};
}
segment sub_even() {
if (l % 2) {
return {
layer + 1,
mod + (1 << layer),
l / 2
};
} else {
return {
layer + 1,
mod,
l / 2
};
}
}
segment sub_odd() {
if (l % 2) {
return {
layer + 1,
mod,
l / 2 + 1
};
} else {
return {
layer + 1,
mod + (1 << layer),
l / 2
};
}
}
};
void init(int n0, const char s0[]) {
n = n0;
s = "";
for (int bl = 0; (1 << bl) <= n; ++bl) {
for (int mod = 0; mod < (1 << bl); ++mod) {
blocks[bl].push_back(s.size());
for (int i = mod; i < n; i += (1 << bl))
s.push_back(s0[i]);
}
}
}
map<ll, bool> mp[20];
bool get_ans(segment a, segment b, int k) {
if (k == 0)
return s[a.to_int()] == s[b.to_int()];
ll hsh = 1ll * a.to_int() * n + b.to_int();
if (mp[k].find(hsh) != mp[k].end())
return mp[k][hsh];
bool even = get_ans(a.sub_even(), b, k - 1);
bool odd = get_ans(a.sub_odd(), b + (1 << (k - 1)), k - 1);
return mp[k][hsh] = (even & odd);
}
int query(int l, int k) {
if (l + (1 << k) > n)
return 0;
return get_ans({0, 0, l}, {0, 0, l}, k);
for (int i = 0; i < (1 << k); ++i) {
if (s[l + i] != s[l + rvs_pos(i, k)]) {
return 0;
}
}
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
Output is correct |
2 |
Correct |
7 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
Output is correct |
2 |
Correct |
7 ms |
1492 KB |
Output is correct |
3 |
Runtime error |
2960 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2833 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
Output is correct |
2 |
Correct |
7 ms |
1492 KB |
Output is correct |
3 |
Runtime error |
2960 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |