Submission #864323

# Submission time Handle Problem Language Result Execution time Memory
864323 2023-10-22T12:14:19 Z Blagoj Crossing (JOI21_crossing) C++17
100 / 100
2487 ms 77044 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++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 63 ms 936 KB Output is correct
2 Correct 66 ms 884 KB Output is correct
3 Correct 66 ms 928 KB Output is correct
4 Correct 73 ms 940 KB Output is correct
5 Correct 53 ms 820 KB Output is correct
6 Correct 53 ms 836 KB Output is correct
7 Correct 57 ms 852 KB Output is correct
8 Correct 56 ms 848 KB Output is correct
9 Correct 82 ms 852 KB Output is correct
10 Correct 56 ms 852 KB Output is correct
11 Correct 57 ms 992 KB Output is correct
12 Correct 55 ms 864 KB Output is correct
13 Correct 60 ms 1048 KB Output is correct
14 Correct 56 ms 860 KB Output is correct
15 Correct 59 ms 820 KB Output is correct
16 Correct 71 ms 972 KB Output is correct
17 Correct 56 ms 848 KB Output is correct
18 Correct 56 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 936 KB Output is correct
2 Correct 66 ms 884 KB Output is correct
3 Correct 66 ms 928 KB Output is correct
4 Correct 73 ms 940 KB Output is correct
5 Correct 53 ms 820 KB Output is correct
6 Correct 53 ms 836 KB Output is correct
7 Correct 57 ms 852 KB Output is correct
8 Correct 56 ms 848 KB Output is correct
9 Correct 82 ms 852 KB Output is correct
10 Correct 56 ms 852 KB Output is correct
11 Correct 57 ms 992 KB Output is correct
12 Correct 55 ms 864 KB Output is correct
13 Correct 60 ms 1048 KB Output is correct
14 Correct 56 ms 860 KB Output is correct
15 Correct 59 ms 820 KB Output is correct
16 Correct 71 ms 972 KB Output is correct
17 Correct 56 ms 848 KB Output is correct
18 Correct 56 ms 964 KB Output is correct
19 Correct 215 ms 10448 KB Output is correct
20 Correct 185 ms 10452 KB Output is correct
21 Correct 118 ms 9872 KB Output is correct
22 Correct 125 ms 8828 KB Output is correct
23 Correct 118 ms 1380 KB Output is correct
24 Correct 86 ms 1360 KB Output is correct
25 Correct 121 ms 10420 KB Output is correct
26 Correct 137 ms 10476 KB Output is correct
27 Correct 169 ms 10368 KB Output is correct
28 Correct 167 ms 10440 KB Output is correct
29 Correct 152 ms 10180 KB Output is correct
30 Correct 102 ms 1360 KB Output is correct
31 Correct 171 ms 10424 KB Output is correct
32 Correct 158 ms 9372 KB Output is correct
33 Correct 95 ms 1364 KB Output is correct
34 Correct 163 ms 10428 KB Output is correct
35 Correct 117 ms 7988 KB Output is correct
36 Correct 88 ms 1468 KB Output is correct
37 Correct 111 ms 1396 KB Output is correct
38 Correct 157 ms 10436 KB Output is correct
39 Correct 110 ms 10440 KB Output is correct
40 Correct 117 ms 7168 KB Output is correct
41 Correct 235 ms 10484 KB Output is correct
42 Correct 45 ms 10708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 936 KB Output is correct
2 Correct 66 ms 884 KB Output is correct
3 Correct 66 ms 928 KB Output is correct
4 Correct 73 ms 940 KB Output is correct
5 Correct 53 ms 820 KB Output is correct
6 Correct 53 ms 836 KB Output is correct
7 Correct 57 ms 852 KB Output is correct
8 Correct 56 ms 848 KB Output is correct
9 Correct 82 ms 852 KB Output is correct
10 Correct 56 ms 852 KB Output is correct
11 Correct 57 ms 992 KB Output is correct
12 Correct 55 ms 864 KB Output is correct
13 Correct 60 ms 1048 KB Output is correct
14 Correct 56 ms 860 KB Output is correct
15 Correct 59 ms 820 KB Output is correct
16 Correct 71 ms 972 KB Output is correct
17 Correct 56 ms 848 KB Output is correct
18 Correct 56 ms 964 KB Output is correct
19 Correct 327 ms 812 KB Output is correct
20 Correct 356 ms 1084 KB Output is correct
21 Correct 117 ms 856 KB Output is correct
22 Correct 101 ms 852 KB Output is correct
23 Correct 112 ms 932 KB Output is correct
24 Correct 110 ms 836 KB Output is correct
25 Correct 117 ms 848 KB Output is correct
26 Correct 106 ms 880 KB Output is correct
27 Correct 120 ms 988 KB Output is correct
28 Correct 105 ms 840 KB Output is correct
29 Correct 115 ms 848 KB Output is correct
30 Correct 113 ms 936 KB Output is correct
31 Correct 248 ms 848 KB Output is correct
32 Correct 244 ms 1080 KB Output is correct
33 Correct 255 ms 848 KB Output is correct
34 Correct 226 ms 852 KB Output is correct
35 Correct 249 ms 1264 KB Output is correct
36 Correct 253 ms 956 KB Output is correct
37 Correct 246 ms 980 KB Output is correct
38 Correct 256 ms 1300 KB Output is correct
39 Correct 252 ms 912 KB Output is correct
40 Correct 261 ms 1104 KB Output is correct
41 Correct 246 ms 1080 KB Output is correct
42 Correct 255 ms 852 KB Output is correct
43 Correct 266 ms 836 KB Output is correct
44 Correct 256 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 936 KB Output is correct
2 Correct 66 ms 884 KB Output is correct
3 Correct 66 ms 928 KB Output is correct
4 Correct 73 ms 940 KB Output is correct
5 Correct 53 ms 820 KB Output is correct
6 Correct 53 ms 836 KB Output is correct
7 Correct 57 ms 852 KB Output is correct
8 Correct 56 ms 848 KB Output is correct
9 Correct 82 ms 852 KB Output is correct
10 Correct 56 ms 852 KB Output is correct
11 Correct 57 ms 992 KB Output is correct
12 Correct 55 ms 864 KB Output is correct
13 Correct 60 ms 1048 KB Output is correct
14 Correct 56 ms 860 KB Output is correct
15 Correct 59 ms 820 KB Output is correct
16 Correct 71 ms 972 KB Output is correct
17 Correct 56 ms 848 KB Output is correct
18 Correct 56 ms 964 KB Output is correct
19 Correct 215 ms 10448 KB Output is correct
20 Correct 185 ms 10452 KB Output is correct
21 Correct 118 ms 9872 KB Output is correct
22 Correct 125 ms 8828 KB Output is correct
23 Correct 118 ms 1380 KB Output is correct
24 Correct 86 ms 1360 KB Output is correct
25 Correct 121 ms 10420 KB Output is correct
26 Correct 137 ms 10476 KB Output is correct
27 Correct 169 ms 10368 KB Output is correct
28 Correct 167 ms 10440 KB Output is correct
29 Correct 152 ms 10180 KB Output is correct
30 Correct 102 ms 1360 KB Output is correct
31 Correct 171 ms 10424 KB Output is correct
32 Correct 158 ms 9372 KB Output is correct
33 Correct 95 ms 1364 KB Output is correct
34 Correct 163 ms 10428 KB Output is correct
35 Correct 117 ms 7988 KB Output is correct
36 Correct 88 ms 1468 KB Output is correct
37 Correct 111 ms 1396 KB Output is correct
38 Correct 157 ms 10436 KB Output is correct
39 Correct 110 ms 10440 KB Output is correct
40 Correct 117 ms 7168 KB Output is correct
41 Correct 235 ms 10484 KB Output is correct
42 Correct 45 ms 10708 KB Output is correct
43 Correct 327 ms 812 KB Output is correct
44 Correct 356 ms 1084 KB Output is correct
45 Correct 117 ms 856 KB Output is correct
46 Correct 101 ms 852 KB Output is correct
47 Correct 112 ms 932 KB Output is correct
48 Correct 110 ms 836 KB Output is correct
49 Correct 117 ms 848 KB Output is correct
50 Correct 106 ms 880 KB Output is correct
51 Correct 120 ms 988 KB Output is correct
52 Correct 105 ms 840 KB Output is correct
53 Correct 115 ms 848 KB Output is correct
54 Correct 113 ms 936 KB Output is correct
55 Correct 248 ms 848 KB Output is correct
56 Correct 244 ms 1080 KB Output is correct
57 Correct 255 ms 848 KB Output is correct
58 Correct 226 ms 852 KB Output is correct
59 Correct 249 ms 1264 KB Output is correct
60 Correct 253 ms 956 KB Output is correct
61 Correct 246 ms 980 KB Output is correct
62 Correct 256 ms 1300 KB Output is correct
63 Correct 252 ms 912 KB Output is correct
64 Correct 261 ms 1104 KB Output is correct
65 Correct 246 ms 1080 KB Output is correct
66 Correct 255 ms 852 KB Output is correct
67 Correct 266 ms 836 KB Output is correct
68 Correct 256 ms 1052 KB Output is correct
69 Correct 1932 ms 64376 KB Output is correct
70 Correct 1611 ms 76424 KB Output is correct
71 Correct 198 ms 2232 KB Output is correct
72 Correct 249 ms 2412 KB Output is correct
73 Correct 199 ms 2384 KB Output is correct
74 Correct 365 ms 22716 KB Output is correct
75 Correct 196 ms 2176 KB Output is correct
76 Correct 387 ms 26804 KB Output is correct
77 Correct 439 ms 22752 KB Output is correct
78 Correct 197 ms 2200 KB Output is correct
79 Correct 196 ms 2324 KB Output is correct
80 Correct 1133 ms 54796 KB Output is correct
81 Correct 503 ms 5216 KB Output is correct
82 Correct 1324 ms 76488 KB Output is correct
83 Correct 1331 ms 72244 KB Output is correct
84 Correct 499 ms 4888 KB Output is correct
85 Correct 492 ms 4692 KB Output is correct
86 Correct 1553 ms 58180 KB Output is correct
87 Correct 1668 ms 77044 KB Output is correct
88 Correct 575 ms 5004 KB Output is correct
89 Correct 1409 ms 67584 KB Output is correct
90 Correct 1641 ms 76308 KB Output is correct
91 Correct 559 ms 4936 KB Output is correct
92 Correct 1136 ms 57932 KB Output is correct
93 Correct 486 ms 4692 KB Output is correct
94 Correct 483 ms 4804 KB Output is correct
95 Correct 497 ms 5240 KB Output is correct
96 Correct 158 ms 10480 KB Output is correct
97 Correct 714 ms 76300 KB Output is correct
98 Correct 1101 ms 50656 KB Output is correct
99 Correct 2487 ms 76760 KB Output is correct
100 Correct 198 ms 76560 KB Output is correct