Submission #906005

# Submission time Handle Problem Language Result Execution time Memory
906005 2024-01-13T09:09:18 Z hmm789 Crossing (JOI21_crossing) C++14
100 / 100
5637 ms 307304 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000
#define MOD 998244353

struct node {
    int s, e, m, v, ans, lz;
    node *l, *r;
    node(int _s, int _e, vector<int> &vec, vector<int> &qry) {
        s = _s, e = _e, m = (s+e)/2, lz = -1;
        if(s != e) {
            l = new node(s, m, vec, qry);
            r = new node(m+1, e, vec, qry);
            if(l->v == -1 || r->v == -1 || l->v != r->v) v = -1;
            else v = l->v;
            ans = l->ans & r->ans;
        } else {
            v = vec[s];
            ans = vec[s] == qry[s];
        }
    }
    void prop() {
        if(lz == -1) return;
        ans = lz == v;
        if(s != e) {
            l->lz = lz;
            r->lz = lz;
        }
        lz = -1;
    }
    void update(int x, int y, int val) {
        prop();
        if(x <= s && e <= y) {lz = val; return;}
        else if(x > m) r->update(x, y, val);
        else if(y <= m) l->update(x, y, val);
        else l->update(x, y, val), r->update(x, y, val);
        l->prop(); r->prop();
        ans = l->ans & r->ans;
    }
    int query() {
        prop();
        return ans;
    }
} *root[27];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q, l, r, x;
    cin >> n;
    int a[3][n];
    string s;
    for(int j = 0; j < 3; j++) {
        cin >> s;
        for(int i = 0; i < n; i++) {
            if(s[i] == 'J') a[j][i] = 0;
            else if(s[i] == 'O') a[j][i] = 1;
            else a[j][i] = 2;
        }
    }
    vector<vector<int>> valid;
    for(int x = 0; x < 3; x++) {
        for(int y = 0; y < 3; y++) {
            for(int z = 0; z < 3; z++) {
                if((x+y+z)%3 != 1) continue;
                vector<int> v;
                for(int i = 0; i < n; i++) {
                    v.push_back((a[0][i]*x+a[1][i]*y+a[2][i]*z)%3);
                }
                valid.push_back(v);
            }
        }
    }
    cin >> q >> s;
    vector<int> vs;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'J') vs.push_back(0);
        else if(s[i] == 'O') vs.push_back(1);
        else vs.push_back(2);
    }
    int ans = 0;
    for(int i = 0; i < valid.size(); i++) {
        root[i] = new node(0, n-1, valid[i], vs);
        if(root[i]->query()) ans = 1;
    }
    cout << (ans?"Yes":"No") << '\n';
    char c;
    while(q--) {
        cin >> l >> r >> c;
        l--; r--;
        if(c == 'J') x = 0;
        else if(c == 'O') x = 1;
        else x = 2;
        ans = 0;
        for(int i = 0; i < valid.size(); i++) {
            root[i]->update(l, r, x);
            if(root[i]->query()) ans = 1;
        }
        cout << (ans?"Yes":"No") << '\n';
    }
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:83:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i = 0; i < valid.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
Main.cpp:96:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |         for(int i = 0; i < valid.size(); i++) {
      |                        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 151 ms 916 KB Output is correct
2 Correct 182 ms 944 KB Output is correct
3 Correct 213 ms 1104 KB Output is correct
4 Correct 135 ms 1108 KB Output is correct
5 Correct 132 ms 988 KB Output is correct
6 Correct 137 ms 1104 KB Output is correct
7 Correct 137 ms 1296 KB Output is correct
8 Correct 173 ms 1092 KB Output is correct
9 Correct 146 ms 1104 KB Output is correct
10 Correct 142 ms 1092 KB Output is correct
11 Correct 158 ms 1064 KB Output is correct
12 Correct 142 ms 976 KB Output is correct
13 Correct 171 ms 1028 KB Output is correct
14 Correct 150 ms 1192 KB Output is correct
15 Correct 153 ms 1104 KB Output is correct
16 Correct 142 ms 976 KB Output is correct
17 Correct 148 ms 952 KB Output is correct
18 Correct 159 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 916 KB Output is correct
2 Correct 182 ms 944 KB Output is correct
3 Correct 213 ms 1104 KB Output is correct
4 Correct 135 ms 1108 KB Output is correct
5 Correct 132 ms 988 KB Output is correct
6 Correct 137 ms 1104 KB Output is correct
7 Correct 137 ms 1296 KB Output is correct
8 Correct 173 ms 1092 KB Output is correct
9 Correct 146 ms 1104 KB Output is correct
10 Correct 142 ms 1092 KB Output is correct
11 Correct 158 ms 1064 KB Output is correct
12 Correct 142 ms 976 KB Output is correct
13 Correct 171 ms 1028 KB Output is correct
14 Correct 150 ms 1192 KB Output is correct
15 Correct 153 ms 1104 KB Output is correct
16 Correct 142 ms 976 KB Output is correct
17 Correct 148 ms 952 KB Output is correct
18 Correct 159 ms 964 KB Output is correct
19 Correct 5070 ms 306112 KB Output is correct
20 Correct 3517 ms 306892 KB Output is correct
21 Correct 3311 ms 289252 KB Output is correct
22 Correct 3307 ms 259460 KB Output is correct
23 Correct 775 ms 19352 KB Output is correct
24 Correct 747 ms 18996 KB Output is correct
25 Correct 3414 ms 307024 KB Output is correct
26 Correct 3748 ms 307012 KB Output is correct
27 Correct 4333 ms 307268 KB Output is correct
28 Correct 4551 ms 307112 KB Output is correct
29 Correct 4050 ms 298776 KB Output is correct
30 Correct 812 ms 19212 KB Output is correct
31 Correct 4086 ms 306984 KB Output is correct
32 Correct 4177 ms 280080 KB Output is correct
33 Correct 694 ms 18300 KB Output is correct
34 Correct 4122 ms 307040 KB Output is correct
35 Correct 2974 ms 229192 KB Output is correct
36 Correct 663 ms 18476 KB Output is correct
37 Correct 617 ms 18800 KB Output is correct
38 Correct 2937 ms 307036 KB Output is correct
39 Correct 519 ms 307244 KB Output is correct
40 Correct 3454 ms 203004 KB Output is correct
41 Correct 5637 ms 307172 KB Output is correct
42 Correct 239 ms 306536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 916 KB Output is correct
2 Correct 182 ms 944 KB Output is correct
3 Correct 213 ms 1104 KB Output is correct
4 Correct 135 ms 1108 KB Output is correct
5 Correct 132 ms 988 KB Output is correct
6 Correct 137 ms 1104 KB Output is correct
7 Correct 137 ms 1296 KB Output is correct
8 Correct 173 ms 1092 KB Output is correct
9 Correct 146 ms 1104 KB Output is correct
10 Correct 142 ms 1092 KB Output is correct
11 Correct 158 ms 1064 KB Output is correct
12 Correct 142 ms 976 KB Output is correct
13 Correct 171 ms 1028 KB Output is correct
14 Correct 150 ms 1192 KB Output is correct
15 Correct 153 ms 1104 KB Output is correct
16 Correct 142 ms 976 KB Output is correct
17 Correct 148 ms 952 KB Output is correct
18 Correct 159 ms 964 KB Output is correct
19 Correct 168 ms 1032 KB Output is correct
20 Correct 184 ms 1184 KB Output is correct
21 Correct 144 ms 1032 KB Output is correct
22 Correct 137 ms 1184 KB Output is correct
23 Correct 142 ms 1108 KB Output is correct
24 Correct 147 ms 1324 KB Output is correct
25 Correct 144 ms 1104 KB Output is correct
26 Correct 128 ms 1104 KB Output is correct
27 Correct 143 ms 1304 KB Output is correct
28 Correct 129 ms 884 KB Output is correct
29 Correct 144 ms 960 KB Output is correct
30 Correct 128 ms 880 KB Output is correct
31 Correct 174 ms 1088 KB Output is correct
32 Correct 143 ms 1048 KB Output is correct
33 Correct 190 ms 1136 KB Output is correct
34 Correct 137 ms 928 KB Output is correct
35 Correct 149 ms 1128 KB Output is correct
36 Correct 156 ms 1212 KB Output is correct
37 Correct 143 ms 1108 KB Output is correct
38 Correct 148 ms 1120 KB Output is correct
39 Correct 143 ms 1108 KB Output is correct
40 Correct 147 ms 1184 KB Output is correct
41 Correct 146 ms 1104 KB Output is correct
42 Correct 151 ms 1012 KB Output is correct
43 Correct 139 ms 1104 KB Output is correct
44 Correct 146 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 916 KB Output is correct
2 Correct 182 ms 944 KB Output is correct
3 Correct 213 ms 1104 KB Output is correct
4 Correct 135 ms 1108 KB Output is correct
5 Correct 132 ms 988 KB Output is correct
6 Correct 137 ms 1104 KB Output is correct
7 Correct 137 ms 1296 KB Output is correct
8 Correct 173 ms 1092 KB Output is correct
9 Correct 146 ms 1104 KB Output is correct
10 Correct 142 ms 1092 KB Output is correct
11 Correct 158 ms 1064 KB Output is correct
12 Correct 142 ms 976 KB Output is correct
13 Correct 171 ms 1028 KB Output is correct
14 Correct 150 ms 1192 KB Output is correct
15 Correct 153 ms 1104 KB Output is correct
16 Correct 142 ms 976 KB Output is correct
17 Correct 148 ms 952 KB Output is correct
18 Correct 159 ms 964 KB Output is correct
19 Correct 5070 ms 306112 KB Output is correct
20 Correct 3517 ms 306892 KB Output is correct
21 Correct 3311 ms 289252 KB Output is correct
22 Correct 3307 ms 259460 KB Output is correct
23 Correct 775 ms 19352 KB Output is correct
24 Correct 747 ms 18996 KB Output is correct
25 Correct 3414 ms 307024 KB Output is correct
26 Correct 3748 ms 307012 KB Output is correct
27 Correct 4333 ms 307268 KB Output is correct
28 Correct 4551 ms 307112 KB Output is correct
29 Correct 4050 ms 298776 KB Output is correct
30 Correct 812 ms 19212 KB Output is correct
31 Correct 4086 ms 306984 KB Output is correct
32 Correct 4177 ms 280080 KB Output is correct
33 Correct 694 ms 18300 KB Output is correct
34 Correct 4122 ms 307040 KB Output is correct
35 Correct 2974 ms 229192 KB Output is correct
36 Correct 663 ms 18476 KB Output is correct
37 Correct 617 ms 18800 KB Output is correct
38 Correct 2937 ms 307036 KB Output is correct
39 Correct 519 ms 307244 KB Output is correct
40 Correct 3454 ms 203004 KB Output is correct
41 Correct 5637 ms 307172 KB Output is correct
42 Correct 239 ms 306536 KB Output is correct
43 Correct 168 ms 1032 KB Output is correct
44 Correct 184 ms 1184 KB Output is correct
45 Correct 144 ms 1032 KB Output is correct
46 Correct 137 ms 1184 KB Output is correct
47 Correct 142 ms 1108 KB Output is correct
48 Correct 147 ms 1324 KB Output is correct
49 Correct 144 ms 1104 KB Output is correct
50 Correct 128 ms 1104 KB Output is correct
51 Correct 143 ms 1304 KB Output is correct
52 Correct 129 ms 884 KB Output is correct
53 Correct 144 ms 960 KB Output is correct
54 Correct 128 ms 880 KB Output is correct
55 Correct 174 ms 1088 KB Output is correct
56 Correct 143 ms 1048 KB Output is correct
57 Correct 190 ms 1136 KB Output is correct
58 Correct 137 ms 928 KB Output is correct
59 Correct 149 ms 1128 KB Output is correct
60 Correct 156 ms 1212 KB Output is correct
61 Correct 143 ms 1108 KB Output is correct
62 Correct 148 ms 1120 KB Output is correct
63 Correct 143 ms 1108 KB Output is correct
64 Correct 147 ms 1184 KB Output is correct
65 Correct 146 ms 1104 KB Output is correct
66 Correct 151 ms 1012 KB Output is correct
67 Correct 139 ms 1104 KB Output is correct
68 Correct 146 ms 1108 KB Output is correct
69 Correct 4407 ms 257160 KB Output is correct
70 Correct 3544 ms 306816 KB Output is correct
71 Correct 695 ms 18648 KB Output is correct
72 Correct 691 ms 18860 KB Output is correct
73 Correct 698 ms 19156 KB Output is correct
74 Correct 3022 ms 256248 KB Output is correct
75 Correct 627 ms 18864 KB Output is correct
76 Correct 3268 ms 307044 KB Output is correct
77 Correct 3129 ms 256844 KB Output is correct
78 Correct 639 ms 18664 KB Output is correct
79 Correct 619 ms 18844 KB Output is correct
80 Correct 2825 ms 219204 KB Output is correct
81 Correct 916 ms 18580 KB Output is correct
82 Correct 3599 ms 307088 KB Output is correct
83 Correct 3766 ms 288584 KB Output is correct
84 Correct 882 ms 18424 KB Output is correct
85 Correct 765 ms 18516 KB Output is correct
86 Correct 3849 ms 233748 KB Output is correct
87 Correct 4359 ms 306856 KB Output is correct
88 Correct 618 ms 18896 KB Output is correct
89 Correct 3776 ms 270948 KB Output is correct
90 Correct 4042 ms 306976 KB Output is correct
91 Correct 649 ms 18648 KB Output is correct
92 Correct 2947 ms 230496 KB Output is correct
93 Correct 535 ms 18512 KB Output is correct
94 Correct 756 ms 18652 KB Output is correct
95 Correct 724 ms 19104 KB Output is correct
96 Correct 2966 ms 307168 KB Output is correct
97 Correct 530 ms 307080 KB Output is correct
98 Correct 3416 ms 202352 KB Output is correct
99 Correct 5572 ms 307304 KB Output is correct
100 Correct 247 ms 306480 KB Output is correct