Submission #804906

# Submission time Handle Problem Language Result Execution time Memory
804906 2023-08-03T11:52:55 Z myst6 Crossing (JOI21_crossing) C++14
100 / 100
2408 ms 23920 KB
#pragma GCC optimize(2)

#include <bits/stdc++.h>

using namespace std;

struct segtree {
    vector<char> orig;
    vector<char> upd;
    vector<bool> match;
    segtree(string s) {
        int sz = (int)s.size();
        orig.resize(sz*4,0);
        upd.resize(sz*4,0);
        match.resize(sz*4,1);
        build(s,1,0,sz-1);
    }
    int lc(int x) { return x << 1; }
    int rc(int x) { return lc(x) | 1; }
    void build(string &s, int x, int xl, int xr) {
        if (xl == xr) orig[x] = upd[x] = s[xl];
        else {
            int xm = (xl + xr) >> 1;
            build(s,lc(x),xl,xm);
            build(s,rc(x),xm+1,xr);
            if (orig[lc(x)] == orig[rc(x)]) {
                orig[x] = upd[x] = orig[lc(x)];
            }
        }
    }
    void pushdown(int x) {
        if (upd[x] == '0') return;
        if (lc(x) < upd.size()) {
            upd[lc(x)] = upd[x];
            match[lc(x)] = upd[lc(x)] == orig[lc(x)];
        }
        if (rc(x) < upd.size()) {
            upd[rc(x)] = upd[x];
            match[rc(x)] = upd[rc(x)] == orig[rc(x)];
        }
        upd[x] = '0';
    }
    void update(int l, int r, int x, int xl, int xr, char c) {
        if (l > r) return;
        if (l == xl && r == xr) {
            upd[x] = c;
            match[x] = upd[x] == orig[x];
        } else {
            int xm = (xl + xr) >> 1;
            pushdown(x);
            update(l, min(xm,r), lc(x), xl, xm, c);
            update(max(xm+1,l), r, rc(x), xm+1, xr, c);
            pushdown(lc(x)); pushdown(rc(x));
            match[x] = match[lc(x)] && match[rc(x)];
        }
    }
    bool query() {
        return match[1];
    }
};

string cross(string a, string b) {
    string out = a;
    for (int i=0; i<(int)a.size(); i++) {
        if (a[i] != b[i]) {
            set<char> C = {'J', 'O', 'I'};
            C.erase(a[i]);
            C.erase(b[i]);
            out[i] = *C.begin();
        }
    }
    return out;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    string d = cross(a, b);
    string e = cross(b, c);
    string f = cross(c, a);
    string g = cross(d, e);
    string h = cross(e, f);
    string i = cross(f, d);

    set<string> V = {a,b,c,d,e,f,g,h,i};
    // cerr << V.size() << endl;

    vector<segtree> trees;
    for (const string &s : V) {
        trees.push_back(segtree(s));
    }
    int q;
    cin >> q;
    string t;
    cin >> t;
    for (int i=0; i<(int)t.size(); i++) {
        for (segtree &tree : trees) tree.update(i,i,1,0,n-1,t[i]);
    }
    auto output_ans = [&]() {
        bool ans = false;
        for (segtree &tree : trees) {
            if (tree.query()) {
                ans = true;
                break;
            }
        }
        cout << ( ans ? "Yes" : "No" ) << "\n";
    };
    output_ans();
    for (int i=0; i<q; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        char c;
        cin >> c;
        for (segtree &tree : trees) tree.update(l,r,1,0,n-1,c);
        output_ans();
    }

    return 0;
}

Compilation message

Main.cpp: In member function 'void segtree::pushdown(int)':
Main.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if (lc(x) < upd.size()) {
      |             ~~~~~~^~~~~~~~~~~~
Main.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if (rc(x) < upd.size()) {
      |             ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2240 KB Output is correct
2 Correct 75 ms 2448 KB Output is correct
3 Correct 75 ms 2208 KB Output is correct
4 Correct 66 ms 2276 KB Output is correct
5 Correct 61 ms 2300 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 65 ms 2332 KB Output is correct
9 Correct 66 ms 2400 KB Output is correct
10 Correct 69 ms 2424 KB Output is correct
11 Correct 64 ms 2332 KB Output is correct
12 Correct 63 ms 2444 KB Output is correct
13 Correct 68 ms 2420 KB Output is correct
14 Correct 63 ms 2368 KB Output is correct
15 Correct 65 ms 2380 KB Output is correct
16 Correct 63 ms 2404 KB Output is correct
17 Correct 72 ms 2364 KB Output is correct
18 Correct 69 ms 2312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2240 KB Output is correct
2 Correct 75 ms 2448 KB Output is correct
3 Correct 75 ms 2208 KB Output is correct
4 Correct 66 ms 2276 KB Output is correct
5 Correct 61 ms 2300 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 65 ms 2332 KB Output is correct
9 Correct 66 ms 2400 KB Output is correct
10 Correct 69 ms 2424 KB Output is correct
11 Correct 64 ms 2332 KB Output is correct
12 Correct 63 ms 2444 KB Output is correct
13 Correct 68 ms 2420 KB Output is correct
14 Correct 63 ms 2368 KB Output is correct
15 Correct 65 ms 2380 KB Output is correct
16 Correct 63 ms 2404 KB Output is correct
17 Correct 72 ms 2364 KB Output is correct
18 Correct 69 ms 2312 KB Output is correct
19 Correct 236 ms 9104 KB Output is correct
20 Correct 254 ms 8964 KB Output is correct
21 Correct 160 ms 8564 KB Output is correct
22 Correct 169 ms 7944 KB Output is correct
23 Correct 97 ms 3396 KB Output is correct
24 Correct 106 ms 3416 KB Output is correct
25 Correct 178 ms 9024 KB Output is correct
26 Correct 181 ms 9024 KB Output is correct
27 Correct 230 ms 9064 KB Output is correct
28 Correct 221 ms 9080 KB Output is correct
29 Correct 209 ms 8776 KB Output is correct
30 Correct 122 ms 3404 KB Output is correct
31 Correct 209 ms 9028 KB Output is correct
32 Correct 211 ms 8476 KB Output is correct
33 Correct 101 ms 3404 KB Output is correct
34 Correct 202 ms 9024 KB Output is correct
35 Correct 144 ms 7388 KB Output is correct
36 Correct 96 ms 3448 KB Output is correct
37 Correct 95 ms 3452 KB Output is correct
38 Correct 234 ms 8856 KB Output is correct
39 Correct 158 ms 9160 KB Output is correct
40 Correct 143 ms 7148 KB Output is correct
41 Correct 261 ms 9304 KB Output is correct
42 Correct 86 ms 8512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2240 KB Output is correct
2 Correct 75 ms 2448 KB Output is correct
3 Correct 75 ms 2208 KB Output is correct
4 Correct 66 ms 2276 KB Output is correct
5 Correct 61 ms 2300 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 65 ms 2332 KB Output is correct
9 Correct 66 ms 2400 KB Output is correct
10 Correct 69 ms 2424 KB Output is correct
11 Correct 64 ms 2332 KB Output is correct
12 Correct 63 ms 2444 KB Output is correct
13 Correct 68 ms 2420 KB Output is correct
14 Correct 63 ms 2368 KB Output is correct
15 Correct 65 ms 2380 KB Output is correct
16 Correct 63 ms 2404 KB Output is correct
17 Correct 72 ms 2364 KB Output is correct
18 Correct 69 ms 2312 KB Output is correct
19 Correct 411 ms 2248 KB Output is correct
20 Correct 439 ms 2300 KB Output is correct
21 Correct 130 ms 2352 KB Output is correct
22 Correct 115 ms 2188 KB Output is correct
23 Correct 134 ms 2516 KB Output is correct
24 Correct 136 ms 2280 KB Output is correct
25 Correct 132 ms 2376 KB Output is correct
26 Correct 122 ms 2288 KB Output is correct
27 Correct 130 ms 2508 KB Output is correct
28 Correct 118 ms 2144 KB Output is correct
29 Correct 132 ms 2340 KB Output is correct
30 Correct 115 ms 2236 KB Output is correct
31 Correct 319 ms 2444 KB Output is correct
32 Correct 292 ms 2424 KB Output is correct
33 Correct 324 ms 2380 KB Output is correct
34 Correct 282 ms 2284 KB Output is correct
35 Correct 293 ms 2384 KB Output is correct
36 Correct 308 ms 2356 KB Output is correct
37 Correct 307 ms 2388 KB Output is correct
38 Correct 311 ms 2376 KB Output is correct
39 Correct 313 ms 2360 KB Output is correct
40 Correct 323 ms 2396 KB Output is correct
41 Correct 310 ms 2384 KB Output is correct
42 Correct 329 ms 2424 KB Output is correct
43 Correct 300 ms 2368 KB Output is correct
44 Correct 323 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2240 KB Output is correct
2 Correct 75 ms 2448 KB Output is correct
3 Correct 75 ms 2208 KB Output is correct
4 Correct 66 ms 2276 KB Output is correct
5 Correct 61 ms 2300 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 65 ms 2332 KB Output is correct
9 Correct 66 ms 2400 KB Output is correct
10 Correct 69 ms 2424 KB Output is correct
11 Correct 64 ms 2332 KB Output is correct
12 Correct 63 ms 2444 KB Output is correct
13 Correct 68 ms 2420 KB Output is correct
14 Correct 63 ms 2368 KB Output is correct
15 Correct 65 ms 2380 KB Output is correct
16 Correct 63 ms 2404 KB Output is correct
17 Correct 72 ms 2364 KB Output is correct
18 Correct 69 ms 2312 KB Output is correct
19 Correct 236 ms 9104 KB Output is correct
20 Correct 254 ms 8964 KB Output is correct
21 Correct 160 ms 8564 KB Output is correct
22 Correct 169 ms 7944 KB Output is correct
23 Correct 97 ms 3396 KB Output is correct
24 Correct 106 ms 3416 KB Output is correct
25 Correct 178 ms 9024 KB Output is correct
26 Correct 181 ms 9024 KB Output is correct
27 Correct 230 ms 9064 KB Output is correct
28 Correct 221 ms 9080 KB Output is correct
29 Correct 209 ms 8776 KB Output is correct
30 Correct 122 ms 3404 KB Output is correct
31 Correct 209 ms 9028 KB Output is correct
32 Correct 211 ms 8476 KB Output is correct
33 Correct 101 ms 3404 KB Output is correct
34 Correct 202 ms 9024 KB Output is correct
35 Correct 144 ms 7388 KB Output is correct
36 Correct 96 ms 3448 KB Output is correct
37 Correct 95 ms 3452 KB Output is correct
38 Correct 234 ms 8856 KB Output is correct
39 Correct 158 ms 9160 KB Output is correct
40 Correct 143 ms 7148 KB Output is correct
41 Correct 261 ms 9304 KB Output is correct
42 Correct 86 ms 8512 KB Output is correct
43 Correct 411 ms 2248 KB Output is correct
44 Correct 439 ms 2300 KB Output is correct
45 Correct 130 ms 2352 KB Output is correct
46 Correct 115 ms 2188 KB Output is correct
47 Correct 134 ms 2516 KB Output is correct
48 Correct 136 ms 2280 KB Output is correct
49 Correct 132 ms 2376 KB Output is correct
50 Correct 122 ms 2288 KB Output is correct
51 Correct 130 ms 2508 KB Output is correct
52 Correct 118 ms 2144 KB Output is correct
53 Correct 132 ms 2340 KB Output is correct
54 Correct 115 ms 2236 KB Output is correct
55 Correct 319 ms 2444 KB Output is correct
56 Correct 292 ms 2424 KB Output is correct
57 Correct 324 ms 2380 KB Output is correct
58 Correct 282 ms 2284 KB Output is correct
59 Correct 293 ms 2384 KB Output is correct
60 Correct 308 ms 2356 KB Output is correct
61 Correct 307 ms 2388 KB Output is correct
62 Correct 311 ms 2376 KB Output is correct
63 Correct 313 ms 2360 KB Output is correct
64 Correct 323 ms 2396 KB Output is correct
65 Correct 310 ms 2384 KB Output is correct
66 Correct 329 ms 2424 KB Output is correct
67 Correct 300 ms 2368 KB Output is correct
68 Correct 323 ms 2516 KB Output is correct
69 Correct 1852 ms 20012 KB Output is correct
70 Correct 2142 ms 23500 KB Output is correct
71 Correct 229 ms 3656 KB Output is correct
72 Correct 232 ms 3664 KB Output is correct
73 Correct 234 ms 3700 KB Output is correct
74 Correct 467 ms 11008 KB Output is correct
75 Correct 223 ms 3636 KB Output is correct
76 Correct 579 ms 12544 KB Output is correct
77 Correct 500 ms 11176 KB Output is correct
78 Correct 237 ms 3664 KB Output is correct
79 Correct 225 ms 3628 KB Output is correct
80 Correct 1144 ms 17596 KB Output is correct
81 Correct 569 ms 4116 KB Output is correct
82 Correct 1560 ms 23684 KB Output is correct
83 Correct 1422 ms 22452 KB Output is correct
84 Correct 564 ms 4164 KB Output is correct
85 Correct 595 ms 4176 KB Output is correct
86 Correct 1548 ms 18612 KB Output is correct
87 Correct 1907 ms 23628 KB Output is correct
88 Correct 679 ms 4136 KB Output is correct
89 Correct 1552 ms 21068 KB Output is correct
90 Correct 1710 ms 23544 KB Output is correct
91 Correct 663 ms 4144 KB Output is correct
92 Correct 1205 ms 18472 KB Output is correct
93 Correct 557 ms 4104 KB Output is correct
94 Correct 570 ms 4148 KB Output is correct
95 Correct 563 ms 4184 KB Output is correct
96 Correct 227 ms 8880 KB Output is correct
97 Correct 1064 ms 23920 KB Output is correct
98 Correct 1197 ms 16952 KB Output is correct
99 Correct 2408 ms 23840 KB Output is correct
100 Correct 611 ms 22992 KB Output is correct