109292024-04-19 20:17:25zsomborTúlcsorduláscpp17Accepted 100/100171ms17728 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();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted7ms14212 KiB
2Accepted7ms14404 KiB
subtask240/40
3Accepted7ms14620 KiB
4Accepted7ms14836 KiB
5Accepted8ms15044 KiB
6Accepted7ms15384 KiB
7Accepted7ms15332 KiB
8Accepted8ms15412 KiB
9Accepted8ms15336 KiB
subtask330/30
10Accepted7ms15340 KiB
11Accepted20ms15488 KiB
12Accepted63ms16444 KiB
13Accepted64ms16704 KiB
14Accepted118ms17280 KiB
15Accepted162ms17256 KiB
16Accepted159ms17252 KiB
17Accepted163ms17456 KiB
subtask430/30
18Accepted12ms15764 KiB
19Accepted34ms17488 KiB
20Accepted57ms16512 KiB
21Accepted97ms17404 KiB
22Accepted171ms17588 KiB
23Accepted156ms17592 KiB
24Accepted162ms17560 KiB
25Accepted159ms17564 KiB
26Accepted167ms17588 KiB
27Accepted163ms17588 KiB
28Accepted158ms17728 KiB