답안 #864322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864322 2023-10-22T12:13:39 Z vjudge1 Crossing (JOI21_crossing) C++17
100 / 100
2650 ms 76636 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

int n;
string t;

struct SegmentTree {

    string s;
    vector<int> sgt, lz;
    vector<char> let, slet;

    void build(int k = 1, int l = 0, int r = n - 1) {
        if (l == r) {
            let[k] = t[l];
            if (t[l] == s[l]) sgt[k] = 1;
            else sgt[k] = 0;
            slet[k] = s[l];
            return;
        }
        int m = (l + r) / 2;
        build(k * 2, l, m);
        build(k * 2 + 1, m + 1, r);
        sgt[k] = sgt[k * 2] * sgt[k * 2 + 1];
        let[k] = 'z';
        if (let[k * 2] == let[k * 2 + 1]) let[k] = let[k * 2];
        slet[k] = 'z';
        if (slet[k * 2] == slet[k * 2 + 1]) slet[k] = slet[k * 2];
    }

    void init(string a) {
        s = a;
        sgt.resize(4 * n);
        let.resize(4 * n);
        slet.resize(4 * n);
        lz.resize(4 * n);
        build();
    }

    void push(int k, int l, int r) {
        if (l == r) return;
        if (lz[k]) {
            if (l != r) lz[k * 2] = lz[k * 2 + 1] = 1;
            let[k * 2] = let[k * 2 + 1] = let[k];
            if (slet[k * 2] == let[k * 2]) sgt[k * 2] = 1;
            else sgt[k * 2] = 0;
            if (slet[k * 2 + 1] == let[k * 2 + 1]) sgt[k * 2 + 1] = 1;
            else sgt[k * 2 + 1] = 0;
            sgt[k] = sgt[k * 2] * sgt[k * 2 + 1];
        }
        lz[k] = 0;
    }

    void update(int k, int l, int r, int i, int j, char v) {
        push(k, l, r);
        if (l > j || r < i) return;
        if (i <= l && r <= j) {
            if (slet[k] == v) sgt[k] = 1;
            else sgt[k] = 0;
            let[k] = v;
            lz[k] = 1;
            // cout << s << " " << l << " - " << r << " " << sgt[k] << " " << let[k] << endl;
            return;
        }
        int m = (l + r) / 2;
        update(k * 2, l, m, i, j, v);
        update(k * 2 + 1, m + 1, r, i, j, v);
        sgt[k] = sgt[k * 2] * sgt[k * 2 + 1];
        let[k] = 'z';
        if (let[k * 2] == let[k * 2 + 1]) let[k] = let[k * 2];
        // cout << s << " " << l << " - " << r << " " << sgt[k] << " " << let[k] << endl;
    }
};


string merge(string a, string b) {
    string c = "";
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == b[i]) c += a[i];
        else {
            set<char> f;
            f.insert(a[i]);
            f.insert(b[i]);
            if (!f.count('J')) c += "J";
            if (!f.count('O')) c += "O";
            if (!f.count('I')) c += "I";
        }
    }
    return c;
}

vector<SegmentTree> v(9);

int cnt;

bool pos() {
    int flag = 0;
    for (int i = 0; i < cnt; i++) flag = max(flag, v[i].sgt[1]);
    return flag;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    string s[3];
    for (int i = 0; i < 3; i++) cin >> s[i];
    set<string> all;
    all.insert(s[0]);
    all.insert(s[1]);
    all.insert(s[2]);
    all.insert(merge(s[0], s[1]));
    all.insert(merge(s[0], s[2]));
    all.insert(merge(s[1], s[2]));
    all.insert(merge(s[0], merge(s[1], s[2])));
    all.insert(merge(s[1], merge(s[0], s[2])));
    all.insert(merge(s[2], merge(s[0], s[1])));
    int q;
    cin >> q;
    cin >> t;
    for (auto x : all) {
        v[cnt++].init(x);
    }
    cout << (pos() ? "Yes" : "No") << endl;
    while (q--) {
        int l, r;
        char x;
        cin >> l >> r >> x;
        l--;
        r--;
        for (int i = 0; i < cnt; i++) v[i].update(1, 0, n - 1, l, r, x);
        cout << (pos() ? "Yes" : "No") << endl;
    }
}

Compilation message

Main.cpp: In function 'std::string merge(std::string, std::string)':
Main.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 844 KB Output is correct
2 Correct 68 ms 848 KB Output is correct
3 Correct 63 ms 848 KB Output is correct
4 Correct 57 ms 852 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 54 ms 960 KB Output is correct
7 Correct 53 ms 848 KB Output is correct
8 Correct 56 ms 852 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Correct 55 ms 848 KB Output is correct
11 Correct 58 ms 920 KB Output is correct
12 Correct 55 ms 820 KB Output is correct
13 Correct 60 ms 1056 KB Output is correct
14 Correct 59 ms 1004 KB Output is correct
15 Correct 56 ms 856 KB Output is correct
16 Correct 56 ms 896 KB Output is correct
17 Correct 57 ms 848 KB Output is correct
18 Correct 57 ms 916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 844 KB Output is correct
2 Correct 68 ms 848 KB Output is correct
3 Correct 63 ms 848 KB Output is correct
4 Correct 57 ms 852 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 54 ms 960 KB Output is correct
7 Correct 53 ms 848 KB Output is correct
8 Correct 56 ms 852 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Correct 55 ms 848 KB Output is correct
11 Correct 58 ms 920 KB Output is correct
12 Correct 55 ms 820 KB Output is correct
13 Correct 60 ms 1056 KB Output is correct
14 Correct 59 ms 1004 KB Output is correct
15 Correct 56 ms 856 KB Output is correct
16 Correct 56 ms 896 KB Output is correct
17 Correct 57 ms 848 KB Output is correct
18 Correct 57 ms 916 KB Output is correct
19 Correct 175 ms 10444 KB Output is correct
20 Correct 185 ms 10412 KB Output is correct
21 Correct 135 ms 9876 KB Output is correct
22 Correct 116 ms 8964 KB Output is correct
23 Correct 85 ms 1364 KB Output is correct
24 Correct 85 ms 1364 KB Output is correct
25 Correct 121 ms 10416 KB Output is correct
26 Correct 125 ms 10428 KB Output is correct
27 Correct 150 ms 10412 KB Output is correct
28 Correct 150 ms 10244 KB Output is correct
29 Correct 156 ms 10332 KB Output is correct
30 Correct 116 ms 1360 KB Output is correct
31 Correct 149 ms 10428 KB Output is correct
32 Correct 148 ms 9804 KB Output is correct
33 Correct 114 ms 1360 KB Output is correct
34 Correct 146 ms 10432 KB Output is correct
35 Correct 109 ms 8080 KB Output is correct
36 Correct 91 ms 1736 KB Output is correct
37 Correct 86 ms 1340 KB Output is correct
38 Correct 153 ms 10436 KB Output is correct
39 Correct 106 ms 10424 KB Output is correct
40 Correct 115 ms 7072 KB Output is correct
41 Correct 183 ms 10680 KB Output is correct
42 Correct 45 ms 10660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 844 KB Output is correct
2 Correct 68 ms 848 KB Output is correct
3 Correct 63 ms 848 KB Output is correct
4 Correct 57 ms 852 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 54 ms 960 KB Output is correct
7 Correct 53 ms 848 KB Output is correct
8 Correct 56 ms 852 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Correct 55 ms 848 KB Output is correct
11 Correct 58 ms 920 KB Output is correct
12 Correct 55 ms 820 KB Output is correct
13 Correct 60 ms 1056 KB Output is correct
14 Correct 59 ms 1004 KB Output is correct
15 Correct 56 ms 856 KB Output is correct
16 Correct 56 ms 896 KB Output is correct
17 Correct 57 ms 848 KB Output is correct
18 Correct 57 ms 916 KB Output is correct
19 Correct 317 ms 840 KB Output is correct
20 Correct 362 ms 852 KB Output is correct
21 Correct 112 ms 848 KB Output is correct
22 Correct 100 ms 844 KB Output is correct
23 Correct 112 ms 992 KB Output is correct
24 Correct 130 ms 872 KB Output is correct
25 Correct 119 ms 888 KB Output is correct
26 Correct 115 ms 1136 KB Output is correct
27 Correct 113 ms 1024 KB Output is correct
28 Correct 107 ms 852 KB Output is correct
29 Correct 116 ms 1040 KB Output is correct
30 Correct 105 ms 848 KB Output is correct
31 Correct 247 ms 1048 KB Output is correct
32 Correct 290 ms 1192 KB Output is correct
33 Correct 255 ms 848 KB Output is correct
34 Correct 228 ms 940 KB Output is correct
35 Correct 253 ms 1116 KB Output is correct
36 Correct 253 ms 852 KB Output is correct
37 Correct 251 ms 1120 KB Output is correct
38 Correct 254 ms 848 KB Output is correct
39 Correct 248 ms 912 KB Output is correct
40 Correct 262 ms 1080 KB Output is correct
41 Correct 246 ms 852 KB Output is correct
42 Correct 256 ms 880 KB Output is correct
43 Correct 240 ms 1060 KB Output is correct
44 Correct 255 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 844 KB Output is correct
2 Correct 68 ms 848 KB Output is correct
3 Correct 63 ms 848 KB Output is correct
4 Correct 57 ms 852 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 54 ms 960 KB Output is correct
7 Correct 53 ms 848 KB Output is correct
8 Correct 56 ms 852 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Correct 55 ms 848 KB Output is correct
11 Correct 58 ms 920 KB Output is correct
12 Correct 55 ms 820 KB Output is correct
13 Correct 60 ms 1056 KB Output is correct
14 Correct 59 ms 1004 KB Output is correct
15 Correct 56 ms 856 KB Output is correct
16 Correct 56 ms 896 KB Output is correct
17 Correct 57 ms 848 KB Output is correct
18 Correct 57 ms 916 KB Output is correct
19 Correct 175 ms 10444 KB Output is correct
20 Correct 185 ms 10412 KB Output is correct
21 Correct 135 ms 9876 KB Output is correct
22 Correct 116 ms 8964 KB Output is correct
23 Correct 85 ms 1364 KB Output is correct
24 Correct 85 ms 1364 KB Output is correct
25 Correct 121 ms 10416 KB Output is correct
26 Correct 125 ms 10428 KB Output is correct
27 Correct 150 ms 10412 KB Output is correct
28 Correct 150 ms 10244 KB Output is correct
29 Correct 156 ms 10332 KB Output is correct
30 Correct 116 ms 1360 KB Output is correct
31 Correct 149 ms 10428 KB Output is correct
32 Correct 148 ms 9804 KB Output is correct
33 Correct 114 ms 1360 KB Output is correct
34 Correct 146 ms 10432 KB Output is correct
35 Correct 109 ms 8080 KB Output is correct
36 Correct 91 ms 1736 KB Output is correct
37 Correct 86 ms 1340 KB Output is correct
38 Correct 153 ms 10436 KB Output is correct
39 Correct 106 ms 10424 KB Output is correct
40 Correct 115 ms 7072 KB Output is correct
41 Correct 183 ms 10680 KB Output is correct
42 Correct 45 ms 10660 KB Output is correct
43 Correct 317 ms 840 KB Output is correct
44 Correct 362 ms 852 KB Output is correct
45 Correct 112 ms 848 KB Output is correct
46 Correct 100 ms 844 KB Output is correct
47 Correct 112 ms 992 KB Output is correct
48 Correct 130 ms 872 KB Output is correct
49 Correct 119 ms 888 KB Output is correct
50 Correct 115 ms 1136 KB Output is correct
51 Correct 113 ms 1024 KB Output is correct
52 Correct 107 ms 852 KB Output is correct
53 Correct 116 ms 1040 KB Output is correct
54 Correct 105 ms 848 KB Output is correct
55 Correct 247 ms 1048 KB Output is correct
56 Correct 290 ms 1192 KB Output is correct
57 Correct 255 ms 848 KB Output is correct
58 Correct 228 ms 940 KB Output is correct
59 Correct 253 ms 1116 KB Output is correct
60 Correct 253 ms 852 KB Output is correct
61 Correct 251 ms 1120 KB Output is correct
62 Correct 254 ms 848 KB Output is correct
63 Correct 248 ms 912 KB Output is correct
64 Correct 262 ms 1080 KB Output is correct
65 Correct 246 ms 852 KB Output is correct
66 Correct 256 ms 880 KB Output is correct
67 Correct 240 ms 1060 KB Output is correct
68 Correct 255 ms 852 KB Output is correct
69 Correct 1870 ms 64264 KB Output is correct
70 Correct 1533 ms 76296 KB Output is correct
71 Correct 198 ms 2384 KB Output is correct
72 Correct 199 ms 2364 KB Output is correct
73 Correct 208 ms 2388 KB Output is correct
74 Correct 366 ms 22436 KB Output is correct
75 Correct 198 ms 2384 KB Output is correct
76 Correct 401 ms 27056 KB Output is correct
77 Correct 385 ms 22760 KB Output is correct
78 Correct 200 ms 2384 KB Output is correct
79 Correct 197 ms 2200 KB Output is correct
80 Correct 1125 ms 54572 KB Output is correct
81 Correct 490 ms 4864 KB Output is correct
82 Correct 1365 ms 76360 KB Output is correct
83 Correct 1398 ms 71876 KB Output is correct
84 Correct 489 ms 4944 KB Output is correct
85 Correct 499 ms 4944 KB Output is correct
86 Correct 1538 ms 58384 KB Output is correct
87 Correct 1742 ms 76292 KB Output is correct
88 Correct 591 ms 5008 KB Output is correct
89 Correct 1604 ms 67424 KB Output is correct
90 Correct 1701 ms 76636 KB Output is correct
91 Correct 633 ms 4824 KB Output is correct
92 Correct 1340 ms 57420 KB Output is correct
93 Correct 530 ms 4860 KB Output is correct
94 Correct 520 ms 4692 KB Output is correct
95 Correct 509 ms 4888 KB Output is correct
96 Correct 170 ms 10904 KB Output is correct
97 Correct 750 ms 76304 KB Output is correct
98 Correct 1275 ms 50408 KB Output is correct
99 Correct 2650 ms 76496 KB Output is correct
100 Correct 222 ms 76484 KB Output is correct