답안 #680403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680403 2023-01-10T17:37:21 Z bashkort Crossing (JOI21_crossing) C++17
100 / 100
1926 ms 41608 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

string cross(string &a, string &b) {
    string res(a.size(), 'a');
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] == b[i]) {
            res[i] = a[i];
        } else {
            res[i] = 'J' ^ 'O' ^ 'I' ^ a[i] ^ b[i];
        }
    }
    return res;
}

constexpr int MOD[]{1000'000'000 + 7, 228228227, 998244353, 1000'000'000 + 9, 10696969};
constexpr int P = 239, hsz = size(MOD);

constexpr int N = 2e5 + 1;

struct Info {
    array<int, hsz> h{}, power{}, sum{};

    Info() = default;
};

vector<Info> t;
vector<int> tag;
int sz;

void apply(int x, int y) {
    if (y != -1) {
        for (int i = 0; i < hsz; ++i) {
            t[x].h[i] = 1LL * t[x].sum[i] * y % MOD[i];
        }
        tag[x] = y;
    }
}

void push(int x) {
    apply(x << 1, tag[x]);
    apply(x << 1 | 1, tag[x]);
    tag[x] = -1;
}

void pull(int x) {
    for (int i = 0; i < hsz; ++i) {
        t[x].h[i] = (t[x << 1].h[i] + 1LL * t[x << 1].power[i] * P % MOD[i] * t[x << 1 | 1].h[i]) % MOD[i];
        t[x].power[i] = 1LL * t[x << 1].power[i] * t[x << 1 | 1].power[i] % MOD[i] * P % MOD[i];
        t[x].sum[i] = (t[x << 1].sum[i] + 1LL * t[x << 1].power[i] * P % MOD[i] * t[x << 1 | 1].sum[i]) % MOD[i];
    }
}

int to_int(char c) {
    return c == 'J' ? 0 : 1 + (c == 'O');
}

void init(int n, string T) {
    sz = 1 << __lg(n) + bool(n & (n - 1));
    tag.assign(sz << 1, -1), t.resize(sz << 1);

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < hsz; ++j) {
            t[i + sz].sum[j] = t[i + sz].power[j] = 1;
            t[i + sz].h[j] = to_int(T[i]);
        }
    }
    for (int i = sz - 1; i > 0; --i) {
        pull(i);
    }
}

void rangeApply(int l, int r, int tg, int x = 1, int lx = 0, int rx = sz) {
    if (l >= rx || lx >= r) {
        return;
    }
    if (l <= lx && rx <= r) {
        apply(x, tg);
        return;
    }

    push(x);

    int mid = (lx + rx) >> 1;

    rangeApply(l, r, tg, x << 1, lx, mid), rangeApply(l, r, tg, x << 1 | 1, mid, rx);

    pull(x);
}

array<int, hsz> hashed(string &s) {
    array<int, hsz> ans{};
    for (int i = int(s.size()) - 1; i >= 0; --i) {
        for (int j = 0; j < hsz; ++j) {
            ans[j] = (1LL * ans[j] * P + to_int(s[i])) % MOD[j];
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    string A, B, C;
    cin >> A >> B >> C;

    unordered_set<string> every{A, B, C};

    queue<string> qu;
    qu.push(A), qu.push(B), qu.push(C);

    while (!qu.empty()) {
        string s = qu.front();
        qu.pop();

        for (string to : every) {
            string res = cross(s, to);

            if (!every.count(res)) {
                qu.push(res);
                every.insert(res);
            }
        }
    }

    set<array<int, hsz>> st;
    for (string s : every) {
        st.insert(hashed(s));
    }

    int q;
    cin >> q;

    string T;
    cin >> T;

    init(n, T);

    cout << (st.count(t[1].h) ? "Yes\n" : "No\n");

    while (q--) {
        int l, r;
        char c;
        cin >> l >> r >> c;

        rangeApply(l - 1, r, to_int(c));

//        assert(t[1].h == hashed(T));
        cout << (st.count(t[1].h) ? "Yes\n" : "No\n");
    }

    return 0;
}

Compilation message

Main.cpp: In function 'std::string cross(std::string&, std::string&)':
Main.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'void init(int, std::string)':
Main.cpp:61:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   61 |     sz = 1 << __lg(n) + bool(n & (n - 1));
      |               ~~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 780 KB Output is correct
2 Correct 452 ms 904 KB Output is correct
3 Correct 492 ms 908 KB Output is correct
4 Correct 390 ms 844 KB Output is correct
5 Correct 375 ms 860 KB Output is correct
6 Correct 361 ms 844 KB Output is correct
7 Correct 381 ms 904 KB Output is correct
8 Correct 394 ms 844 KB Output is correct
9 Correct 418 ms 856 KB Output is correct
10 Correct 403 ms 912 KB Output is correct
11 Correct 425 ms 992 KB Output is correct
12 Correct 404 ms 880 KB Output is correct
13 Correct 423 ms 812 KB Output is correct
14 Correct 399 ms 1116 KB Output is correct
15 Correct 431 ms 2368 KB Output is correct
16 Correct 381 ms 2408 KB Output is correct
17 Correct 381 ms 2388 KB Output is correct
18 Correct 471 ms 2372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 780 KB Output is correct
2 Correct 452 ms 904 KB Output is correct
3 Correct 492 ms 908 KB Output is correct
4 Correct 390 ms 844 KB Output is correct
5 Correct 375 ms 860 KB Output is correct
6 Correct 361 ms 844 KB Output is correct
7 Correct 381 ms 904 KB Output is correct
8 Correct 394 ms 844 KB Output is correct
9 Correct 418 ms 856 KB Output is correct
10 Correct 403 ms 912 KB Output is correct
11 Correct 425 ms 992 KB Output is correct
12 Correct 404 ms 880 KB Output is correct
13 Correct 423 ms 812 KB Output is correct
14 Correct 399 ms 1116 KB Output is correct
15 Correct 431 ms 2368 KB Output is correct
16 Correct 381 ms 2408 KB Output is correct
17 Correct 381 ms 2388 KB Output is correct
18 Correct 471 ms 2372 KB Output is correct
19 Correct 1649 ms 38768 KB Output is correct
20 Correct 1834 ms 38884 KB Output is correct
21 Correct 1126 ms 38492 KB Output is correct
22 Correct 1048 ms 38264 KB Output is correct
23 Correct 800 ms 5552 KB Output is correct
24 Correct 791 ms 5560 KB Output is correct
25 Correct 1119 ms 38740 KB Output is correct
26 Correct 1176 ms 39016 KB Output is correct
27 Correct 1401 ms 38860 KB Output is correct
28 Correct 1659 ms 38740 KB Output is correct
29 Correct 1455 ms 38756 KB Output is correct
30 Correct 931 ms 5432 KB Output is correct
31 Correct 1490 ms 38748 KB Output is correct
32 Correct 1558 ms 38432 KB Output is correct
33 Correct 878 ms 5376 KB Output is correct
34 Correct 1464 ms 38732 KB Output is correct
35 Correct 1169 ms 37912 KB Output is correct
36 Correct 914 ms 5380 KB Output is correct
37 Correct 1127 ms 5280 KB Output is correct
38 Correct 1695 ms 38484 KB Output is correct
39 Correct 997 ms 38712 KB Output is correct
40 Correct 1122 ms 21692 KB Output is correct
41 Correct 1926 ms 38952 KB Output is correct
42 Correct 570 ms 38084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 780 KB Output is correct
2 Correct 452 ms 904 KB Output is correct
3 Correct 492 ms 908 KB Output is correct
4 Correct 390 ms 844 KB Output is correct
5 Correct 375 ms 860 KB Output is correct
6 Correct 361 ms 844 KB Output is correct
7 Correct 381 ms 904 KB Output is correct
8 Correct 394 ms 844 KB Output is correct
9 Correct 418 ms 856 KB Output is correct
10 Correct 403 ms 912 KB Output is correct
11 Correct 425 ms 992 KB Output is correct
12 Correct 404 ms 880 KB Output is correct
13 Correct 423 ms 812 KB Output is correct
14 Correct 399 ms 1116 KB Output is correct
15 Correct 431 ms 2368 KB Output is correct
16 Correct 381 ms 2408 KB Output is correct
17 Correct 381 ms 2388 KB Output is correct
18 Correct 471 ms 2372 KB Output is correct
19 Correct 441 ms 896 KB Output is correct
20 Correct 542 ms 848 KB Output is correct
21 Correct 397 ms 812 KB Output is correct
22 Correct 345 ms 836 KB Output is correct
23 Correct 393 ms 892 KB Output is correct
24 Correct 372 ms 868 KB Output is correct
25 Correct 391 ms 1028 KB Output is correct
26 Correct 358 ms 788 KB Output is correct
27 Correct 371 ms 844 KB Output is correct
28 Correct 334 ms 864 KB Output is correct
29 Correct 436 ms 844 KB Output is correct
30 Correct 338 ms 872 KB Output is correct
31 Correct 375 ms 880 KB Output is correct
32 Correct 363 ms 844 KB Output is correct
33 Correct 367 ms 884 KB Output is correct
34 Correct 338 ms 860 KB Output is correct
35 Correct 381 ms 1036 KB Output is correct
36 Correct 378 ms 1040 KB Output is correct
37 Correct 397 ms 2748 KB Output is correct
38 Correct 394 ms 2380 KB Output is correct
39 Correct 398 ms 2364 KB Output is correct
40 Correct 444 ms 2452 KB Output is correct
41 Correct 404 ms 2428 KB Output is correct
42 Correct 368 ms 2636 KB Output is correct
43 Correct 364 ms 2300 KB Output is correct
44 Correct 369 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 780 KB Output is correct
2 Correct 452 ms 904 KB Output is correct
3 Correct 492 ms 908 KB Output is correct
4 Correct 390 ms 844 KB Output is correct
5 Correct 375 ms 860 KB Output is correct
6 Correct 361 ms 844 KB Output is correct
7 Correct 381 ms 904 KB Output is correct
8 Correct 394 ms 844 KB Output is correct
9 Correct 418 ms 856 KB Output is correct
10 Correct 403 ms 912 KB Output is correct
11 Correct 425 ms 992 KB Output is correct
12 Correct 404 ms 880 KB Output is correct
13 Correct 423 ms 812 KB Output is correct
14 Correct 399 ms 1116 KB Output is correct
15 Correct 431 ms 2368 KB Output is correct
16 Correct 381 ms 2408 KB Output is correct
17 Correct 381 ms 2388 KB Output is correct
18 Correct 471 ms 2372 KB Output is correct
19 Correct 1649 ms 38768 KB Output is correct
20 Correct 1834 ms 38884 KB Output is correct
21 Correct 1126 ms 38492 KB Output is correct
22 Correct 1048 ms 38264 KB Output is correct
23 Correct 800 ms 5552 KB Output is correct
24 Correct 791 ms 5560 KB Output is correct
25 Correct 1119 ms 38740 KB Output is correct
26 Correct 1176 ms 39016 KB Output is correct
27 Correct 1401 ms 38860 KB Output is correct
28 Correct 1659 ms 38740 KB Output is correct
29 Correct 1455 ms 38756 KB Output is correct
30 Correct 931 ms 5432 KB Output is correct
31 Correct 1490 ms 38748 KB Output is correct
32 Correct 1558 ms 38432 KB Output is correct
33 Correct 878 ms 5376 KB Output is correct
34 Correct 1464 ms 38732 KB Output is correct
35 Correct 1169 ms 37912 KB Output is correct
36 Correct 914 ms 5380 KB Output is correct
37 Correct 1127 ms 5280 KB Output is correct
38 Correct 1695 ms 38484 KB Output is correct
39 Correct 997 ms 38712 KB Output is correct
40 Correct 1122 ms 21692 KB Output is correct
41 Correct 1926 ms 38952 KB Output is correct
42 Correct 570 ms 38084 KB Output is correct
43 Correct 441 ms 896 KB Output is correct
44 Correct 542 ms 848 KB Output is correct
45 Correct 397 ms 812 KB Output is correct
46 Correct 345 ms 836 KB Output is correct
47 Correct 393 ms 892 KB Output is correct
48 Correct 372 ms 868 KB Output is correct
49 Correct 391 ms 1028 KB Output is correct
50 Correct 358 ms 788 KB Output is correct
51 Correct 371 ms 844 KB Output is correct
52 Correct 334 ms 864 KB Output is correct
53 Correct 436 ms 844 KB Output is correct
54 Correct 338 ms 872 KB Output is correct
55 Correct 375 ms 880 KB Output is correct
56 Correct 363 ms 844 KB Output is correct
57 Correct 367 ms 884 KB Output is correct
58 Correct 338 ms 860 KB Output is correct
59 Correct 381 ms 1036 KB Output is correct
60 Correct 378 ms 1040 KB Output is correct
61 Correct 397 ms 2748 KB Output is correct
62 Correct 394 ms 2380 KB Output is correct
63 Correct 398 ms 2364 KB Output is correct
64 Correct 444 ms 2452 KB Output is correct
65 Correct 404 ms 2428 KB Output is correct
66 Correct 368 ms 2636 KB Output is correct
67 Correct 364 ms 2300 KB Output is correct
68 Correct 369 ms 2412 KB Output is correct
69 Correct 1502 ms 39996 KB Output is correct
70 Correct 1879 ms 41208 KB Output is correct
71 Correct 758 ms 5380 KB Output is correct
72 Correct 759 ms 5580 KB Output is correct
73 Correct 767 ms 5400 KB Output is correct
74 Correct 1004 ms 38592 KB Output is correct
75 Correct 761 ms 5300 KB Output is correct
76 Correct 1164 ms 39116 KB Output is correct
77 Correct 1041 ms 38628 KB Output is correct
78 Correct 737 ms 5324 KB Output is correct
79 Correct 751 ms 5448 KB Output is correct
80 Correct 1049 ms 39436 KB Output is correct
81 Correct 762 ms 5492 KB Output is correct
82 Correct 1146 ms 41476 KB Output is correct
83 Correct 1093 ms 41144 KB Output is correct
84 Correct 751 ms 5432 KB Output is correct
85 Correct 750 ms 5600 KB Output is correct
86 Correct 1305 ms 40124 KB Output is correct
87 Correct 1382 ms 41192 KB Output is correct
88 Correct 824 ms 5524 KB Output is correct
89 Correct 1224 ms 40564 KB Output is correct
90 Correct 1314 ms 41416 KB Output is correct
91 Correct 808 ms 5428 KB Output is correct
92 Correct 1020 ms 40048 KB Output is correct
93 Correct 750 ms 5520 KB Output is correct
94 Correct 739 ms 5528 KB Output is correct
95 Correct 744 ms 5544 KB Output is correct
96 Correct 1483 ms 38616 KB Output is correct
97 Correct 995 ms 41452 KB Output is correct
98 Correct 1041 ms 23404 KB Output is correct
99 Correct 1792 ms 41608 KB Output is correct
100 Correct 580 ms 40580 KB Output is correct