답안 #818686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818686 2023-08-10T06:19:51 Z vjudge1 Crossing (JOI21_crossing) C++17
100 / 100
299 ms 40372 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");
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 32400 KB Output is correct
2 Correct 115 ms 32512 KB Output is correct
3 Correct 113 ms 32508 KB Output is correct
4 Correct 133 ms 32428 KB Output is correct
5 Correct 102 ms 32500 KB Output is correct
6 Correct 106 ms 32404 KB Output is correct
7 Correct 141 ms 32468 KB Output is correct
8 Correct 113 ms 32492 KB Output is correct
9 Correct 110 ms 32468 KB Output is correct
10 Correct 112 ms 32436 KB Output is correct
11 Correct 107 ms 32484 KB Output is correct
12 Correct 133 ms 32520 KB Output is correct
13 Correct 109 ms 32500 KB Output is correct
14 Correct 165 ms 32460 KB Output is correct
15 Correct 104 ms 32460 KB Output is correct
16 Correct 137 ms 32436 KB Output is correct
17 Correct 104 ms 32516 KB Output is correct
18 Correct 120 ms 32440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 32400 KB Output is correct
2 Correct 115 ms 32512 KB Output is correct
3 Correct 113 ms 32508 KB Output is correct
4 Correct 133 ms 32428 KB Output is correct
5 Correct 102 ms 32500 KB Output is correct
6 Correct 106 ms 32404 KB Output is correct
7 Correct 141 ms 32468 KB Output is correct
8 Correct 113 ms 32492 KB Output is correct
9 Correct 110 ms 32468 KB Output is correct
10 Correct 112 ms 32436 KB Output is correct
11 Correct 107 ms 32484 KB Output is correct
12 Correct 133 ms 32520 KB Output is correct
13 Correct 109 ms 32500 KB Output is correct
14 Correct 165 ms 32460 KB Output is correct
15 Correct 104 ms 32460 KB Output is correct
16 Correct 137 ms 32436 KB Output is correct
17 Correct 104 ms 32516 KB Output is correct
18 Correct 120 ms 32440 KB Output is correct
19 Correct 283 ms 37804 KB Output is correct
20 Correct 238 ms 40064 KB Output is correct
21 Correct 176 ms 39772 KB Output is correct
22 Correct 175 ms 39228 KB Output is correct
23 Correct 127 ms 35092 KB Output is correct
24 Correct 125 ms 35068 KB Output is correct
25 Correct 192 ms 40208 KB Output is correct
26 Correct 180 ms 40168 KB Output is correct
27 Correct 190 ms 40200 KB Output is correct
28 Correct 196 ms 40212 KB Output is correct
29 Correct 202 ms 39972 KB Output is correct
30 Correct 135 ms 35032 KB Output is correct
31 Correct 211 ms 40228 KB Output is correct
32 Correct 180 ms 39688 KB Output is correct
33 Correct 142 ms 35108 KB Output is correct
34 Correct 299 ms 40188 KB Output is correct
35 Correct 197 ms 38728 KB Output is correct
36 Correct 123 ms 35076 KB Output is correct
37 Correct 123 ms 35048 KB Output is correct
38 Correct 230 ms 39964 KB Output is correct
39 Correct 151 ms 40372 KB Output is correct
40 Correct 160 ms 38560 KB Output is correct
41 Correct 237 ms 40320 KB Output is correct
42 Correct 103 ms 39656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 32400 KB Output is correct
2 Correct 115 ms 32512 KB Output is correct
3 Correct 113 ms 32508 KB Output is correct
4 Correct 133 ms 32428 KB Output is correct
5 Correct 102 ms 32500 KB Output is correct
6 Correct 106 ms 32404 KB Output is correct
7 Correct 141 ms 32468 KB Output is correct
8 Correct 113 ms 32492 KB Output is correct
9 Correct 110 ms 32468 KB Output is correct
10 Correct 112 ms 32436 KB Output is correct
11 Correct 107 ms 32484 KB Output is correct
12 Correct 133 ms 32520 KB Output is correct
13 Correct 109 ms 32500 KB Output is correct
14 Correct 165 ms 32460 KB Output is correct
15 Correct 104 ms 32460 KB Output is correct
16 Correct 137 ms 32436 KB Output is correct
17 Correct 104 ms 32516 KB Output is correct
18 Correct 120 ms 32440 KB Output is correct
19 Correct 110 ms 32368 KB Output is correct
20 Correct 115 ms 32440 KB Output is correct
21 Correct 104 ms 32484 KB Output is correct
22 Correct 98 ms 32408 KB Output is correct
23 Correct 108 ms 32516 KB Output is correct
24 Correct 114 ms 32420 KB Output is correct
25 Correct 108 ms 32516 KB Output is correct
26 Correct 105 ms 32392 KB Output is correct
27 Correct 124 ms 32444 KB Output is correct
28 Correct 112 ms 32396 KB Output is correct
29 Correct 107 ms 32460 KB Output is correct
30 Correct 106 ms 32412 KB Output is correct
31 Correct 124 ms 32428 KB Output is correct
32 Correct 108 ms 32432 KB Output is correct
33 Correct 105 ms 32456 KB Output is correct
34 Correct 99 ms 32460 KB Output is correct
35 Correct 104 ms 32408 KB Output is correct
36 Correct 113 ms 32560 KB Output is correct
37 Correct 105 ms 32464 KB Output is correct
38 Correct 107 ms 32432 KB Output is correct
39 Correct 121 ms 32396 KB Output is correct
40 Correct 105 ms 32456 KB Output is correct
41 Correct 115 ms 32428 KB Output is correct
42 Correct 106 ms 32412 KB Output is correct
43 Correct 104 ms 32460 KB Output is correct
44 Correct 106 ms 32500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 32400 KB Output is correct
2 Correct 115 ms 32512 KB Output is correct
3 Correct 113 ms 32508 KB Output is correct
4 Correct 133 ms 32428 KB Output is correct
5 Correct 102 ms 32500 KB Output is correct
6 Correct 106 ms 32404 KB Output is correct
7 Correct 141 ms 32468 KB Output is correct
8 Correct 113 ms 32492 KB Output is correct
9 Correct 110 ms 32468 KB Output is correct
10 Correct 112 ms 32436 KB Output is correct
11 Correct 107 ms 32484 KB Output is correct
12 Correct 133 ms 32520 KB Output is correct
13 Correct 109 ms 32500 KB Output is correct
14 Correct 165 ms 32460 KB Output is correct
15 Correct 104 ms 32460 KB Output is correct
16 Correct 137 ms 32436 KB Output is correct
17 Correct 104 ms 32516 KB Output is correct
18 Correct 120 ms 32440 KB Output is correct
19 Correct 283 ms 37804 KB Output is correct
20 Correct 238 ms 40064 KB Output is correct
21 Correct 176 ms 39772 KB Output is correct
22 Correct 175 ms 39228 KB Output is correct
23 Correct 127 ms 35092 KB Output is correct
24 Correct 125 ms 35068 KB Output is correct
25 Correct 192 ms 40208 KB Output is correct
26 Correct 180 ms 40168 KB Output is correct
27 Correct 190 ms 40200 KB Output is correct
28 Correct 196 ms 40212 KB Output is correct
29 Correct 202 ms 39972 KB Output is correct
30 Correct 135 ms 35032 KB Output is correct
31 Correct 211 ms 40228 KB Output is correct
32 Correct 180 ms 39688 KB Output is correct
33 Correct 142 ms 35108 KB Output is correct
34 Correct 299 ms 40188 KB Output is correct
35 Correct 197 ms 38728 KB Output is correct
36 Correct 123 ms 35076 KB Output is correct
37 Correct 123 ms 35048 KB Output is correct
38 Correct 230 ms 39964 KB Output is correct
39 Correct 151 ms 40372 KB Output is correct
40 Correct 160 ms 38560 KB Output is correct
41 Correct 237 ms 40320 KB Output is correct
42 Correct 103 ms 39656 KB Output is correct
43 Correct 110 ms 32368 KB Output is correct
44 Correct 115 ms 32440 KB Output is correct
45 Correct 104 ms 32484 KB Output is correct
46 Correct 98 ms 32408 KB Output is correct
47 Correct 108 ms 32516 KB Output is correct
48 Correct 114 ms 32420 KB Output is correct
49 Correct 108 ms 32516 KB Output is correct
50 Correct 105 ms 32392 KB Output is correct
51 Correct 124 ms 32444 KB Output is correct
52 Correct 112 ms 32396 KB Output is correct
53 Correct 107 ms 32460 KB Output is correct
54 Correct 106 ms 32412 KB Output is correct
55 Correct 124 ms 32428 KB Output is correct
56 Correct 108 ms 32432 KB Output is correct
57 Correct 105 ms 32456 KB Output is correct
58 Correct 99 ms 32460 KB Output is correct
59 Correct 104 ms 32408 KB Output is correct
60 Correct 113 ms 32560 KB Output is correct
61 Correct 105 ms 32464 KB Output is correct
62 Correct 107 ms 32432 KB Output is correct
63 Correct 121 ms 32396 KB Output is correct
64 Correct 105 ms 32456 KB Output is correct
65 Correct 115 ms 32428 KB Output is correct
66 Correct 106 ms 32412 KB Output is correct
67 Correct 104 ms 32460 KB Output is correct
68 Correct 106 ms 32500 KB Output is correct
69 Correct 236 ms 39108 KB Output is correct
70 Correct 260 ms 40144 KB Output is correct
71 Correct 124 ms 35044 KB Output is correct
72 Correct 126 ms 35048 KB Output is correct
73 Correct 125 ms 35132 KB Output is correct
74 Correct 175 ms 39124 KB Output is correct
75 Correct 125 ms 35044 KB Output is correct
76 Correct 212 ms 40220 KB Output is correct
77 Correct 195 ms 39236 KB Output is correct
78 Correct 124 ms 35136 KB Output is correct
79 Correct 123 ms 35116 KB Output is correct
80 Correct 177 ms 38520 KB Output is correct
81 Correct 127 ms 35116 KB Output is correct
82 Correct 212 ms 40188 KB Output is correct
83 Correct 203 ms 39820 KB Output is correct
84 Correct 124 ms 35028 KB Output is correct
85 Correct 125 ms 35020 KB Output is correct
86 Correct 175 ms 38900 KB Output is correct
87 Correct 198 ms 40220 KB Output is correct
88 Correct 153 ms 35076 KB Output is correct
89 Correct 183 ms 39420 KB Output is correct
90 Correct 186 ms 40220 KB Output is correct
91 Correct 129 ms 35012 KB Output is correct
92 Correct 187 ms 38748 KB Output is correct
93 Correct 123 ms 35020 KB Output is correct
94 Correct 130 ms 35064 KB Output is correct
95 Correct 123 ms 35036 KB Output is correct
96 Correct 199 ms 40012 KB Output is correct
97 Correct 145 ms 40212 KB Output is correct
98 Correct 186 ms 38524 KB Output is correct
99 Correct 274 ms 40372 KB Output is correct
100 Correct 140 ms 39600 KB Output is correct