Submission #864296

# Submission time Handle Problem Language Result Execution time Memory
864296 2023-10-22T10:43:25 Z vjudge1 Crossing (JOI21_crossing) C++17
100 / 100
2402 ms 80200 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] = 'y';
        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++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 66 ms 852 KB Output is correct
3 Correct 70 ms 1204 KB Output is correct
4 Correct 52 ms 812 KB Output is correct
5 Correct 52 ms 2384 KB Output is correct
6 Correct 54 ms 2388 KB Output is correct
7 Correct 54 ms 2384 KB Output is correct
8 Correct 56 ms 2376 KB Output is correct
9 Correct 56 ms 2392 KB Output is correct
10 Correct 58 ms 2384 KB Output is correct
11 Correct 57 ms 2480 KB Output is correct
12 Correct 58 ms 2396 KB Output is correct
13 Correct 58 ms 2400 KB Output is correct
14 Correct 56 ms 2396 KB Output is correct
15 Correct 57 ms 2356 KB Output is correct
16 Correct 59 ms 2452 KB Output is correct
17 Correct 64 ms 2344 KB Output is correct
18 Correct 57 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 66 ms 852 KB Output is correct
3 Correct 70 ms 1204 KB Output is correct
4 Correct 52 ms 812 KB Output is correct
5 Correct 52 ms 2384 KB Output is correct
6 Correct 54 ms 2388 KB Output is correct
7 Correct 54 ms 2384 KB Output is correct
8 Correct 56 ms 2376 KB Output is correct
9 Correct 56 ms 2392 KB Output is correct
10 Correct 58 ms 2384 KB Output is correct
11 Correct 57 ms 2480 KB Output is correct
12 Correct 58 ms 2396 KB Output is correct
13 Correct 58 ms 2400 KB Output is correct
14 Correct 56 ms 2396 KB Output is correct
15 Correct 57 ms 2356 KB Output is correct
16 Correct 59 ms 2452 KB Output is correct
17 Correct 64 ms 2344 KB Output is correct
18 Correct 57 ms 2384 KB Output is correct
19 Correct 178 ms 14024 KB Output is correct
20 Correct 196 ms 14296 KB Output is correct
21 Correct 114 ms 13212 KB Output is correct
22 Correct 114 ms 12136 KB Output is correct
23 Correct 85 ms 3920 KB Output is correct
24 Correct 87 ms 3784 KB Output is correct
25 Correct 122 ms 13988 KB Output is correct
26 Correct 130 ms 14040 KB Output is correct
27 Correct 164 ms 14400 KB Output is correct
28 Correct 152 ms 14056 KB Output is correct
29 Correct 148 ms 13648 KB Output is correct
30 Correct 97 ms 3680 KB Output is correct
31 Correct 155 ms 13992 KB Output is correct
32 Correct 147 ms 13000 KB Output is correct
33 Correct 88 ms 3632 KB Output is correct
34 Correct 154 ms 14308 KB Output is correct
35 Correct 110 ms 11316 KB Output is correct
36 Correct 87 ms 3792 KB Output is correct
37 Correct 87 ms 3672 KB Output is correct
38 Correct 157 ms 13752 KB Output is correct
39 Correct 106 ms 14084 KB Output is correct
40 Correct 114 ms 10404 KB Output is correct
41 Correct 195 ms 14404 KB Output is correct
42 Correct 45 ms 13504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 66 ms 852 KB Output is correct
3 Correct 70 ms 1204 KB Output is correct
4 Correct 52 ms 812 KB Output is correct
5 Correct 52 ms 2384 KB Output is correct
6 Correct 54 ms 2388 KB Output is correct
7 Correct 54 ms 2384 KB Output is correct
8 Correct 56 ms 2376 KB Output is correct
9 Correct 56 ms 2392 KB Output is correct
10 Correct 58 ms 2384 KB Output is correct
11 Correct 57 ms 2480 KB Output is correct
12 Correct 58 ms 2396 KB Output is correct
13 Correct 58 ms 2400 KB Output is correct
14 Correct 56 ms 2396 KB Output is correct
15 Correct 57 ms 2356 KB Output is correct
16 Correct 59 ms 2452 KB Output is correct
17 Correct 64 ms 2344 KB Output is correct
18 Correct 57 ms 2384 KB Output is correct
19 Correct 318 ms 2452 KB Output is correct
20 Correct 368 ms 2464 KB Output is correct
21 Correct 116 ms 2536 KB Output is correct
22 Correct 101 ms 2132 KB Output is correct
23 Correct 117 ms 2644 KB Output is correct
24 Correct 111 ms 2388 KB Output is correct
25 Correct 116 ms 2376 KB Output is correct
26 Correct 108 ms 2260 KB Output is correct
27 Correct 116 ms 2472 KB Output is correct
28 Correct 101 ms 2384 KB Output is correct
29 Correct 116 ms 2388 KB Output is correct
30 Correct 105 ms 2180 KB Output is correct
31 Correct 248 ms 2388 KB Output is correct
32 Correct 244 ms 2384 KB Output is correct
33 Correct 261 ms 2576 KB Output is correct
34 Correct 227 ms 2388 KB Output is correct
35 Correct 246 ms 2560 KB Output is correct
36 Correct 255 ms 2384 KB Output is correct
37 Correct 246 ms 2480 KB Output is correct
38 Correct 261 ms 2656 KB Output is correct
39 Correct 247 ms 2388 KB Output is correct
40 Correct 253 ms 2388 KB Output is correct
41 Correct 246 ms 2388 KB Output is correct
42 Correct 260 ms 2388 KB Output is correct
43 Correct 246 ms 2640 KB Output is correct
44 Correct 255 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 852 KB Output is correct
2 Correct 66 ms 852 KB Output is correct
3 Correct 70 ms 1204 KB Output is correct
4 Correct 52 ms 812 KB Output is correct
5 Correct 52 ms 2384 KB Output is correct
6 Correct 54 ms 2388 KB Output is correct
7 Correct 54 ms 2384 KB Output is correct
8 Correct 56 ms 2376 KB Output is correct
9 Correct 56 ms 2392 KB Output is correct
10 Correct 58 ms 2384 KB Output is correct
11 Correct 57 ms 2480 KB Output is correct
12 Correct 58 ms 2396 KB Output is correct
13 Correct 58 ms 2400 KB Output is correct
14 Correct 56 ms 2396 KB Output is correct
15 Correct 57 ms 2356 KB Output is correct
16 Correct 59 ms 2452 KB Output is correct
17 Correct 64 ms 2344 KB Output is correct
18 Correct 57 ms 2384 KB Output is correct
19 Correct 178 ms 14024 KB Output is correct
20 Correct 196 ms 14296 KB Output is correct
21 Correct 114 ms 13212 KB Output is correct
22 Correct 114 ms 12136 KB Output is correct
23 Correct 85 ms 3920 KB Output is correct
24 Correct 87 ms 3784 KB Output is correct
25 Correct 122 ms 13988 KB Output is correct
26 Correct 130 ms 14040 KB Output is correct
27 Correct 164 ms 14400 KB Output is correct
28 Correct 152 ms 14056 KB Output is correct
29 Correct 148 ms 13648 KB Output is correct
30 Correct 97 ms 3680 KB Output is correct
31 Correct 155 ms 13992 KB Output is correct
32 Correct 147 ms 13000 KB Output is correct
33 Correct 88 ms 3632 KB Output is correct
34 Correct 154 ms 14308 KB Output is correct
35 Correct 110 ms 11316 KB Output is correct
36 Correct 87 ms 3792 KB Output is correct
37 Correct 87 ms 3672 KB Output is correct
38 Correct 157 ms 13752 KB Output is correct
39 Correct 106 ms 14084 KB Output is correct
40 Correct 114 ms 10404 KB Output is correct
41 Correct 195 ms 14404 KB Output is correct
42 Correct 45 ms 13504 KB Output is correct
43 Correct 318 ms 2452 KB Output is correct
44 Correct 368 ms 2464 KB Output is correct
45 Correct 116 ms 2536 KB Output is correct
46 Correct 101 ms 2132 KB Output is correct
47 Correct 117 ms 2644 KB Output is correct
48 Correct 111 ms 2388 KB Output is correct
49 Correct 116 ms 2376 KB Output is correct
50 Correct 108 ms 2260 KB Output is correct
51 Correct 116 ms 2472 KB Output is correct
52 Correct 101 ms 2384 KB Output is correct
53 Correct 116 ms 2388 KB Output is correct
54 Correct 105 ms 2180 KB Output is correct
55 Correct 248 ms 2388 KB Output is correct
56 Correct 244 ms 2384 KB Output is correct
57 Correct 261 ms 2576 KB Output is correct
58 Correct 227 ms 2388 KB Output is correct
59 Correct 246 ms 2560 KB Output is correct
60 Correct 255 ms 2384 KB Output is correct
61 Correct 246 ms 2480 KB Output is correct
62 Correct 261 ms 2656 KB Output is correct
63 Correct 247 ms 2388 KB Output is correct
64 Correct 253 ms 2388 KB Output is correct
65 Correct 246 ms 2388 KB Output is correct
66 Correct 260 ms 2388 KB Output is correct
67 Correct 246 ms 2640 KB Output is correct
68 Correct 255 ms 2384 KB Output is correct
69 Correct 1788 ms 67408 KB Output is correct
70 Correct 1516 ms 80024 KB Output is correct
71 Correct 202 ms 4692 KB Output is correct
72 Correct 199 ms 4696 KB Output is correct
73 Correct 198 ms 4692 KB Output is correct
74 Correct 347 ms 25728 KB Output is correct
75 Correct 203 ms 4788 KB Output is correct
76 Correct 387 ms 30388 KB Output is correct
77 Correct 385 ms 26400 KB Output is correct
78 Correct 200 ms 4712 KB Output is correct
79 Correct 204 ms 4944 KB Output is correct
80 Correct 1101 ms 57744 KB Output is correct
81 Correct 489 ms 7152 KB Output is correct
82 Correct 1300 ms 80112 KB Output is correct
83 Correct 1324 ms 75632 KB Output is correct
84 Correct 484 ms 7252 KB Output is correct
85 Correct 504 ms 7440 KB Output is correct
86 Correct 1517 ms 61516 KB Output is correct
87 Correct 1632 ms 80088 KB Output is correct
88 Correct 577 ms 7576 KB Output is correct
89 Correct 1404 ms 70764 KB Output is correct
90 Correct 1523 ms 80112 KB Output is correct
91 Correct 571 ms 7192 KB Output is correct
92 Correct 1143 ms 60544 KB Output is correct
93 Correct 488 ms 7388 KB Output is correct
94 Correct 499 ms 7208 KB Output is correct
95 Correct 486 ms 7256 KB Output is correct
96 Correct 164 ms 13852 KB Output is correct
97 Correct 779 ms 80008 KB Output is correct
98 Correct 1202 ms 54096 KB Output is correct
99 Correct 2402 ms 80200 KB Output is correct
100 Correct 195 ms 79456 KB Output is correct