Submission #423397

# Submission time Handle Problem Language Result Execution time Memory
423397 2021-06-11T05:07:56 Z benedict0724 Crossing (JOI21_crossing) C++17
100 / 100
969 ms 79656 KB
#include <iostream>

using namespace std;

int tree[800002][9], a[800002][9], b[800002][9], c[800002][9], lazy[800002];
int n, q;
string s[9], t;

string P(string S, string T)
{
    string ans;
    ans.resize(n);
    for(int i=0;i<n;i++)
    {
        if(S[i] == T[i]) ans[i] = S[i];
        else ans[i] = 'J' + 'O' + 'I' - S[i] - T[i];
    }
    return ans;
}

void propagate(int i, int l, int r)
{
    if(lazy[i] == 0) return;
    for(int j=0;j<9;j++)
    {
        if(lazy[i] == 1 && b[i][j] == 0 && c[i][j] == 0) tree[i][j] = 1;
        else if(lazy[i] == 2 && a[i][j] == 0 && c[i][j] == 0) tree[i][j] = 1;
        else if(lazy[i] == 3 && a[i][j] == 0 && b[i][j] == 0) tree[i][j] = 1;
        else tree[i][j] = 0;
    }

    if(l != r)
    {
        lazy[i*2] = lazy[i];
        lazy[i*2+1] = lazy[i];
    }
    lazy[i] = 0;
}

void init(int i, int l, int r)
{
    if(l == r)
    {
        for(int j=0;j<9;j++) if(s[j][l] == 'J') a[i][j] = 1;
        for(int j=0;j<9;j++) if(s[j][l] == 'O') b[i][j] = 1;
        for(int j=0;j<9;j++) if(s[j][l] == 'I') c[i][j] = 1;
        for(int j=0;j<9;j++) if(s[j][l] == t[l]) tree[i][j] = 1;
        return;
    }
    int m = (l + r)/2;
    init(i*2, l, m);
    init(i*2+1, m+1, r);
    for(int j=0;j<9;j++)
    {
        a[i][j] = a[i*2][j] | a[i*2+1][j];
        b[i][j] = b[i*2][j] | b[i*2+1][j];
        c[i][j] = c[i*2][j] | c[i*2+1][j];
        tree[i][j] = tree[i*2][j] & tree[i*2+1][j];
    }
}

void update(int i, int l, int r, int s, int e, int v)
{
    propagate(i, l, r);
    if(e < l || r < s) return;
    if(s <= l && r <= e)
    {
        lazy[i] = v;
        propagate(i, l, r);
        return;
    }
    int m = (l + r)/2;
    update(i*2, l, m, s, e, v);
    update(i*2+1, m+1, r, s, e, v);
    for(int j=0;j<9;j++) tree[i][j] = tree[i*2][j] & tree[i*2+1][j];
}

int query()
{
    for(int i=0;i<9;i++)
    {
        if(tree[1][i]) return 1;
    }
    return 0;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    cin >> s[0] >> s[1] >> s[2];
    s[3] = P(s[0], s[1]);
    s[4] = P(s[0], s[2]);
    s[5] = P(s[1], s[2]);
    s[6] = P(s[0], s[5]);
    s[7] = P(s[1], s[4]);
    s[8] = P(s[2], s[3]);
    cin >> q;
    cin >> t;
    init(1, 0, n-1);
    cout << (query() ? "Yes\n" : "No\n");
    for(int i=1;i<=q;i++)
    {
        int l, r, ch; char c;
        cin >> l >> r >> c;
        if(c == 'J') ch = 1;
        if(c == 'O') ch = 2;
        if(c == 'I') ch = 3;
        update(1, 0, n-1, l-1, r-1, ch);
        cout << (query() ? "Yes\n" : "No\n");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:109:15: warning: 'ch' may be used uninitialized in this function [-Wmaybe-uninitialized]
  109 |         update(1, 0, n-1, l-1, r-1, ch);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 145 ms 968 KB Output is correct
2 Correct 161 ms 856 KB Output is correct
3 Correct 170 ms 924 KB Output is correct
4 Correct 151 ms 852 KB Output is correct
5 Correct 120 ms 836 KB Output is correct
6 Correct 131 ms 928 KB Output is correct
7 Correct 124 ms 972 KB Output is correct
8 Correct 159 ms 940 KB Output is correct
9 Correct 132 ms 880 KB Output is correct
10 Correct 130 ms 1020 KB Output is correct
11 Correct 133 ms 944 KB Output is correct
12 Correct 129 ms 948 KB Output is correct
13 Correct 131 ms 928 KB Output is correct
14 Correct 127 ms 964 KB Output is correct
15 Correct 131 ms 940 KB Output is correct
16 Correct 126 ms 912 KB Output is correct
17 Correct 134 ms 940 KB Output is correct
18 Correct 153 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 968 KB Output is correct
2 Correct 161 ms 856 KB Output is correct
3 Correct 170 ms 924 KB Output is correct
4 Correct 151 ms 852 KB Output is correct
5 Correct 120 ms 836 KB Output is correct
6 Correct 131 ms 928 KB Output is correct
7 Correct 124 ms 972 KB Output is correct
8 Correct 159 ms 940 KB Output is correct
9 Correct 132 ms 880 KB Output is correct
10 Correct 130 ms 1020 KB Output is correct
11 Correct 133 ms 944 KB Output is correct
12 Correct 129 ms 948 KB Output is correct
13 Correct 131 ms 928 KB Output is correct
14 Correct 127 ms 964 KB Output is correct
15 Correct 131 ms 940 KB Output is correct
16 Correct 126 ms 912 KB Output is correct
17 Correct 134 ms 940 KB Output is correct
18 Correct 153 ms 884 KB Output is correct
19 Correct 865 ms 79272 KB Output is correct
20 Correct 726 ms 77540 KB Output is correct
21 Correct 442 ms 79044 KB Output is correct
22 Correct 498 ms 78804 KB Output is correct
23 Correct 232 ms 5792 KB Output is correct
24 Correct 230 ms 5776 KB Output is correct
25 Correct 491 ms 79288 KB Output is correct
26 Correct 534 ms 79204 KB Output is correct
27 Correct 702 ms 73308 KB Output is correct
28 Correct 741 ms 73388 KB Output is correct
29 Correct 638 ms 70216 KB Output is correct
30 Correct 288 ms 5752 KB Output is correct
31 Correct 659 ms 70700 KB Output is correct
32 Correct 627 ms 74360 KB Output is correct
33 Correct 234 ms 5752 KB Output is correct
34 Correct 680 ms 74940 KB Output is correct
35 Correct 436 ms 78484 KB Output is correct
36 Correct 242 ms 5816 KB Output is correct
37 Correct 240 ms 5740 KB Output is correct
38 Correct 682 ms 59268 KB Output is correct
39 Correct 242 ms 77284 KB Output is correct
40 Correct 440 ms 35860 KB Output is correct
41 Correct 872 ms 61020 KB Output is correct
42 Correct 102 ms 58852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 968 KB Output is correct
2 Correct 161 ms 856 KB Output is correct
3 Correct 170 ms 924 KB Output is correct
4 Correct 151 ms 852 KB Output is correct
5 Correct 120 ms 836 KB Output is correct
6 Correct 131 ms 928 KB Output is correct
7 Correct 124 ms 972 KB Output is correct
8 Correct 159 ms 940 KB Output is correct
9 Correct 132 ms 880 KB Output is correct
10 Correct 130 ms 1020 KB Output is correct
11 Correct 133 ms 944 KB Output is correct
12 Correct 129 ms 948 KB Output is correct
13 Correct 131 ms 928 KB Output is correct
14 Correct 127 ms 964 KB Output is correct
15 Correct 131 ms 940 KB Output is correct
16 Correct 126 ms 912 KB Output is correct
17 Correct 134 ms 940 KB Output is correct
18 Correct 153 ms 884 KB Output is correct
19 Correct 214 ms 848 KB Output is correct
20 Correct 185 ms 920 KB Output is correct
21 Correct 144 ms 940 KB Output is correct
22 Correct 132 ms 960 KB Output is correct
23 Correct 144 ms 1008 KB Output is correct
24 Correct 158 ms 916 KB Output is correct
25 Correct 148 ms 1044 KB Output is correct
26 Correct 137 ms 892 KB Output is correct
27 Correct 147 ms 952 KB Output is correct
28 Correct 131 ms 884 KB Output is correct
29 Correct 152 ms 960 KB Output is correct
30 Correct 130 ms 832 KB Output is correct
31 Correct 165 ms 864 KB Output is correct
32 Correct 165 ms 972 KB Output is correct
33 Correct 197 ms 940 KB Output is correct
34 Correct 153 ms 924 KB Output is correct
35 Correct 164 ms 880 KB Output is correct
36 Correct 171 ms 968 KB Output is correct
37 Correct 169 ms 876 KB Output is correct
38 Correct 170 ms 964 KB Output is correct
39 Correct 192 ms 884 KB Output is correct
40 Correct 170 ms 876 KB Output is correct
41 Correct 169 ms 940 KB Output is correct
42 Correct 180 ms 960 KB Output is correct
43 Correct 161 ms 940 KB Output is correct
44 Correct 168 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 968 KB Output is correct
2 Correct 161 ms 856 KB Output is correct
3 Correct 170 ms 924 KB Output is correct
4 Correct 151 ms 852 KB Output is correct
5 Correct 120 ms 836 KB Output is correct
6 Correct 131 ms 928 KB Output is correct
7 Correct 124 ms 972 KB Output is correct
8 Correct 159 ms 940 KB Output is correct
9 Correct 132 ms 880 KB Output is correct
10 Correct 130 ms 1020 KB Output is correct
11 Correct 133 ms 944 KB Output is correct
12 Correct 129 ms 948 KB Output is correct
13 Correct 131 ms 928 KB Output is correct
14 Correct 127 ms 964 KB Output is correct
15 Correct 131 ms 940 KB Output is correct
16 Correct 126 ms 912 KB Output is correct
17 Correct 134 ms 940 KB Output is correct
18 Correct 153 ms 884 KB Output is correct
19 Correct 865 ms 79272 KB Output is correct
20 Correct 726 ms 77540 KB Output is correct
21 Correct 442 ms 79044 KB Output is correct
22 Correct 498 ms 78804 KB Output is correct
23 Correct 232 ms 5792 KB Output is correct
24 Correct 230 ms 5776 KB Output is correct
25 Correct 491 ms 79288 KB Output is correct
26 Correct 534 ms 79204 KB Output is correct
27 Correct 702 ms 73308 KB Output is correct
28 Correct 741 ms 73388 KB Output is correct
29 Correct 638 ms 70216 KB Output is correct
30 Correct 288 ms 5752 KB Output is correct
31 Correct 659 ms 70700 KB Output is correct
32 Correct 627 ms 74360 KB Output is correct
33 Correct 234 ms 5752 KB Output is correct
34 Correct 680 ms 74940 KB Output is correct
35 Correct 436 ms 78484 KB Output is correct
36 Correct 242 ms 5816 KB Output is correct
37 Correct 240 ms 5740 KB Output is correct
38 Correct 682 ms 59268 KB Output is correct
39 Correct 242 ms 77284 KB Output is correct
40 Correct 440 ms 35860 KB Output is correct
41 Correct 872 ms 61020 KB Output is correct
42 Correct 102 ms 58852 KB Output is correct
43 Correct 214 ms 848 KB Output is correct
44 Correct 185 ms 920 KB Output is correct
45 Correct 144 ms 940 KB Output is correct
46 Correct 132 ms 960 KB Output is correct
47 Correct 144 ms 1008 KB Output is correct
48 Correct 158 ms 916 KB Output is correct
49 Correct 148 ms 1044 KB Output is correct
50 Correct 137 ms 892 KB Output is correct
51 Correct 147 ms 952 KB Output is correct
52 Correct 131 ms 884 KB Output is correct
53 Correct 152 ms 960 KB Output is correct
54 Correct 130 ms 832 KB Output is correct
55 Correct 165 ms 864 KB Output is correct
56 Correct 165 ms 972 KB Output is correct
57 Correct 197 ms 940 KB Output is correct
58 Correct 153 ms 924 KB Output is correct
59 Correct 164 ms 880 KB Output is correct
60 Correct 171 ms 968 KB Output is correct
61 Correct 169 ms 876 KB Output is correct
62 Correct 170 ms 964 KB Output is correct
63 Correct 192 ms 884 KB Output is correct
64 Correct 170 ms 876 KB Output is correct
65 Correct 169 ms 940 KB Output is correct
66 Correct 180 ms 960 KB Output is correct
67 Correct 161 ms 940 KB Output is correct
68 Correct 168 ms 964 KB Output is correct
69 Correct 969 ms 78888 KB Output is correct
70 Correct 914 ms 77612 KB Output is correct
71 Correct 251 ms 5816 KB Output is correct
72 Correct 304 ms 5796 KB Output is correct
73 Correct 262 ms 6000 KB Output is correct
74 Correct 506 ms 78756 KB Output is correct
75 Correct 244 ms 5772 KB Output is correct
76 Correct 547 ms 79260 KB Output is correct
77 Correct 526 ms 78804 KB Output is correct
78 Correct 253 ms 5764 KB Output is correct
79 Correct 284 ms 5920 KB Output is correct
80 Correct 521 ms 78712 KB Output is correct
81 Correct 327 ms 5700 KB Output is correct
82 Correct 553 ms 79200 KB Output is correct
83 Correct 591 ms 79112 KB Output is correct
84 Correct 280 ms 5816 KB Output is correct
85 Correct 275 ms 5788 KB Output is correct
86 Correct 816 ms 77924 KB Output is correct
87 Correct 859 ms 79132 KB Output is correct
88 Correct 367 ms 5932 KB Output is correct
89 Correct 713 ms 78844 KB Output is correct
90 Correct 770 ms 79252 KB Output is correct
91 Correct 349 ms 5756 KB Output is correct
92 Correct 500 ms 78556 KB Output is correct
93 Correct 301 ms 5804 KB Output is correct
94 Correct 304 ms 5704 KB Output is correct
95 Correct 288 ms 5804 KB Output is correct
96 Correct 617 ms 59148 KB Output is correct
97 Correct 266 ms 77152 KB Output is correct
98 Correct 506 ms 40548 KB Output is correct
99 Correct 932 ms 79656 KB Output is correct
100 Correct 122 ms 77284 KB Output is correct