Submission #1117372

# Submission time Handle Problem Language Result Execution time Memory
1117372 2024-11-23T12:48:10 Z Sharky Crossing (JOI21_crossing) C++17
100 / 100
1489 ms 27468 KB
#include "bits/stdc++.h"
using namespace std;

int n;
string T = "JOI";
string S;

string cross(string& a, string& b) {
    string res;
    for (int i = 0; i < n; i++) {
        if (a[i] == b[i]) res += a[i];
        else for (char& c : T) if (a[i] != c && b[i] != c) res += c;
    }
    return res;
}

struct Node {
    char rng = '?';
    bool same = false;
} dummy;

struct SegTree {
    int size = 1;
    string tar;
    vector<Node> seg;
    vector<char> lazy;
    void init(int n, string _tar) {
        while (size < n) size *= 2;
        tar = _tar;
        seg.assign(2 * size + 10, dummy);
        lazy.assign(2 * size + 10, '?');
    }
    void push(int id) {
        if (lazy[id] != '?') {
            seg[id].same = (seg[id].rng == lazy[id]);
            if (id < size) for (int i = 0; i < 2; i++) lazy[id * 2 + i] = lazy[id];
        }
        lazy[id] = '?';
    }
    void pull(int id) {
        if (!seg[id * 2].same || !seg[id * 2 + 1].same) seg[id].same = false;
        else seg[id].same = true;
    }
    void build(int l, int r, int id) {
        if (l == r) {
            seg[id].rng = tar[l];
            seg[id].same = (tar[l] == S[l]);
            return;
        }
        int mid = (l + r) >> 1;
        build(l, mid, id * 2);
        build(mid + 1, r, id * 2 + 1);
        if (seg[id * 2].rng == seg[id * 2 + 1].rng) seg[id].rng = seg[id * 2].rng;
        else seg[id].rng = '?';
        pull(id);
    }
    void update(int ql, int qr, char c, int l, int r, int id) {
        push(id);
        if (qr < l || r < ql) return;
        if (ql <= l && r <= qr) {
            lazy[id] = c;
            push(id);
            return;
        }
        int mid = (l + r) >> 1;
        update(ql, qr, c, l, mid, id * 2);
        update(ql, qr, c, mid + 1, r, id * 2 + 1);
        pull(id);
    }
    bool query(int ql, int qr, int l, int r, int id) {
        push(id);
        if (qr < l || r < ql) return true;
        if (ql <= l && r <= qr) return seg[id].same;
        int mid = (l + r) >> 1;
        bool L = query(ql, qr, l, mid, id * 2);
        bool R = query(ql, qr, mid + 1, r, id * 2 + 1);
        if (!L || !R) return false;
        return true;
    }
} ST[9];

struct Query {
    int l, r;
    char c;
};

int main() {
    string a, b, c;
    cin >> n >> a >> b >> c;
    set<string> proc;
    queue<string> q;
    q.push(a); q.push(b); q.push(c);
    while (!q.empty()) {
        string s = q.front();
        q.pop();
        for (auto t : proc) {
            string res = cross(s, t);
            if (!proc.count(res)) q.push(res);
        }
        proc.insert(s);
    }
    vector<string> str;
    for (auto x : proc) str.push_back(x);
    int queries;
    cin >> queries;
    vector<Query> Q(queries);
    vector<bool> ans(queries, false);
    cin >> S;
    S = '.' + S;
    for (int i = 0; i < queries; i++) cin >> Q[i].l >> Q[i].r >> Q[i].c;
    for (int i = 0; i < min((int) str.size(), 9); i++) {
        str[i] = '.' + str[i];
        ST[i].init(n + 1, str[i]);
        ST[i].build(1, n, 1);
    }
    bool init = false;
    for (int i = 0; i < min((int) str.size(), 9); i++) {
        if (ST[i].query(1, n, 1, n, 1)) {
            init = true;
            break;
        }
    }
    cout << (init ? "Yes\n" : "No\n");
    for (int i = 0; i < queries; i++) {
        auto [l, r, ch] = Q[i];
        for (int j = 0; j < min((int) str.size(), 9); j++) {
            ST[j].update(l, r, ch, 1, n, 1);
            if (!ans[i] && ST[j].query(1, n, 1, n, 1)) ans[i] = true;
        }
        cout << (ans[i] ? "Yes\n" : "No\n");
    }
}
# Verdict Execution time Memory Grader output
1 Correct 76 ms 4424 KB Output is correct
2 Correct 90 ms 4832 KB Output is correct
3 Correct 76 ms 4680 KB Output is correct
4 Correct 71 ms 4680 KB Output is correct
5 Correct 73 ms 4680 KB Output is correct
6 Correct 71 ms 4608 KB Output is correct
7 Correct 79 ms 4824 KB Output is correct
8 Correct 89 ms 4804 KB Output is correct
9 Correct 79 ms 4952 KB Output is correct
10 Correct 77 ms 4680 KB Output is correct
11 Correct 79 ms 4680 KB Output is correct
12 Correct 76 ms 4948 KB Output is correct
13 Correct 83 ms 4680 KB Output is correct
14 Correct 75 ms 4940 KB Output is correct
15 Correct 80 ms 4712 KB Output is correct
16 Correct 80 ms 4936 KB Output is correct
17 Correct 90 ms 4844 KB Output is correct
18 Correct 87 ms 4936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 4424 KB Output is correct
2 Correct 90 ms 4832 KB Output is correct
3 Correct 76 ms 4680 KB Output is correct
4 Correct 71 ms 4680 KB Output is correct
5 Correct 73 ms 4680 KB Output is correct
6 Correct 71 ms 4608 KB Output is correct
7 Correct 79 ms 4824 KB Output is correct
8 Correct 89 ms 4804 KB Output is correct
9 Correct 79 ms 4952 KB Output is correct
10 Correct 77 ms 4680 KB Output is correct
11 Correct 79 ms 4680 KB Output is correct
12 Correct 76 ms 4948 KB Output is correct
13 Correct 83 ms 4680 KB Output is correct
14 Correct 75 ms 4940 KB Output is correct
15 Correct 80 ms 4712 KB Output is correct
16 Correct 80 ms 4936 KB Output is correct
17 Correct 90 ms 4844 KB Output is correct
18 Correct 87 ms 4936 KB Output is correct
19 Correct 205 ms 10472 KB Output is correct
20 Correct 214 ms 10228 KB Output is correct
21 Correct 159 ms 9944 KB Output is correct
22 Correct 144 ms 9520 KB Output is correct
23 Correct 122 ms 5708 KB Output is correct
24 Correct 119 ms 5708 KB Output is correct
25 Correct 167 ms 10472 KB Output is correct
26 Correct 163 ms 10472 KB Output is correct
27 Correct 186 ms 10468 KB Output is correct
28 Correct 177 ms 10352 KB Output is correct
29 Correct 168 ms 10252 KB Output is correct
30 Correct 119 ms 5704 KB Output is correct
31 Correct 173 ms 10472 KB Output is correct
32 Correct 170 ms 9944 KB Output is correct
33 Correct 112 ms 5704 KB Output is correct
34 Correct 178 ms 10468 KB Output is correct
35 Correct 153 ms 9124 KB Output is correct
36 Correct 123 ms 5820 KB Output is correct
37 Correct 108 ms 5704 KB Output is correct
38 Correct 172 ms 10216 KB Output is correct
39 Correct 141 ms 10476 KB Output is correct
40 Correct 150 ms 9268 KB Output is correct
41 Correct 199 ms 10724 KB Output is correct
42 Correct 84 ms 9704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 4424 KB Output is correct
2 Correct 90 ms 4832 KB Output is correct
3 Correct 76 ms 4680 KB Output is correct
4 Correct 71 ms 4680 KB Output is correct
5 Correct 73 ms 4680 KB Output is correct
6 Correct 71 ms 4608 KB Output is correct
7 Correct 79 ms 4824 KB Output is correct
8 Correct 89 ms 4804 KB Output is correct
9 Correct 79 ms 4952 KB Output is correct
10 Correct 77 ms 4680 KB Output is correct
11 Correct 79 ms 4680 KB Output is correct
12 Correct 76 ms 4948 KB Output is correct
13 Correct 83 ms 4680 KB Output is correct
14 Correct 75 ms 4940 KB Output is correct
15 Correct 80 ms 4712 KB Output is correct
16 Correct 80 ms 4936 KB Output is correct
17 Correct 90 ms 4844 KB Output is correct
18 Correct 87 ms 4936 KB Output is correct
19 Correct 231 ms 4604 KB Output is correct
20 Correct 265 ms 4680 KB Output is correct
21 Correct 111 ms 4936 KB Output is correct
22 Correct 98 ms 4424 KB Output is correct
23 Correct 118 ms 4952 KB Output is correct
24 Correct 113 ms 4768 KB Output is correct
25 Correct 115 ms 4684 KB Output is correct
26 Correct 110 ms 4620 KB Output is correct
27 Correct 119 ms 4944 KB Output is correct
28 Correct 103 ms 4424 KB Output is correct
29 Correct 118 ms 4680 KB Output is correct
30 Correct 104 ms 4544 KB Output is correct
31 Correct 215 ms 4836 KB Output is correct
32 Correct 208 ms 4680 KB Output is correct
33 Correct 210 ms 4712 KB Output is correct
34 Correct 205 ms 4188 KB Output is correct
35 Correct 208 ms 4772 KB Output is correct
36 Correct 208 ms 4936 KB Output is correct
37 Correct 212 ms 4936 KB Output is correct
38 Correct 241 ms 4832 KB Output is correct
39 Correct 221 ms 4932 KB Output is correct
40 Correct 222 ms 4936 KB Output is correct
41 Correct 206 ms 4712 KB Output is correct
42 Correct 239 ms 4580 KB Output is correct
43 Correct 211 ms 4680 KB Output is correct
44 Correct 219 ms 4720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 4424 KB Output is correct
2 Correct 90 ms 4832 KB Output is correct
3 Correct 76 ms 4680 KB Output is correct
4 Correct 71 ms 4680 KB Output is correct
5 Correct 73 ms 4680 KB Output is correct
6 Correct 71 ms 4608 KB Output is correct
7 Correct 79 ms 4824 KB Output is correct
8 Correct 89 ms 4804 KB Output is correct
9 Correct 79 ms 4952 KB Output is correct
10 Correct 77 ms 4680 KB Output is correct
11 Correct 79 ms 4680 KB Output is correct
12 Correct 76 ms 4948 KB Output is correct
13 Correct 83 ms 4680 KB Output is correct
14 Correct 75 ms 4940 KB Output is correct
15 Correct 80 ms 4712 KB Output is correct
16 Correct 80 ms 4936 KB Output is correct
17 Correct 90 ms 4844 KB Output is correct
18 Correct 87 ms 4936 KB Output is correct
19 Correct 205 ms 10472 KB Output is correct
20 Correct 214 ms 10228 KB Output is correct
21 Correct 159 ms 9944 KB Output is correct
22 Correct 144 ms 9520 KB Output is correct
23 Correct 122 ms 5708 KB Output is correct
24 Correct 119 ms 5708 KB Output is correct
25 Correct 167 ms 10472 KB Output is correct
26 Correct 163 ms 10472 KB Output is correct
27 Correct 186 ms 10468 KB Output is correct
28 Correct 177 ms 10352 KB Output is correct
29 Correct 168 ms 10252 KB Output is correct
30 Correct 119 ms 5704 KB Output is correct
31 Correct 173 ms 10472 KB Output is correct
32 Correct 170 ms 9944 KB Output is correct
33 Correct 112 ms 5704 KB Output is correct
34 Correct 178 ms 10468 KB Output is correct
35 Correct 153 ms 9124 KB Output is correct
36 Correct 123 ms 5820 KB Output is correct
37 Correct 108 ms 5704 KB Output is correct
38 Correct 172 ms 10216 KB Output is correct
39 Correct 141 ms 10476 KB Output is correct
40 Correct 150 ms 9268 KB Output is correct
41 Correct 199 ms 10724 KB Output is correct
42 Correct 84 ms 9704 KB Output is correct
43 Correct 231 ms 4604 KB Output is correct
44 Correct 265 ms 4680 KB Output is correct
45 Correct 111 ms 4936 KB Output is correct
46 Correct 98 ms 4424 KB Output is correct
47 Correct 118 ms 4952 KB Output is correct
48 Correct 113 ms 4768 KB Output is correct
49 Correct 115 ms 4684 KB Output is correct
50 Correct 110 ms 4620 KB Output is correct
51 Correct 119 ms 4944 KB Output is correct
52 Correct 103 ms 4424 KB Output is correct
53 Correct 118 ms 4680 KB Output is correct
54 Correct 104 ms 4544 KB Output is correct
55 Correct 215 ms 4836 KB Output is correct
56 Correct 208 ms 4680 KB Output is correct
57 Correct 210 ms 4712 KB Output is correct
58 Correct 205 ms 4188 KB Output is correct
59 Correct 208 ms 4772 KB Output is correct
60 Correct 208 ms 4936 KB Output is correct
61 Correct 212 ms 4936 KB Output is correct
62 Correct 241 ms 4832 KB Output is correct
63 Correct 221 ms 4932 KB Output is correct
64 Correct 222 ms 4936 KB Output is correct
65 Correct 206 ms 4712 KB Output is correct
66 Correct 239 ms 4580 KB Output is correct
67 Correct 211 ms 4680 KB Output is correct
68 Correct 219 ms 4720 KB Output is correct
69 Correct 1247 ms 25460 KB Output is correct
70 Correct 1234 ms 27364 KB Output is correct
71 Correct 194 ms 5960 KB Output is correct
72 Correct 190 ms 5960 KB Output is correct
73 Correct 201 ms 5960 KB Output is correct
74 Correct 261 ms 13400 KB Output is correct
75 Correct 197 ms 5960 KB Output is correct
76 Correct 298 ms 14624 KB Output is correct
77 Correct 273 ms 13724 KB Output is correct
78 Correct 201 ms 6120 KB Output is correct
79 Correct 194 ms 5960 KB Output is correct
80 Correct 830 ms 24824 KB Output is correct
81 Correct 408 ms 6728 KB Output is correct
82 Correct 965 ms 27220 KB Output is correct
83 Correct 930 ms 26784 KB Output is correct
84 Correct 431 ms 6708 KB Output is correct
85 Correct 444 ms 6736 KB Output is correct
86 Correct 875 ms 25192 KB Output is correct
87 Correct 956 ms 27428 KB Output is correct
88 Correct 455 ms 6728 KB Output is correct
89 Correct 841 ms 26164 KB Output is correct
90 Correct 886 ms 27440 KB Output is correct
91 Correct 483 ms 6728 KB Output is correct
92 Correct 822 ms 25116 KB Output is correct
93 Correct 409 ms 6772 KB Output is correct
94 Correct 401 ms 6876 KB Output is correct
95 Correct 427 ms 6728 KB Output is correct
96 Correct 179 ms 10216 KB Output is correct
97 Correct 609 ms 27300 KB Output is correct
98 Correct 794 ms 24832 KB Output is correct
99 Correct 1489 ms 27468 KB Output is correct
100 Correct 391 ms 26664 KB Output is correct