10929 | 2024-04-19 20:17:25 | zsombor | Túlcsordulás | cpp17 | Accepted 100/100 | 171ms | 17728 KiB |
#include <iostream>
#include <vector>
using namespace std;
using ull = unsigned long long;
int n, q, x, y, l;
string a, b;
vector <ull> pwr(4e5, 1);
vector <ull> h(4e5, 0);
ull hsh(int L, int R) {
L--;
ull ret = h[R];
if (L > -1) ret -= h[L] * pwr[R - L];
return ret;
}
bool check(int M) {
return hsh(x, x + M - 1) == hsh(y, y + M - 1);
}
void solve() {
cin >> x >> y >> l;
y += n;
int L = 0, R = l + 1, M;
while (R - L > 1) {
M = (L + R) / 2;
check(M) ? L = M : R = M;
}
cout << (R > l || a[x + R - 1] == '0' ? "1 " : "0 ");
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> a >> b >> q;
for (char c : b) a.push_back('1' - (c - '0'));
for (int i = 1; i < 2 * n; i++) pwr[i] = pwr[i - 1] * 3;
h[0] = a[0] - '0' + 1;
for (int i = 1; i < 2 * n; i++) h[i] = h[i - 1] * 3 + (a[i] - '0' + 1);
while (q--) solve();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 7ms | 14212 KiB | ||||
2 | Accepted | 7ms | 14404 KiB | ||||
subtask2 | 40/40 | ||||||
3 | Accepted | 7ms | 14620 KiB | ||||
4 | Accepted | 7ms | 14836 KiB | ||||
5 | Accepted | 8ms | 15044 KiB | ||||
6 | Accepted | 7ms | 15384 KiB | ||||
7 | Accepted | 7ms | 15332 KiB | ||||
8 | Accepted | 8ms | 15412 KiB | ||||
9 | Accepted | 8ms | 15336 KiB | ||||
subtask3 | 30/30 | ||||||
10 | Accepted | 7ms | 15340 KiB | ||||
11 | Accepted | 20ms | 15488 KiB | ||||
12 | Accepted | 63ms | 16444 KiB | ||||
13 | Accepted | 64ms | 16704 KiB | ||||
14 | Accepted | 118ms | 17280 KiB | ||||
15 | Accepted | 162ms | 17256 KiB | ||||
16 | Accepted | 159ms | 17252 KiB | ||||
17 | Accepted | 163ms | 17456 KiB | ||||
subtask4 | 30/30 | ||||||
18 | Accepted | 12ms | 15764 KiB | ||||
19 | Accepted | 34ms | 17488 KiB | ||||
20 | Accepted | 57ms | 16512 KiB | ||||
21 | Accepted | 97ms | 17404 KiB | ||||
22 | Accepted | 171ms | 17588 KiB | ||||
23 | Accepted | 156ms | 17592 KiB | ||||
24 | Accepted | 162ms | 17560 KiB | ||||
25 | Accepted | 159ms | 17564 KiB | ||||
26 | Accepted | 167ms | 17588 KiB | ||||
27 | Accepted | 163ms | 17588 KiB | ||||
28 | Accepted | 158ms | 17728 KiB |