답안 #580462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580462 2022-06-21T09:32:46 Z colossal_pepe Crossing (JOI21_crossing) C++17
100 / 100
570 ms 117140 KB
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
using namespace std;

struct Node {
    int cnt_s[9][3], cnt_t[3];
    bool match[9];
    int lazy;
    Node() {
        memset(cnt_s, 0, sizeof(cnt_s));
        memset(cnt_t, 0, sizeof(cnt_t));
        lazy = -1;
    }
};

int n, q;
set<string> dict;
vector<string> all, now(3);
string t;
vector<Node> sgt;

int id(char c) {
    if (c == 'J') return 0;
    else if (c == 'O') return 1;
    else return 2;
}

void init(int u, int l, int r) {
    if (l == r) {
        sgt[u].cnt_t[id(t[l])]++;
        for (int i = 0; i < 9; i++) {
            sgt[u].cnt_s[i][id(all[i][l])]++;
            sgt[u].match[i] = (all[i][l] == t[l]);
        }
    } else {
        int mid = (l + r) / 2;
        init(2 * u, l, mid);
        init(2 * u + 1, mid + 1, r);
        for (int i = 0; i < 3; i++) {
            sgt[u].cnt_t[i] = sgt[2 * u].cnt_t[i] + sgt[2 * u + 1].cnt_t[i];
        }
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 3; j++) {
                sgt[u].cnt_s[i][j] = sgt[2 * u].cnt_s[i][j] + sgt[2 * u + 1].cnt_s[i][j];
            }
            sgt[u].match[i] = (sgt[2 * u].match[i] & sgt[2 * u + 1].match[i]);
        }
    }
}

void update(int u, int l, int r, int L, int R, int x) {
    if (r < L or R < l) return;
    else if (L <= l and r <= R) {
        memset(sgt[u].cnt_t, 0, sizeof(sgt[u].cnt_t));
        sgt[u].cnt_t[x] = r - l + 1;
        sgt[u].lazy = x;
        for (int i = 0; i < 9; i++) {
            sgt[u].match[i] = (sgt[u].cnt_s[i][x] == sgt[u].cnt_t[x]);
        }
    } else {
        int mid = (l + r) / 2;
        if (sgt[u].lazy != -1) {
            memset(sgt[2 * u].cnt_t, 0, sizeof(sgt[2 * u].cnt_t));
            memset(sgt[2 * u + 1].cnt_t, 0, sizeof(sgt[2 * u + 1].cnt_t));
            sgt[2 * u].cnt_t[sgt[u].lazy] = mid - l + 1;
            sgt[2 * u + 1].cnt_t[sgt[u].lazy] = r - mid;
            for (int i = 0; i < 9; i++) {
                sgt[2 * u].match[i] = (sgt[2 * u].cnt_s[i][sgt[u].lazy] == sgt[2 * u].cnt_t[sgt[u].lazy]);
                sgt[2 * u + 1].match[i] = (sgt[2 * u + 1].cnt_s[i][sgt[u].lazy] == sgt[2 * u + 1].cnt_t[sgt[u].lazy]);
            }
            sgt[2 * u].lazy = sgt[2 * u + 1].lazy = sgt[u].lazy;
            sgt[u].lazy = -1;
        }
        update(2 * u, l, mid, L, R, x);
        update(2 * u + 1, mid + 1, r, L, R, x);
        for (int i = 0; i < 3; i++) {
            sgt[u].cnt_t[i] = sgt[2 * u].cnt_t[i] + sgt[2 * u + 1].cnt_t[i];
        }
        for (int i = 0; i < 9; i++) {
            sgt[u].match[i] = (sgt[2 * u].match[i] & sgt[2 * u + 1].match[i]);
        }
    }
}

char crossChar(char c1, char c2) {
    if (c1 == c2) return c1;
    if (c1 != 'J' and c2 != 'J') return 'J';
    else if (c1 != 'O' and c2 != 'O') return 'O';
    else return 'I';
}
 
string crossStr(string s1, string s2) {
    string ret;
    for (int i = 0; i < s1.size(); i++) {
        ret += crossChar(s1[i], s2[i]);
    }
    return ret;
}

void generate() {
    while (not now.empty()) {
        string s = now.back();
        now.pop_back();
        if (dict.find(s) != dict.end()) continue;
        dict.insert(s);
        all.push_back(s);
        for (string t : all) {
            now.push_back(crossStr(s, t));
        }
    }
    while (all.size() < 9) {
        all.push_back(all.back());
    }
}

bool check() {
    for (int i = 0; i < 9; i++) {
        if (sgt[1].match[i]) return 1;
    }
    return 0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> now[0] >> now[1] >> now[2];
    generate();
    cin >> q >> t;
    sgt.resize(4 * n, Node());
    init(1, 0, n - 1);
    cout << (check() ? "Yes" : "No") << '\n';
    while (q--) {
        int l, r;
        char c;
        cin >> l >> r >> c;
        update(1, 0, n - 1, l - 1, r - 1, id(c));
        cout << (check() ? "Yes" : "No") << '\n';
    }
    return 0;
}

Compilation message

Main.cpp: In function 'std::string crossStr(std::string, std::string)':
Main.cpp:96:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for (int i = 0; i < s1.size(); i++) {
      |                     ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 872 KB Output is correct
2 Correct 92 ms 948 KB Output is correct
3 Correct 92 ms 1048 KB Output is correct
4 Correct 71 ms 836 KB Output is correct
5 Correct 73 ms 852 KB Output is correct
6 Correct 75 ms 816 KB Output is correct
7 Correct 90 ms 860 KB Output is correct
8 Correct 79 ms 960 KB Output is correct
9 Correct 77 ms 920 KB Output is correct
10 Correct 79 ms 880 KB Output is correct
11 Correct 85 ms 848 KB Output is correct
12 Correct 76 ms 860 KB Output is correct
13 Correct 85 ms 856 KB Output is correct
14 Correct 79 ms 876 KB Output is correct
15 Correct 80 ms 916 KB Output is correct
16 Correct 77 ms 908 KB Output is correct
17 Correct 75 ms 892 KB Output is correct
18 Correct 85 ms 936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 872 KB Output is correct
2 Correct 92 ms 948 KB Output is correct
3 Correct 92 ms 1048 KB Output is correct
4 Correct 71 ms 836 KB Output is correct
5 Correct 73 ms 852 KB Output is correct
6 Correct 75 ms 816 KB Output is correct
7 Correct 90 ms 860 KB Output is correct
8 Correct 79 ms 960 KB Output is correct
9 Correct 77 ms 920 KB Output is correct
10 Correct 79 ms 880 KB Output is correct
11 Correct 85 ms 848 KB Output is correct
12 Correct 76 ms 860 KB Output is correct
13 Correct 85 ms 856 KB Output is correct
14 Correct 79 ms 876 KB Output is correct
15 Correct 80 ms 916 KB Output is correct
16 Correct 77 ms 908 KB Output is correct
17 Correct 75 ms 892 KB Output is correct
18 Correct 85 ms 936 KB Output is correct
19 Correct 446 ms 109660 KB Output is correct
20 Correct 391 ms 109744 KB Output is correct
21 Correct 279 ms 103348 KB Output is correct
22 Correct 274 ms 92848 KB Output is correct
23 Correct 143 ms 6476 KB Output is correct
24 Correct 131 ms 6384 KB Output is correct
25 Correct 290 ms 109688 KB Output is correct
26 Correct 365 ms 109676 KB Output is correct
27 Correct 353 ms 109656 KB Output is correct
28 Correct 363 ms 109744 KB Output is correct
29 Correct 333 ms 106800 KB Output is correct
30 Correct 145 ms 6484 KB Output is correct
31 Correct 326 ms 109732 KB Output is correct
32 Correct 318 ms 100308 KB Output is correct
33 Correct 122 ms 6348 KB Output is correct
34 Correct 335 ms 109724 KB Output is correct
35 Correct 250 ms 81904 KB Output is correct
36 Correct 130 ms 6384 KB Output is correct
37 Correct 130 ms 6392 KB Output is correct
38 Correct 326 ms 109672 KB Output is correct
39 Correct 185 ms 109664 KB Output is correct
40 Correct 278 ms 72324 KB Output is correct
41 Correct 554 ms 109860 KB Output is correct
42 Correct 100 ms 109952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 872 KB Output is correct
2 Correct 92 ms 948 KB Output is correct
3 Correct 92 ms 1048 KB Output is correct
4 Correct 71 ms 836 KB Output is correct
5 Correct 73 ms 852 KB Output is correct
6 Correct 75 ms 816 KB Output is correct
7 Correct 90 ms 860 KB Output is correct
8 Correct 79 ms 960 KB Output is correct
9 Correct 77 ms 920 KB Output is correct
10 Correct 79 ms 880 KB Output is correct
11 Correct 85 ms 848 KB Output is correct
12 Correct 76 ms 860 KB Output is correct
13 Correct 85 ms 856 KB Output is correct
14 Correct 79 ms 876 KB Output is correct
15 Correct 80 ms 916 KB Output is correct
16 Correct 77 ms 908 KB Output is correct
17 Correct 75 ms 892 KB Output is correct
18 Correct 85 ms 936 KB Output is correct
19 Correct 88 ms 924 KB Output is correct
20 Correct 93 ms 992 KB Output is correct
21 Correct 77 ms 932 KB Output is correct
22 Correct 69 ms 2212 KB Output is correct
23 Correct 77 ms 2484 KB Output is correct
24 Correct 74 ms 2376 KB Output is correct
25 Correct 76 ms 2412 KB Output is correct
26 Correct 71 ms 2356 KB Output is correct
27 Correct 78 ms 2428 KB Output is correct
28 Correct 66 ms 2208 KB Output is correct
29 Correct 76 ms 2404 KB Output is correct
30 Correct 70 ms 2252 KB Output is correct
31 Correct 76 ms 2448 KB Output is correct
32 Correct 78 ms 2424 KB Output is correct
33 Correct 79 ms 2488 KB Output is correct
34 Correct 70 ms 2288 KB Output is correct
35 Correct 75 ms 2424 KB Output is correct
36 Correct 77 ms 2508 KB Output is correct
37 Correct 76 ms 2448 KB Output is correct
38 Correct 76 ms 2404 KB Output is correct
39 Correct 76 ms 2380 KB Output is correct
40 Correct 76 ms 2504 KB Output is correct
41 Correct 81 ms 2396 KB Output is correct
42 Correct 83 ms 2380 KB Output is correct
43 Correct 75 ms 2384 KB Output is correct
44 Correct 75 ms 2500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 872 KB Output is correct
2 Correct 92 ms 948 KB Output is correct
3 Correct 92 ms 1048 KB Output is correct
4 Correct 71 ms 836 KB Output is correct
5 Correct 73 ms 852 KB Output is correct
6 Correct 75 ms 816 KB Output is correct
7 Correct 90 ms 860 KB Output is correct
8 Correct 79 ms 960 KB Output is correct
9 Correct 77 ms 920 KB Output is correct
10 Correct 79 ms 880 KB Output is correct
11 Correct 85 ms 848 KB Output is correct
12 Correct 76 ms 860 KB Output is correct
13 Correct 85 ms 856 KB Output is correct
14 Correct 79 ms 876 KB Output is correct
15 Correct 80 ms 916 KB Output is correct
16 Correct 77 ms 908 KB Output is correct
17 Correct 75 ms 892 KB Output is correct
18 Correct 85 ms 936 KB Output is correct
19 Correct 446 ms 109660 KB Output is correct
20 Correct 391 ms 109744 KB Output is correct
21 Correct 279 ms 103348 KB Output is correct
22 Correct 274 ms 92848 KB Output is correct
23 Correct 143 ms 6476 KB Output is correct
24 Correct 131 ms 6384 KB Output is correct
25 Correct 290 ms 109688 KB Output is correct
26 Correct 365 ms 109676 KB Output is correct
27 Correct 353 ms 109656 KB Output is correct
28 Correct 363 ms 109744 KB Output is correct
29 Correct 333 ms 106800 KB Output is correct
30 Correct 145 ms 6484 KB Output is correct
31 Correct 326 ms 109732 KB Output is correct
32 Correct 318 ms 100308 KB Output is correct
33 Correct 122 ms 6348 KB Output is correct
34 Correct 335 ms 109724 KB Output is correct
35 Correct 250 ms 81904 KB Output is correct
36 Correct 130 ms 6384 KB Output is correct
37 Correct 130 ms 6392 KB Output is correct
38 Correct 326 ms 109672 KB Output is correct
39 Correct 185 ms 109664 KB Output is correct
40 Correct 278 ms 72324 KB Output is correct
41 Correct 554 ms 109860 KB Output is correct
42 Correct 100 ms 109952 KB Output is correct
43 Correct 88 ms 924 KB Output is correct
44 Correct 93 ms 992 KB Output is correct
45 Correct 77 ms 932 KB Output is correct
46 Correct 69 ms 2212 KB Output is correct
47 Correct 77 ms 2484 KB Output is correct
48 Correct 74 ms 2376 KB Output is correct
49 Correct 76 ms 2412 KB Output is correct
50 Correct 71 ms 2356 KB Output is correct
51 Correct 78 ms 2428 KB Output is correct
52 Correct 66 ms 2208 KB Output is correct
53 Correct 76 ms 2404 KB Output is correct
54 Correct 70 ms 2252 KB Output is correct
55 Correct 76 ms 2448 KB Output is correct
56 Correct 78 ms 2424 KB Output is correct
57 Correct 79 ms 2488 KB Output is correct
58 Correct 70 ms 2288 KB Output is correct
59 Correct 75 ms 2424 KB Output is correct
60 Correct 77 ms 2508 KB Output is correct
61 Correct 76 ms 2448 KB Output is correct
62 Correct 76 ms 2404 KB Output is correct
63 Correct 76 ms 2380 KB Output is correct
64 Correct 76 ms 2504 KB Output is correct
65 Correct 81 ms 2396 KB Output is correct
66 Correct 83 ms 2380 KB Output is correct
67 Correct 75 ms 2384 KB Output is correct
68 Correct 75 ms 2500 KB Output is correct
69 Correct 484 ms 98180 KB Output is correct
70 Correct 494 ms 116908 KB Output is correct
71 Correct 133 ms 8784 KB Output is correct
72 Correct 127 ms 8940 KB Output is correct
73 Correct 142 ms 9044 KB Output is correct
74 Correct 255 ms 95344 KB Output is correct
75 Correct 124 ms 8672 KB Output is correct
76 Correct 291 ms 113840 KB Output is correct
77 Correct 288 ms 95700 KB Output is correct
78 Correct 126 ms 8764 KB Output is correct
79 Correct 125 ms 8812 KB Output is correct
80 Correct 328 ms 84016 KB Output is correct
81 Correct 140 ms 9036 KB Output is correct
82 Correct 393 ms 116936 KB Output is correct
83 Correct 390 ms 110008 KB Output is correct
84 Correct 129 ms 9004 KB Output is correct
85 Correct 133 ms 8932 KB Output is correct
86 Correct 366 ms 89564 KB Output is correct
87 Correct 422 ms 116972 KB Output is correct
88 Correct 139 ms 9208 KB Output is correct
89 Correct 354 ms 103312 KB Output is correct
90 Correct 367 ms 116928 KB Output is correct
91 Correct 150 ms 9040 KB Output is correct
92 Correct 322 ms 88220 KB Output is correct
93 Correct 165 ms 9052 KB Output is correct
94 Correct 130 ms 8964 KB Output is correct
95 Correct 130 ms 9028 KB Output is correct
96 Correct 335 ms 113240 KB Output is correct
97 Correct 227 ms 117032 KB Output is correct
98 Correct 386 ms 77972 KB Output is correct
99 Correct 570 ms 117140 KB Output is correct
100 Correct 206 ms 116376 KB Output is correct