Submission #824988

# Submission time Handle Problem Language Result Execution time Memory
824988 2023-08-14T12:53:36 Z phoenix Crossing (JOI21_crossing) C++17
100 / 100
273 ms 40400 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

namespace hashing {

    struct H {
        int len;
        ll h1;
        unsigned long long h2;
        H() : len(0), h1(0), h2(0) {} 
        H(int c) : len(1), h1(c), h2(c) {}

    };
    map<char, int> tran = {
        {'J', 0},
        {'O', 1},
        {'I', 2}
    };

    const int MOD = 1e9 + 7, MAX_LEN = 2e5 + 10;
    ll p1[MAX_LEN];
    unsigned long long p2[MAX_LEN];
    mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
    H spam_str[MAX_LEN][3];
    H operator + (const H a, const H b) {
        H res;
        res.len = a.len + b.len;
        res.h1 = (a.h1 * p1[b.len] + b.h1) % MOD;
        res.h2 = (a.h2 * p2[b.len] + b.h2);
        return res;
    }
    bool operator == (const H a, const H b) {
        bool res = 1;
        res &= (a.len == b.len);
        res &= (a.h1 == b.h1);
        res &= (a.h2 == b.h2);
        return res;
    }

    void H_precalc() {
        p1[0] = p2[0] = 1;
        int p = rnd() % 500 * 2 + 10;
        int q = rnd() % 500 * 2 + 10;
        for(int i = 1; i < MAX_LEN; i++) 
            p1[i] = p1[i - 1] * p % MOD,
            p2[i] = p2[i - 1] * q;
        for(int i = 1; i < MAX_LEN; i++) {
            spam_str[i][0] = spam_str[i - 1][0] + H(0);
            spam_str[i][1] = spam_str[i - 1][1] + H(1);
            spam_str[i][2] = spam_str[i - 1][2] + H(2);
        }
    }

    const int M = (1 << 18);
    H tr[2 * M];
    vector<int> upd(2 * M, -1);
    
    void setpush(int v, int l, int r, int x) {
        tr[v] = spam_str[r - l + 1][x];
        upd[v] = x;
    }
    void push(int v, int l, int r) {
        if(l == r || upd[v] == -1) return;
        int mid = (l + r) / 2;
        setpush(2 * v, l, mid, upd[v]);
        setpush(2 * v + 1, mid + 1, r, upd[v]);
        upd[v] = -1;
    }
    void build(string &t, int l = 0, int r = M - 1, int v = 1) {
        if(l == r) {
            if(l < (int)t.size()) tr[v] = H(tran[t[l]]);
            return;
        }
        int mid = (l + r) / 2;
        build(t, l, mid, 2 * v);
        build(t, mid + 1, r, 2 * v + 1);
        tr[v] = tr[2 * v] + tr[2 * v + 1];
    }
    void update(char c, int ql, int qr, int l = 0, int r = M - 1, int v = 1) {
        if(r < ql || l > qr) return;
        if(ql <= l && r <= qr) {
            setpush(v, l, r, tran[c]);
            return;
        }
        push(v, l, r);
        int mid = (l + r) / 2;
        update(c, ql, qr, l, mid, 2 * v);
        update(c, ql, qr, mid + 1, r, 2 * v + 1);
        tr[v] = tr[2 * v] + tr[2 * v + 1];
    }
};
using namespace hashing;


int n;
string T = "JOI";

string get(string a, string b) {
    string res;
    for(int i = 0; i < n; i++)
        if(a[i] == b[i]) res += a[i];
        else {
            int k = 0;
            while(T[k] == a[i] || T[k] == b[i]) k++;
            res += T[k];
        }
    return res;
}
vector<string> st;
vector<H> h;
bool check() {
    for(H cur : h)
        if(cur == tr[1]) return 1;
    return 0;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    hashing::H_precalc();

    cin >> n;
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    st.push_back(s[0]);
    st.push_back(s[1]);
    st.push_back(s[2]);
    st.push_back(get(s[0], s[1]));
    st.push_back(get(s[0], s[2]));
    st.push_back(get(s[1], s[2]));
    st.push_back(get(s[0], get(s[1], s[2])));
    st.push_back(get(s[0], get(s[2], s[1])));
    st.push_back(get(s[1], get(s[0], s[2])));
    st.push_back(get(s[1], get(s[2], s[0])));
    st.push_back(get(s[2], get(s[0], s[1])));
    st.push_back(get(s[2], get(s[1], s[0])));
    for(string c : st) {
        H res;
        for(int i = 0; i < n; i++) 
            res = res + H(tran[c[i]]);
        h.push_back(res);
    }

    int q;
    cin >> q;
    string t;
    cin >> t;
    build(t);

    cout << (check() ? "Yes\n" : "No\n");
    while(q--) {
        int l, r; char x;
        cin >> l >> r >> x;
        l--; r--;
        update(x, l, r);
        cout << (check() ? "Yes\n" : "No\n");
    }
}
# Verdict Execution time Memory Grader output
1 Correct 117 ms 33868 KB Output is correct
2 Correct 113 ms 33972 KB Output is correct
3 Correct 116 ms 33868 KB Output is correct
4 Correct 100 ms 33888 KB Output is correct
5 Correct 98 ms 33880 KB Output is correct
6 Correct 107 ms 33916 KB Output is correct
7 Correct 100 ms 33892 KB Output is correct
8 Correct 106 ms 34136 KB Output is correct
9 Correct 101 ms 34024 KB Output is correct
10 Correct 106 ms 34040 KB Output is correct
11 Correct 105 ms 34012 KB Output is correct
12 Correct 105 ms 34020 KB Output is correct
13 Correct 103 ms 33952 KB Output is correct
14 Correct 107 ms 34020 KB Output is correct
15 Correct 105 ms 33996 KB Output is correct
16 Correct 103 ms 34052 KB Output is correct
17 Correct 109 ms 34056 KB Output is correct
18 Correct 108 ms 33908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 33868 KB Output is correct
2 Correct 113 ms 33972 KB Output is correct
3 Correct 116 ms 33868 KB Output is correct
4 Correct 100 ms 33888 KB Output is correct
5 Correct 98 ms 33880 KB Output is correct
6 Correct 107 ms 33916 KB Output is correct
7 Correct 100 ms 33892 KB Output is correct
8 Correct 106 ms 34136 KB Output is correct
9 Correct 101 ms 34024 KB Output is correct
10 Correct 106 ms 34040 KB Output is correct
11 Correct 105 ms 34012 KB Output is correct
12 Correct 105 ms 34020 KB Output is correct
13 Correct 103 ms 33952 KB Output is correct
14 Correct 107 ms 34020 KB Output is correct
15 Correct 105 ms 33996 KB Output is correct
16 Correct 103 ms 34052 KB Output is correct
17 Correct 109 ms 34056 KB Output is correct
18 Correct 108 ms 33908 KB Output is correct
19 Correct 235 ms 40208 KB Output is correct
20 Correct 260 ms 40120 KB Output is correct
21 Correct 169 ms 39680 KB Output is correct
22 Correct 166 ms 39216 KB Output is correct
23 Correct 124 ms 35060 KB Output is correct
24 Correct 121 ms 35044 KB Output is correct
25 Correct 189 ms 40144 KB Output is correct
26 Correct 182 ms 40156 KB Output is correct
27 Correct 190 ms 40188 KB Output is correct
28 Correct 194 ms 40220 KB Output is correct
29 Correct 177 ms 40040 KB Output is correct
30 Correct 128 ms 35124 KB Output is correct
31 Correct 177 ms 40136 KB Output is correct
32 Correct 174 ms 39700 KB Output is correct
33 Correct 123 ms 35020 KB Output is correct
34 Correct 181 ms 40200 KB Output is correct
35 Correct 155 ms 38808 KB Output is correct
36 Correct 120 ms 35056 KB Output is correct
37 Correct 123 ms 35060 KB Output is correct
38 Correct 203 ms 39920 KB Output is correct
39 Correct 144 ms 40164 KB Output is correct
40 Correct 157 ms 38652 KB Output is correct
41 Correct 249 ms 40400 KB Output is correct
42 Correct 100 ms 39604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 33868 KB Output is correct
2 Correct 113 ms 33972 KB Output is correct
3 Correct 116 ms 33868 KB Output is correct
4 Correct 100 ms 33888 KB Output is correct
5 Correct 98 ms 33880 KB Output is correct
6 Correct 107 ms 33916 KB Output is correct
7 Correct 100 ms 33892 KB Output is correct
8 Correct 106 ms 34136 KB Output is correct
9 Correct 101 ms 34024 KB Output is correct
10 Correct 106 ms 34040 KB Output is correct
11 Correct 105 ms 34012 KB Output is correct
12 Correct 105 ms 34020 KB Output is correct
13 Correct 103 ms 33952 KB Output is correct
14 Correct 107 ms 34020 KB Output is correct
15 Correct 105 ms 33996 KB Output is correct
16 Correct 103 ms 34052 KB Output is correct
17 Correct 109 ms 34056 KB Output is correct
18 Correct 108 ms 33908 KB Output is correct
19 Correct 104 ms 33868 KB Output is correct
20 Correct 118 ms 33848 KB Output is correct
21 Correct 102 ms 34008 KB Output is correct
22 Correct 95 ms 33792 KB Output is correct
23 Correct 102 ms 34028 KB Output is correct
24 Correct 106 ms 33880 KB Output is correct
25 Correct 103 ms 34048 KB Output is correct
26 Correct 109 ms 34044 KB Output is correct
27 Correct 102 ms 34024 KB Output is correct
28 Correct 94 ms 33792 KB Output is correct
29 Correct 105 ms 34056 KB Output is correct
30 Correct 97 ms 33876 KB Output is correct
31 Correct 108 ms 34016 KB Output is correct
32 Correct 103 ms 33976 KB Output is correct
33 Correct 103 ms 34024 KB Output is correct
34 Correct 96 ms 33852 KB Output is correct
35 Correct 109 ms 33980 KB Output is correct
36 Correct 108 ms 34028 KB Output is correct
37 Correct 103 ms 34024 KB Output is correct
38 Correct 103 ms 34024 KB Output is correct
39 Correct 116 ms 34020 KB Output is correct
40 Correct 102 ms 34016 KB Output is correct
41 Correct 110 ms 34048 KB Output is correct
42 Correct 104 ms 33968 KB Output is correct
43 Correct 108 ms 33900 KB Output is correct
44 Correct 105 ms 33984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 33868 KB Output is correct
2 Correct 113 ms 33972 KB Output is correct
3 Correct 116 ms 33868 KB Output is correct
4 Correct 100 ms 33888 KB Output is correct
5 Correct 98 ms 33880 KB Output is correct
6 Correct 107 ms 33916 KB Output is correct
7 Correct 100 ms 33892 KB Output is correct
8 Correct 106 ms 34136 KB Output is correct
9 Correct 101 ms 34024 KB Output is correct
10 Correct 106 ms 34040 KB Output is correct
11 Correct 105 ms 34012 KB Output is correct
12 Correct 105 ms 34020 KB Output is correct
13 Correct 103 ms 33952 KB Output is correct
14 Correct 107 ms 34020 KB Output is correct
15 Correct 105 ms 33996 KB Output is correct
16 Correct 103 ms 34052 KB Output is correct
17 Correct 109 ms 34056 KB Output is correct
18 Correct 108 ms 33908 KB Output is correct
19 Correct 235 ms 40208 KB Output is correct
20 Correct 260 ms 40120 KB Output is correct
21 Correct 169 ms 39680 KB Output is correct
22 Correct 166 ms 39216 KB Output is correct
23 Correct 124 ms 35060 KB Output is correct
24 Correct 121 ms 35044 KB Output is correct
25 Correct 189 ms 40144 KB Output is correct
26 Correct 182 ms 40156 KB Output is correct
27 Correct 190 ms 40188 KB Output is correct
28 Correct 194 ms 40220 KB Output is correct
29 Correct 177 ms 40040 KB Output is correct
30 Correct 128 ms 35124 KB Output is correct
31 Correct 177 ms 40136 KB Output is correct
32 Correct 174 ms 39700 KB Output is correct
33 Correct 123 ms 35020 KB Output is correct
34 Correct 181 ms 40200 KB Output is correct
35 Correct 155 ms 38808 KB Output is correct
36 Correct 120 ms 35056 KB Output is correct
37 Correct 123 ms 35060 KB Output is correct
38 Correct 203 ms 39920 KB Output is correct
39 Correct 144 ms 40164 KB Output is correct
40 Correct 157 ms 38652 KB Output is correct
41 Correct 249 ms 40400 KB Output is correct
42 Correct 100 ms 39604 KB Output is correct
43 Correct 104 ms 33868 KB Output is correct
44 Correct 118 ms 33848 KB Output is correct
45 Correct 102 ms 34008 KB Output is correct
46 Correct 95 ms 33792 KB Output is correct
47 Correct 102 ms 34028 KB Output is correct
48 Correct 106 ms 33880 KB Output is correct
49 Correct 103 ms 34048 KB Output is correct
50 Correct 109 ms 34044 KB Output is correct
51 Correct 102 ms 34024 KB Output is correct
52 Correct 94 ms 33792 KB Output is correct
53 Correct 105 ms 34056 KB Output is correct
54 Correct 97 ms 33876 KB Output is correct
55 Correct 108 ms 34016 KB Output is correct
56 Correct 103 ms 33976 KB Output is correct
57 Correct 103 ms 34024 KB Output is correct
58 Correct 96 ms 33852 KB Output is correct
59 Correct 109 ms 33980 KB Output is correct
60 Correct 108 ms 34028 KB Output is correct
61 Correct 103 ms 34024 KB Output is correct
62 Correct 103 ms 34024 KB Output is correct
63 Correct 116 ms 34020 KB Output is correct
64 Correct 102 ms 34016 KB Output is correct
65 Correct 110 ms 34048 KB Output is correct
66 Correct 104 ms 33968 KB Output is correct
67 Correct 108 ms 33900 KB Output is correct
68 Correct 105 ms 33984 KB Output is correct
69 Correct 233 ms 39132 KB Output is correct
70 Correct 273 ms 40240 KB Output is correct
71 Correct 121 ms 35076 KB Output is correct
72 Correct 124 ms 35020 KB Output is correct
73 Correct 121 ms 35048 KB Output is correct
74 Correct 180 ms 39168 KB Output is correct
75 Correct 120 ms 35100 KB Output is correct
76 Correct 201 ms 40204 KB Output is correct
77 Correct 229 ms 39280 KB Output is correct
78 Correct 121 ms 35064 KB Output is correct
79 Correct 120 ms 35020 KB Output is correct
80 Correct 220 ms 38576 KB Output is correct
81 Correct 125 ms 35068 KB Output is correct
82 Correct 207 ms 40152 KB Output is correct
83 Correct 193 ms 39780 KB Output is correct
84 Correct 121 ms 35032 KB Output is correct
85 Correct 126 ms 35004 KB Output is correct
86 Correct 179 ms 38868 KB Output is correct
87 Correct 198 ms 40280 KB Output is correct
88 Correct 129 ms 35104 KB Output is correct
89 Correct 179 ms 39344 KB Output is correct
90 Correct 192 ms 40156 KB Output is correct
91 Correct 129 ms 35092 KB Output is correct
92 Correct 173 ms 38848 KB Output is correct
93 Correct 123 ms 35088 KB Output is correct
94 Correct 129 ms 35140 KB Output is correct
95 Correct 125 ms 35092 KB Output is correct
96 Correct 202 ms 40004 KB Output is correct
97 Correct 146 ms 40276 KB Output is correct
98 Correct 171 ms 38560 KB Output is correct
99 Correct 269 ms 40388 KB Output is correct
100 Correct 134 ms 39664 KB Output is correct