Submission #1051925

# Submission time Handle Problem Language Result Execution time Memory
1051925 2024-08-10T10:37:44 Z Sacharlemagne Crossing (JOI21_crossing) C++17
100 / 100
199 ms 41848 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7, BASE = 5, MXN = 2e5+5;
ll Pow[MXN], Same[MXN];
ll getVal(char c) {
    if (c == 'J') return 1;
    if (c == 'O') return 2;
    return 3;
}
char cross(char a, char b) {
    if (a == b) return a;
    if (a != 'O' && b != 'O') return 'O';
    if (a != 'J' && b != 'J') return 'J';
    return 'I';
}
string merge(string a, string b) {
    string c(a.size(), ' ');
    for (int i = 0; i<a.size(); ++i) {
        c[i] = cross(a[i], b[i]);
    }
    return c;
}
vector<ll> starter;
struct Node {
    ll l,r, mid,sz, set, hash;
    Node *lp, *rp;
    void blaSet(ll val) {
        hash = val * Same[sz-1];
        set = val;
    }
    void pull() {
        hash = lp->hash * Pow[rp->sz] + rp->hash;
        hash %= MOD;
    }
    void push() {
        if (set != -1) {
            lp->blaSet(set), rp->blaSet(set);
            set = -1;
        }
    }
    Node(ll l, ll r) : l(l), r(r), mid((l+r)/2), sz(r-l+1), set(-1) {
        if (l != r) {
            lp = new Node(l, mid), rp = new Node(mid+1,r);
            pull();
        }
        else blaSet(starter[l]);
    }
    void update(int s, int e, ll val) {
        if (s > r || e < l) return;
        if (s <= l && e >= r) {
            blaSet(val);
            return;
        }
        push();
        if (s <= mid) lp->update(s,e,val);
        if (e > mid) rp->update(s,e,val);
        pull();
    }
};
void init() {
    Pow[0] = 1; Same[0] = 1;
    for (int i = 1; i<MXN; ++i) {
        Pow[i] = (Pow[i-1] * BASE) % MOD;
        Same[i] = (Same[i-1] * BASE + 1) % MOD;
    }
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n,q; cin >> n;
    init();

    vector<string> start(3);
    set<string> s;
    for (string &S :start) {
        cin >> S;
        s.insert(S);
    }
    for (int i = 0; i<3; ++i) for (int j = i+1; j<3; ++j) s.insert(merge(start[i], start[j]));
    s.insert(merge(start[0], merge(start[2], start[1])));
    s.insert(merge(start[1], merge(start[2], start[0])));
    s.insert(merge(start[2], merge(start[1], start[0])));
    set<ll> hashs;
    for (string str : s) {
        ll tot = 0;
        for (int i = 0; i < n; ++i) tot = (tot * BASE + getVal(str[i])) % MOD;
        hashs.insert(tot);
    }
    cin >> q;
    string seq; cin >> seq;
    cout << (s.count(seq) ? "Yes" : "No") << '\n';
    starter.resize(n);
    for (int i = 0; i<n; ++i) starter[i] = getVal(seq[i]);
    Node *seg = new Node(0, n-1);
    while (q--) {
        int l,r; char c;
        cin >> l >> r >> c;
        ll ne = getVal(c);
        seg->update(l-1,r-1,ne);
        cout << (hashs.count(seg->hash) ? "Yes" : "No") << '\n';
    }
}

/*
 * 7
OOOOOOO
OOOOOOO
OOOOOOO
4
OOOOOOO
 */

Compilation message

Main.cpp: In function 'std::string merge(std::string, std::string)':
Main.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i<a.size(); ++i) {
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3924 KB Output is correct
2 Correct 44 ms 4184 KB Output is correct
3 Correct 39 ms 4180 KB Output is correct
4 Correct 41 ms 4076 KB Output is correct
5 Correct 35 ms 4108 KB Output is correct
6 Correct 36 ms 3932 KB Output is correct
7 Correct 36 ms 4056 KB Output is correct
8 Correct 37 ms 4180 KB Output is correct
9 Correct 38 ms 4176 KB Output is correct
10 Correct 38 ms 4180 KB Output is correct
11 Correct 39 ms 4188 KB Output is correct
12 Correct 37 ms 4064 KB Output is correct
13 Correct 39 ms 4052 KB Output is correct
14 Correct 38 ms 4180 KB Output is correct
15 Correct 37 ms 4056 KB Output is correct
16 Correct 38 ms 4180 KB Output is correct
17 Correct 42 ms 4092 KB Output is correct
18 Correct 36 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3924 KB Output is correct
2 Correct 44 ms 4184 KB Output is correct
3 Correct 39 ms 4180 KB Output is correct
4 Correct 41 ms 4076 KB Output is correct
5 Correct 35 ms 4108 KB Output is correct
6 Correct 36 ms 3932 KB Output is correct
7 Correct 36 ms 4056 KB Output is correct
8 Correct 37 ms 4180 KB Output is correct
9 Correct 38 ms 4176 KB Output is correct
10 Correct 38 ms 4180 KB Output is correct
11 Correct 39 ms 4188 KB Output is correct
12 Correct 37 ms 4064 KB Output is correct
13 Correct 39 ms 4052 KB Output is correct
14 Correct 38 ms 4180 KB Output is correct
15 Correct 37 ms 4056 KB Output is correct
16 Correct 38 ms 4180 KB Output is correct
17 Correct 42 ms 4092 KB Output is correct
18 Correct 36 ms 4184 KB Output is correct
19 Correct 170 ms 37928 KB Output is correct
20 Correct 153 ms 37884 KB Output is correct
21 Correct 120 ms 35760 KB Output is correct
22 Correct 124 ms 32652 KB Output is correct
23 Correct 67 ms 5692 KB Output is correct
24 Correct 69 ms 5716 KB Output is correct
25 Correct 131 ms 37868 KB Output is correct
26 Correct 128 ms 37984 KB Output is correct
27 Correct 148 ms 38136 KB Output is correct
28 Correct 146 ms 37872 KB Output is correct
29 Correct 134 ms 36928 KB Output is correct
30 Correct 71 ms 5712 KB Output is correct
31 Correct 133 ms 37880 KB Output is correct
32 Correct 138 ms 34960 KB Output is correct
33 Correct 68 ms 5628 KB Output is correct
34 Correct 146 ms 37808 KB Output is correct
35 Correct 108 ms 29232 KB Output is correct
36 Correct 69 ms 5804 KB Output is correct
37 Correct 66 ms 5748 KB Output is correct
38 Correct 128 ms 37828 KB Output is correct
39 Correct 77 ms 37880 KB Output is correct
40 Correct 115 ms 26316 KB Output is correct
41 Correct 199 ms 38236 KB Output is correct
42 Correct 77 ms 38140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3924 KB Output is correct
2 Correct 44 ms 4184 KB Output is correct
3 Correct 39 ms 4180 KB Output is correct
4 Correct 41 ms 4076 KB Output is correct
5 Correct 35 ms 4108 KB Output is correct
6 Correct 36 ms 3932 KB Output is correct
7 Correct 36 ms 4056 KB Output is correct
8 Correct 37 ms 4180 KB Output is correct
9 Correct 38 ms 4176 KB Output is correct
10 Correct 38 ms 4180 KB Output is correct
11 Correct 39 ms 4188 KB Output is correct
12 Correct 37 ms 4064 KB Output is correct
13 Correct 39 ms 4052 KB Output is correct
14 Correct 38 ms 4180 KB Output is correct
15 Correct 37 ms 4056 KB Output is correct
16 Correct 38 ms 4180 KB Output is correct
17 Correct 42 ms 4092 KB Output is correct
18 Correct 36 ms 4184 KB Output is correct
19 Correct 62 ms 3924 KB Output is correct
20 Correct 48 ms 4176 KB Output is correct
21 Correct 50 ms 4180 KB Output is correct
22 Correct 50 ms 4948 KB Output is correct
23 Correct 40 ms 5176 KB Output is correct
24 Correct 41 ms 4948 KB Output is correct
25 Correct 42 ms 5200 KB Output is correct
26 Correct 37 ms 5176 KB Output is correct
27 Correct 44 ms 5180 KB Output is correct
28 Correct 41 ms 5020 KB Output is correct
29 Correct 53 ms 5456 KB Output is correct
30 Correct 35 ms 4948 KB Output is correct
31 Correct 58 ms 5104 KB Output is correct
32 Correct 45 ms 5032 KB Output is correct
33 Correct 44 ms 5012 KB Output is correct
34 Correct 42 ms 4944 KB Output is correct
35 Correct 44 ms 5204 KB Output is correct
36 Correct 42 ms 5104 KB Output is correct
37 Correct 43 ms 5096 KB Output is correct
38 Correct 42 ms 5204 KB Output is correct
39 Correct 42 ms 5204 KB Output is correct
40 Correct 63 ms 5036 KB Output is correct
41 Correct 44 ms 5208 KB Output is correct
42 Correct 51 ms 5200 KB Output is correct
43 Correct 41 ms 5204 KB Output is correct
44 Correct 65 ms 5088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3924 KB Output is correct
2 Correct 44 ms 4184 KB Output is correct
3 Correct 39 ms 4180 KB Output is correct
4 Correct 41 ms 4076 KB Output is correct
5 Correct 35 ms 4108 KB Output is correct
6 Correct 36 ms 3932 KB Output is correct
7 Correct 36 ms 4056 KB Output is correct
8 Correct 37 ms 4180 KB Output is correct
9 Correct 38 ms 4176 KB Output is correct
10 Correct 38 ms 4180 KB Output is correct
11 Correct 39 ms 4188 KB Output is correct
12 Correct 37 ms 4064 KB Output is correct
13 Correct 39 ms 4052 KB Output is correct
14 Correct 38 ms 4180 KB Output is correct
15 Correct 37 ms 4056 KB Output is correct
16 Correct 38 ms 4180 KB Output is correct
17 Correct 42 ms 4092 KB Output is correct
18 Correct 36 ms 4184 KB Output is correct
19 Correct 170 ms 37928 KB Output is correct
20 Correct 153 ms 37884 KB Output is correct
21 Correct 120 ms 35760 KB Output is correct
22 Correct 124 ms 32652 KB Output is correct
23 Correct 67 ms 5692 KB Output is correct
24 Correct 69 ms 5716 KB Output is correct
25 Correct 131 ms 37868 KB Output is correct
26 Correct 128 ms 37984 KB Output is correct
27 Correct 148 ms 38136 KB Output is correct
28 Correct 146 ms 37872 KB Output is correct
29 Correct 134 ms 36928 KB Output is correct
30 Correct 71 ms 5712 KB Output is correct
31 Correct 133 ms 37880 KB Output is correct
32 Correct 138 ms 34960 KB Output is correct
33 Correct 68 ms 5628 KB Output is correct
34 Correct 146 ms 37808 KB Output is correct
35 Correct 108 ms 29232 KB Output is correct
36 Correct 69 ms 5804 KB Output is correct
37 Correct 66 ms 5748 KB Output is correct
38 Correct 128 ms 37828 KB Output is correct
39 Correct 77 ms 37880 KB Output is correct
40 Correct 115 ms 26316 KB Output is correct
41 Correct 199 ms 38236 KB Output is correct
42 Correct 77 ms 38140 KB Output is correct
43 Correct 62 ms 3924 KB Output is correct
44 Correct 48 ms 4176 KB Output is correct
45 Correct 50 ms 4180 KB Output is correct
46 Correct 50 ms 4948 KB Output is correct
47 Correct 40 ms 5176 KB Output is correct
48 Correct 41 ms 4948 KB Output is correct
49 Correct 42 ms 5200 KB Output is correct
50 Correct 37 ms 5176 KB Output is correct
51 Correct 44 ms 5180 KB Output is correct
52 Correct 41 ms 5020 KB Output is correct
53 Correct 53 ms 5456 KB Output is correct
54 Correct 35 ms 4948 KB Output is correct
55 Correct 58 ms 5104 KB Output is correct
56 Correct 45 ms 5032 KB Output is correct
57 Correct 44 ms 5012 KB Output is correct
58 Correct 42 ms 4944 KB Output is correct
59 Correct 44 ms 5204 KB Output is correct
60 Correct 42 ms 5104 KB Output is correct
61 Correct 43 ms 5096 KB Output is correct
62 Correct 42 ms 5204 KB Output is correct
63 Correct 42 ms 5204 KB Output is correct
64 Correct 63 ms 5036 KB Output is correct
65 Correct 44 ms 5208 KB Output is correct
66 Correct 51 ms 5200 KB Output is correct
67 Correct 41 ms 5204 KB Output is correct
68 Correct 65 ms 5088 KB Output is correct
69 Correct 169 ms 35516 KB Output is correct
70 Correct 162 ms 41516 KB Output is correct
71 Correct 70 ms 7376 KB Output is correct
72 Correct 71 ms 7324 KB Output is correct
73 Correct 70 ms 7508 KB Output is correct
74 Correct 125 ms 34304 KB Output is correct
75 Correct 70 ms 7236 KB Output is correct
76 Correct 139 ms 40420 KB Output is correct
77 Correct 130 ms 34624 KB Output is correct
78 Correct 70 ms 7248 KB Output is correct
79 Correct 71 ms 7340 KB Output is correct
80 Correct 121 ms 31080 KB Output is correct
81 Correct 72 ms 7248 KB Output is correct
82 Correct 157 ms 41616 KB Output is correct
83 Correct 148 ms 39448 KB Output is correct
84 Correct 73 ms 7320 KB Output is correct
85 Correct 75 ms 7660 KB Output is correct
86 Correct 139 ms 32776 KB Output is correct
87 Correct 153 ms 41588 KB Output is correct
88 Correct 77 ms 7548 KB Output is correct
89 Correct 144 ms 37628 KB Output is correct
90 Correct 171 ms 41584 KB Output is correct
91 Correct 76 ms 7508 KB Output is correct
92 Correct 132 ms 32548 KB Output is correct
93 Correct 72 ms 7252 KB Output is correct
94 Correct 74 ms 7348 KB Output is correct
95 Correct 73 ms 7316 KB Output is correct
96 Correct 123 ms 39928 KB Output is correct
97 Correct 86 ms 41464 KB Output is correct
98 Correct 136 ms 29248 KB Output is correct
99 Correct 193 ms 41848 KB Output is correct
100 Correct 58 ms 41376 KB Output is correct