답안 #501673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501673 2022-01-04T09:52:31 Z tengiz05 Crossing (JOI21_crossing) C++17
100 / 100
529 ms 41964 KB
#include <bits/stdc++.h>

using i64 = long long;

int pre[9][3][200005];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    auto in = [&]() {
        std::string a;
        std::cin >> a;
        std::vector<int> b(n);
        for (int i = 0; i < n; i++) {
            b[i] = std::string("JOI").find(a[i]);
        }
        return b;
    };
    
    std::vector<int> a = in(), b = in(), c = in();
    
    auto merge = [&](std::vector<int> a, std::vector<int> b) {
        auto c = a;
        for (int i = 0; i < n; i++) {
            if (a[i] != b[i]) {
                c[i] = 0 ^ 1 ^ 2 ^ a[i] ^ b[i];
            }
        }
        return c;
    };
    
    std::vector<std::vector<int>> s{a, b, c, merge(a, b), merge(a, c), merge(b, c), merge(merge(a, c), b), merge(merge(a, b), c), merge(merge(b, c), a)};
    
    int q;
    std::cin >> q;
    std::vector<int> t = in();
    
    for (int k = 0; k < 9; k++) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < n; j++) {
                pre[k][i][j + 1] = pre[k][i][j] + (s[k][j] == i);
            }
        }
    }
    
    int bad[9] {};
    for (int k = 0; k < 9; k++)
        for (int i = 0; i < n; i++)
            bad[k] += t[i] != s[k][i];
    
    std::set<std::pair<int, int>> p{{-1, -1}, {n, -1}};
    for (int i = 0; i < n; i++)
        p.emplace(i, t[i]);
    
    int ok = 0;
    for (int k = 0; k < 9; k++) {
        ok += bad[k] == 0;
    }
    if (ok) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
    
    auto rem = [&](int l, int r, int c) {
        for (int k = 0; k < 9; k++) {
            bad[k] -= (pre[k][c][r] - pre[k][c][l] != r - l);
        }
    };
    auto add = [&](int l, int r, int c) {
        for (int k = 0; k < 9; k++) {
            bad[k] += (pre[k][c][r] - pre[k][c][l] != r - l);
        }
    };
    
    while (q--) {
        int l, r;
        char ch;
        std::cin >> l >> r >> ch;
        l--;
        
        int x = std::string("JOI").find(ch);
        
        auto it = p.lower_bound({l, -1});
        if (it->first > l) {
            int L = std::prev(it)->first;
            int R = it->first;
            int c = std::prev(it)->second;
            rem(L, R, c);
            add(L, l, c);
            add(l, R, c);
            p.emplace(l, c);
        }
        
        it = p.lower_bound({r, -1});
        if (it->first > r) {
            int L = std::prev(it)->first;
            int R = it->first;
            int c = std::prev(it)->second;
            rem(L, R, c);
            add(L, r, c);
            add(r, R, c);
            p.emplace(r, c);
        }
        
        while (true) {
            it = p.lower_bound({l, -1});
            if (it->first < r) {
                rem(it->first, std::next(it)->first, it->second);
                p.erase(it);
            } else {
                break;
            }
        }
        
        add(l, r, x);
        p.emplace(l, x);
        
        int ok = 0;
        for (int k = 0; k < 9; k++) {
            ok += bad[k] == 0;
        }
        if (ok) {
            std::cout << "Yes\n";
        } else {
            std::cout << "No\n";
        }
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 1216 KB Output is correct
2 Correct 153 ms 1168 KB Output is correct
3 Correct 133 ms 1260 KB Output is correct
4 Correct 124 ms 1148 KB Output is correct
5 Correct 122 ms 1096 KB Output is correct
6 Correct 132 ms 1044 KB Output is correct
7 Correct 135 ms 1088 KB Output is correct
8 Correct 165 ms 1140 KB Output is correct
9 Correct 131 ms 1188 KB Output is correct
10 Correct 132 ms 1080 KB Output is correct
11 Correct 142 ms 1096 KB Output is correct
12 Correct 137 ms 1212 KB Output is correct
13 Correct 138 ms 1344 KB Output is correct
14 Correct 125 ms 1080 KB Output is correct
15 Correct 132 ms 1184 KB Output is correct
16 Correct 138 ms 1120 KB Output is correct
17 Correct 137 ms 1092 KB Output is correct
18 Correct 92 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 1216 KB Output is correct
2 Correct 153 ms 1168 KB Output is correct
3 Correct 133 ms 1260 KB Output is correct
4 Correct 124 ms 1148 KB Output is correct
5 Correct 122 ms 1096 KB Output is correct
6 Correct 132 ms 1044 KB Output is correct
7 Correct 135 ms 1088 KB Output is correct
8 Correct 165 ms 1140 KB Output is correct
9 Correct 131 ms 1188 KB Output is correct
10 Correct 132 ms 1080 KB Output is correct
11 Correct 142 ms 1096 KB Output is correct
12 Correct 137 ms 1212 KB Output is correct
13 Correct 138 ms 1344 KB Output is correct
14 Correct 125 ms 1080 KB Output is correct
15 Correct 132 ms 1184 KB Output is correct
16 Correct 138 ms 1120 KB Output is correct
17 Correct 137 ms 1092 KB Output is correct
18 Correct 92 ms 1116 KB Output is correct
19 Correct 368 ms 41856 KB Output is correct
20 Correct 265 ms 41888 KB Output is correct
21 Correct 490 ms 39620 KB Output is correct
22 Correct 446 ms 35464 KB Output is correct
23 Correct 232 ms 3796 KB Output is correct
24 Correct 215 ms 3784 KB Output is correct
25 Correct 529 ms 41816 KB Output is correct
26 Correct 487 ms 41860 KB Output is correct
27 Correct 411 ms 41708 KB Output is correct
28 Correct 426 ms 41704 KB Output is correct
29 Correct 387 ms 40672 KB Output is correct
30 Correct 196 ms 3852 KB Output is correct
31 Correct 381 ms 41776 KB Output is correct
32 Correct 438 ms 38252 KB Output is correct
33 Correct 212 ms 3764 KB Output is correct
34 Correct 444 ms 41780 KB Output is correct
35 Correct 438 ms 31804 KB Output is correct
36 Correct 225 ms 3712 KB Output is correct
37 Correct 213 ms 3776 KB Output is correct
38 Correct 285 ms 41888 KB Output is correct
39 Correct 281 ms 41844 KB Output is correct
40 Correct 447 ms 28104 KB Output is correct
41 Correct 285 ms 41936 KB Output is correct
42 Correct 154 ms 41932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 1216 KB Output is correct
2 Correct 153 ms 1168 KB Output is correct
3 Correct 133 ms 1260 KB Output is correct
4 Correct 124 ms 1148 KB Output is correct
5 Correct 122 ms 1096 KB Output is correct
6 Correct 132 ms 1044 KB Output is correct
7 Correct 135 ms 1088 KB Output is correct
8 Correct 165 ms 1140 KB Output is correct
9 Correct 131 ms 1188 KB Output is correct
10 Correct 132 ms 1080 KB Output is correct
11 Correct 142 ms 1096 KB Output is correct
12 Correct 137 ms 1212 KB Output is correct
13 Correct 138 ms 1344 KB Output is correct
14 Correct 125 ms 1080 KB Output is correct
15 Correct 132 ms 1184 KB Output is correct
16 Correct 138 ms 1120 KB Output is correct
17 Correct 137 ms 1092 KB Output is correct
18 Correct 92 ms 1116 KB Output is correct
19 Correct 128 ms 1164 KB Output is correct
20 Correct 110 ms 1188 KB Output is correct
21 Correct 137 ms 1188 KB Output is correct
22 Correct 113 ms 1028 KB Output is correct
23 Correct 130 ms 1140 KB Output is correct
24 Correct 131 ms 1256 KB Output is correct
25 Correct 128 ms 1092 KB Output is correct
26 Correct 128 ms 1040 KB Output is correct
27 Correct 130 ms 1076 KB Output is correct
28 Correct 119 ms 1024 KB Output is correct
29 Correct 133 ms 1068 KB Output is correct
30 Correct 116 ms 1080 KB Output is correct
31 Correct 134 ms 1220 KB Output is correct
32 Correct 134 ms 1060 KB Output is correct
33 Correct 137 ms 1140 KB Output is correct
34 Correct 118 ms 1100 KB Output is correct
35 Correct 142 ms 1152 KB Output is correct
36 Correct 138 ms 1104 KB Output is correct
37 Correct 126 ms 1116 KB Output is correct
38 Correct 130 ms 1212 KB Output is correct
39 Correct 127 ms 1228 KB Output is correct
40 Correct 131 ms 1144 KB Output is correct
41 Correct 128 ms 1160 KB Output is correct
42 Correct 131 ms 1148 KB Output is correct
43 Correct 128 ms 1084 KB Output is correct
44 Correct 132 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 1216 KB Output is correct
2 Correct 153 ms 1168 KB Output is correct
3 Correct 133 ms 1260 KB Output is correct
4 Correct 124 ms 1148 KB Output is correct
5 Correct 122 ms 1096 KB Output is correct
6 Correct 132 ms 1044 KB Output is correct
7 Correct 135 ms 1088 KB Output is correct
8 Correct 165 ms 1140 KB Output is correct
9 Correct 131 ms 1188 KB Output is correct
10 Correct 132 ms 1080 KB Output is correct
11 Correct 142 ms 1096 KB Output is correct
12 Correct 137 ms 1212 KB Output is correct
13 Correct 138 ms 1344 KB Output is correct
14 Correct 125 ms 1080 KB Output is correct
15 Correct 132 ms 1184 KB Output is correct
16 Correct 138 ms 1120 KB Output is correct
17 Correct 137 ms 1092 KB Output is correct
18 Correct 92 ms 1116 KB Output is correct
19 Correct 368 ms 41856 KB Output is correct
20 Correct 265 ms 41888 KB Output is correct
21 Correct 490 ms 39620 KB Output is correct
22 Correct 446 ms 35464 KB Output is correct
23 Correct 232 ms 3796 KB Output is correct
24 Correct 215 ms 3784 KB Output is correct
25 Correct 529 ms 41816 KB Output is correct
26 Correct 487 ms 41860 KB Output is correct
27 Correct 411 ms 41708 KB Output is correct
28 Correct 426 ms 41704 KB Output is correct
29 Correct 387 ms 40672 KB Output is correct
30 Correct 196 ms 3852 KB Output is correct
31 Correct 381 ms 41776 KB Output is correct
32 Correct 438 ms 38252 KB Output is correct
33 Correct 212 ms 3764 KB Output is correct
34 Correct 444 ms 41780 KB Output is correct
35 Correct 438 ms 31804 KB Output is correct
36 Correct 225 ms 3712 KB Output is correct
37 Correct 213 ms 3776 KB Output is correct
38 Correct 285 ms 41888 KB Output is correct
39 Correct 281 ms 41844 KB Output is correct
40 Correct 447 ms 28104 KB Output is correct
41 Correct 285 ms 41936 KB Output is correct
42 Correct 154 ms 41932 KB Output is correct
43 Correct 128 ms 1164 KB Output is correct
44 Correct 110 ms 1188 KB Output is correct
45 Correct 137 ms 1188 KB Output is correct
46 Correct 113 ms 1028 KB Output is correct
47 Correct 130 ms 1140 KB Output is correct
48 Correct 131 ms 1256 KB Output is correct
49 Correct 128 ms 1092 KB Output is correct
50 Correct 128 ms 1040 KB Output is correct
51 Correct 130 ms 1076 KB Output is correct
52 Correct 119 ms 1024 KB Output is correct
53 Correct 133 ms 1068 KB Output is correct
54 Correct 116 ms 1080 KB Output is correct
55 Correct 134 ms 1220 KB Output is correct
56 Correct 134 ms 1060 KB Output is correct
57 Correct 137 ms 1140 KB Output is correct
58 Correct 118 ms 1100 KB Output is correct
59 Correct 142 ms 1152 KB Output is correct
60 Correct 138 ms 1104 KB Output is correct
61 Correct 126 ms 1116 KB Output is correct
62 Correct 130 ms 1212 KB Output is correct
63 Correct 127 ms 1228 KB Output is correct
64 Correct 131 ms 1144 KB Output is correct
65 Correct 128 ms 1160 KB Output is correct
66 Correct 131 ms 1148 KB Output is correct
67 Correct 128 ms 1084 KB Output is correct
68 Correct 132 ms 1104 KB Output is correct
69 Correct 328 ms 35104 KB Output is correct
70 Correct 260 ms 41684 KB Output is correct
71 Correct 231 ms 4000 KB Output is correct
72 Correct 222 ms 3888 KB Output is correct
73 Correct 214 ms 3896 KB Output is correct
74 Correct 436 ms 35076 KB Output is correct
75 Correct 212 ms 3756 KB Output is correct
76 Correct 510 ms 41872 KB Output is correct
77 Correct 434 ms 35152 KB Output is correct
78 Correct 243 ms 3740 KB Output is correct
79 Correct 238 ms 3780 KB Output is correct
80 Correct 411 ms 30120 KB Output is correct
81 Correct 218 ms 3712 KB Output is correct
82 Correct 502 ms 41696 KB Output is correct
83 Correct 449 ms 39452 KB Output is correct
84 Correct 216 ms 3832 KB Output is correct
85 Correct 215 ms 3744 KB Output is correct
86 Correct 361 ms 31984 KB Output is correct
87 Correct 416 ms 41780 KB Output is correct
88 Correct 196 ms 3780 KB Output is correct
89 Correct 394 ms 37228 KB Output is correct
90 Correct 492 ms 41772 KB Output is correct
91 Correct 201 ms 3820 KB Output is correct
92 Correct 465 ms 31620 KB Output is correct
93 Correct 213 ms 3808 KB Output is correct
94 Correct 217 ms 3736 KB Output is correct
95 Correct 242 ms 3800 KB Output is correct
96 Correct 212 ms 41704 KB Output is correct
97 Correct 291 ms 41804 KB Output is correct
98 Correct 444 ms 27904 KB Output is correct
99 Correct 338 ms 41904 KB Output is correct
100 Correct 158 ms 41964 KB Output is correct