Submission #887148

# Submission time Handle Problem Language Result Execution time Memory
887148 2023-12-13T21:46:59 Z box Crossing (JOI21_crossing) C++17
100 / 100
719 ms 34492 KB
#include <bits/stdc++.h>
using namespace std;

mt19937 rng(1234);

string gen(int n) {
    string s(n, '?');
    for (int i = 0; i < n; i++) s[i] = "JOI"[rng() % 3];
    return s;
}

#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;

const int N = 2e5, N_ = 1 << 18, K = 9;

string operator+(string one, const string two) {
    static char all = 'J' ^ 'O' ^ 'I';
    for (int i = 0; i < sz(one); i++)
        one[i] = one[i] == two[i] ? one[i] : (one[i] ^ two[i] ^ all);
    return one;
}

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

i64 hsh(const string s) {
    static const int P1 = 1e9 + 7, P2 = 1e9 + 9;
    i64 one = 0, two = 0;
    for (char c : s) {
        one = (one * 3 + id(c)) % P1;
        two = (two * 3 + id(c)) % P2;
    }
    return one * P2 + two;
}

int n, q;
vector<string> v;
unordered_set<i64> s;

void expand() {
    for (string t : v) s.insert(hsh(t));
    while (1) {
        int m = sz(v);
        for (int i = 0; i < m; i++) for (int j = i + 1; j < m; j++) {
            string t = v[i] + v[j];
            i64 h = hsh(t);
            if (!s.count(h)) {
                s.insert(h);
                v.push_back(t);
            }
        }
        if (sz(v) == m) break;
    }
}

ar<int, 3> pf[K][N + 1];
bitset<K> ok[N_ * 2];
int lz[N_ * 2];

bool filled(int t, int l, int r, int c) {
    return pf[t][r + 1][c] - pf[t][l][c] == r - l + 1;
}

void bld(int k, int l, int r, string &s) {
    lz[k] = -1;
    if (l == r) {
        for (int t = 0; t < sz(v); t++)
            ok[k][t] = filled(t, l, l, id(s[l]));
    } else {
        int m = (l + r) / 2;
        bld(k * 2, l, m, s), bld(k * 2 + 1, m + 1, r, s);
        ok[k] = ok[k * 2] & ok[k * 2 + 1];
    }
}

void put(int k, int l, int r, int c) {
    for (int t = 0; t < sz(v); t++)
        ok[k][t] = filled(t, l, r, c);
    lz[k] = c;
}

void push(int k, int l, int r) {
    if (~lz[k]) {
        int m = (l + r) / 2;
        put(k * 2, l, m, lz[k]), put(k * 2 + 1, m + 1, r, lz[k]);
        lz[k] = -1;
    }
}

void upd(int k, int l, int r, int ql, int qr, int c) {
    if (ql > r || qr < l) return;
    if (ql <= l && qr >= r) return void(put(k, l, r, c));
    int m = (l + r) / 2;
    push(k, l, r);
    upd(k * 2, l, m, ql, qr, c), upd(k * 2 + 1, m + 1, r, ql, qr, c);
    ok[k] = ok[k * 2] & ok[k * 2 + 1];
}

bool qry() {
    return ok[1].count();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int rep = 0; rep < 3; rep++) {
        string s;
        cin >> s;
        v.push_back(s);
    }
    expand();
    for (int t = 0; t < sz(v); t++) for (int i = 0; i < n; i++) {
        pf[t][i + 1] = pf[t][i];
        pf[t][i + 1][id(v[t][i])]++;
    }
    cin >> q;
    string t;
    cin >> t;
    bld(1, 0, n - 1, t);
    cout << (qry() ? "Yes\n" : "No\n");
    while (q--) {
        int l, r; char c;
        cin >> l >> r >> c, l--, r--;
        upd(1, 0, n - 1, l, r, id(c));
        cout << (qry() ? "Yes\n" : "No\n");
    }
}
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 68 ms 1220 KB Output is correct
3 Correct 67 ms 924 KB Output is correct
4 Correct 54 ms 968 KB Output is correct
5 Correct 54 ms 848 KB Output is correct
6 Correct 54 ms 848 KB Output is correct
7 Correct 58 ms 1040 KB Output is correct
8 Correct 57 ms 1048 KB Output is correct
9 Correct 70 ms 1044 KB Output is correct
10 Correct 58 ms 856 KB Output is correct
11 Correct 58 ms 852 KB Output is correct
12 Correct 57 ms 1080 KB Output is correct
13 Correct 58 ms 860 KB Output is correct
14 Correct 67 ms 832 KB Output is correct
15 Correct 59 ms 996 KB Output is correct
16 Correct 62 ms 1208 KB Output is correct
17 Correct 58 ms 848 KB Output is correct
18 Correct 64 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 68 ms 1220 KB Output is correct
3 Correct 67 ms 924 KB Output is correct
4 Correct 54 ms 968 KB Output is correct
5 Correct 54 ms 848 KB Output is correct
6 Correct 54 ms 848 KB Output is correct
7 Correct 58 ms 1040 KB Output is correct
8 Correct 57 ms 1048 KB Output is correct
9 Correct 70 ms 1044 KB Output is correct
10 Correct 58 ms 856 KB Output is correct
11 Correct 58 ms 852 KB Output is correct
12 Correct 57 ms 1080 KB Output is correct
13 Correct 58 ms 860 KB Output is correct
14 Correct 67 ms 832 KB Output is correct
15 Correct 59 ms 996 KB Output is correct
16 Correct 62 ms 1208 KB Output is correct
17 Correct 58 ms 848 KB Output is correct
18 Correct 64 ms 940 KB Output is correct
19 Correct 242 ms 16468 KB Output is correct
20 Correct 221 ms 20280 KB Output is correct
21 Correct 126 ms 19896 KB Output is correct
22 Correct 133 ms 19560 KB Output is correct
23 Correct 87 ms 4008 KB Output is correct
24 Correct 87 ms 4196 KB Output is correct
25 Correct 130 ms 20304 KB Output is correct
26 Correct 181 ms 20308 KB Output is correct
27 Correct 164 ms 20184 KB Output is correct
28 Correct 156 ms 20328 KB Output is correct
29 Correct 157 ms 20512 KB Output is correct
30 Correct 98 ms 4184 KB Output is correct
31 Correct 149 ms 20312 KB Output is correct
32 Correct 185 ms 20012 KB Output is correct
33 Correct 104 ms 4176 KB Output is correct
34 Correct 169 ms 20312 KB Output is correct
35 Correct 125 ms 18924 KB Output is correct
36 Correct 91 ms 4232 KB Output is correct
37 Correct 93 ms 4208 KB Output is correct
38 Correct 202 ms 19944 KB Output is correct
39 Correct 100 ms 20312 KB Output is correct
40 Correct 118 ms 14416 KB Output is correct
41 Correct 239 ms 20368 KB Output is correct
42 Correct 47 ms 19796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 68 ms 1220 KB Output is correct
3 Correct 67 ms 924 KB Output is correct
4 Correct 54 ms 968 KB Output is correct
5 Correct 54 ms 848 KB Output is correct
6 Correct 54 ms 848 KB Output is correct
7 Correct 58 ms 1040 KB Output is correct
8 Correct 57 ms 1048 KB Output is correct
9 Correct 70 ms 1044 KB Output is correct
10 Correct 58 ms 856 KB Output is correct
11 Correct 58 ms 852 KB Output is correct
12 Correct 57 ms 1080 KB Output is correct
13 Correct 58 ms 860 KB Output is correct
14 Correct 67 ms 832 KB Output is correct
15 Correct 59 ms 996 KB Output is correct
16 Correct 62 ms 1208 KB Output is correct
17 Correct 58 ms 848 KB Output is correct
18 Correct 64 ms 940 KB Output is correct
19 Correct 87 ms 952 KB Output is correct
20 Correct 87 ms 1064 KB Output is correct
21 Correct 58 ms 852 KB Output is correct
22 Correct 53 ms 852 KB Output is correct
23 Correct 59 ms 848 KB Output is correct
24 Correct 57 ms 844 KB Output is correct
25 Correct 59 ms 848 KB Output is correct
26 Correct 63 ms 860 KB Output is correct
27 Correct 57 ms 848 KB Output is correct
28 Correct 51 ms 860 KB Output is correct
29 Correct 58 ms 852 KB Output is correct
30 Correct 51 ms 1032 KB Output is correct
31 Correct 67 ms 1108 KB Output is correct
32 Correct 68 ms 1108 KB Output is correct
33 Correct 73 ms 976 KB Output is correct
34 Correct 64 ms 1060 KB Output is correct
35 Correct 66 ms 1108 KB Output is correct
36 Correct 68 ms 1108 KB Output is correct
37 Correct 66 ms 992 KB Output is correct
38 Correct 74 ms 1072 KB Output is correct
39 Correct 67 ms 1108 KB Output is correct
40 Correct 68 ms 1016 KB Output is correct
41 Correct 66 ms 900 KB Output is correct
42 Correct 68 ms 1032 KB Output is correct
43 Correct 65 ms 1068 KB Output is correct
44 Correct 68 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 68 ms 1220 KB Output is correct
3 Correct 67 ms 924 KB Output is correct
4 Correct 54 ms 968 KB Output is correct
5 Correct 54 ms 848 KB Output is correct
6 Correct 54 ms 848 KB Output is correct
7 Correct 58 ms 1040 KB Output is correct
8 Correct 57 ms 1048 KB Output is correct
9 Correct 70 ms 1044 KB Output is correct
10 Correct 58 ms 856 KB Output is correct
11 Correct 58 ms 852 KB Output is correct
12 Correct 57 ms 1080 KB Output is correct
13 Correct 58 ms 860 KB Output is correct
14 Correct 67 ms 832 KB Output is correct
15 Correct 59 ms 996 KB Output is correct
16 Correct 62 ms 1208 KB Output is correct
17 Correct 58 ms 848 KB Output is correct
18 Correct 64 ms 940 KB Output is correct
19 Correct 242 ms 16468 KB Output is correct
20 Correct 221 ms 20280 KB Output is correct
21 Correct 126 ms 19896 KB Output is correct
22 Correct 133 ms 19560 KB Output is correct
23 Correct 87 ms 4008 KB Output is correct
24 Correct 87 ms 4196 KB Output is correct
25 Correct 130 ms 20304 KB Output is correct
26 Correct 181 ms 20308 KB Output is correct
27 Correct 164 ms 20184 KB Output is correct
28 Correct 156 ms 20328 KB Output is correct
29 Correct 157 ms 20512 KB Output is correct
30 Correct 98 ms 4184 KB Output is correct
31 Correct 149 ms 20312 KB Output is correct
32 Correct 185 ms 20012 KB Output is correct
33 Correct 104 ms 4176 KB Output is correct
34 Correct 169 ms 20312 KB Output is correct
35 Correct 125 ms 18924 KB Output is correct
36 Correct 91 ms 4232 KB Output is correct
37 Correct 93 ms 4208 KB Output is correct
38 Correct 202 ms 19944 KB Output is correct
39 Correct 100 ms 20312 KB Output is correct
40 Correct 118 ms 14416 KB Output is correct
41 Correct 239 ms 20368 KB Output is correct
42 Correct 47 ms 19796 KB Output is correct
43 Correct 87 ms 952 KB Output is correct
44 Correct 87 ms 1064 KB Output is correct
45 Correct 58 ms 852 KB Output is correct
46 Correct 53 ms 852 KB Output is correct
47 Correct 59 ms 848 KB Output is correct
48 Correct 57 ms 844 KB Output is correct
49 Correct 59 ms 848 KB Output is correct
50 Correct 63 ms 860 KB Output is correct
51 Correct 57 ms 848 KB Output is correct
52 Correct 51 ms 860 KB Output is correct
53 Correct 58 ms 852 KB Output is correct
54 Correct 51 ms 1032 KB Output is correct
55 Correct 67 ms 1108 KB Output is correct
56 Correct 68 ms 1108 KB Output is correct
57 Correct 73 ms 976 KB Output is correct
58 Correct 64 ms 1060 KB Output is correct
59 Correct 66 ms 1108 KB Output is correct
60 Correct 68 ms 1108 KB Output is correct
61 Correct 66 ms 992 KB Output is correct
62 Correct 74 ms 1072 KB Output is correct
63 Correct 67 ms 1108 KB Output is correct
64 Correct 68 ms 1016 KB Output is correct
65 Correct 66 ms 900 KB Output is correct
66 Correct 68 ms 1032 KB Output is correct
67 Correct 65 ms 1068 KB Output is correct
68 Correct 68 ms 1068 KB Output is correct
69 Correct 554 ms 33020 KB Output is correct
70 Correct 408 ms 33904 KB Output is correct
71 Correct 92 ms 4176 KB Output is correct
72 Correct 93 ms 4348 KB Output is correct
73 Correct 92 ms 4288 KB Output is correct
74 Correct 122 ms 19448 KB Output is correct
75 Correct 86 ms 4096 KB Output is correct
76 Correct 149 ms 20360 KB Output is correct
77 Correct 129 ms 19604 KB Output is correct
78 Correct 88 ms 3976 KB Output is correct
79 Correct 95 ms 4140 KB Output is correct
80 Correct 270 ms 31500 KB Output is correct
81 Correct 105 ms 4960 KB Output is correct
82 Correct 296 ms 34140 KB Output is correct
83 Correct 335 ms 33776 KB Output is correct
84 Correct 124 ms 5372 KB Output is correct
85 Correct 107 ms 4948 KB Output is correct
86 Correct 396 ms 31716 KB Output is correct
87 Correct 415 ms 33988 KB Output is correct
88 Correct 133 ms 5064 KB Output is correct
89 Correct 357 ms 33160 KB Output is correct
90 Correct 362 ms 34096 KB Output is correct
91 Correct 137 ms 4844 KB Output is correct
92 Correct 249 ms 31760 KB Output is correct
93 Correct 119 ms 4944 KB Output is correct
94 Correct 114 ms 5004 KB Output is correct
95 Correct 109 ms 4944 KB Output is correct
96 Correct 196 ms 20056 KB Output is correct
97 Correct 198 ms 34492 KB Output is correct
98 Correct 265 ms 28236 KB Output is correct
99 Correct 719 ms 34344 KB Output is correct
100 Correct 130 ms 33584 KB Output is correct