Submission #804655

# Submission time Handle Problem Language Result Execution time Memory
804655 2023-08-03T10:43:16 Z myst6 Crossing (JOI21_crossing) C++14
26 / 100
6298 ms 13432 KB
#include <bits/stdc++.h>

using namespace std;

struct intervals {
    set<pair<int,int>> LR;
    intervals() {}
    void _add(int l, int r) {
        if (l > r) return;
        else LR.insert({l, r});
    }
    void add(int l, int r) {
        remove(l, r);
        _add(l, r);
    }
    void remove(int l, int r) {
        auto it = LR.lower_bound({l,0});
        if (it != LR.begin()) {
            --it;
            int l2 = it->first;
            int r2 = it->second;
            LR.erase(it);
            _add(l2,min(l-1,r2));
            it = LR.lower_bound({l,0});
        }
        while (it != LR.end() && it->first <= r) {
            int l2 = it->first;
            int r2 = it->second;
            LR.erase(it);
            _add(max(r+1,l2),r2);
            it = LR.lower_bound({l,0});
        }
    }
    void print() {
        for (pair<int,int> seg : LR) {
            cout << "[" << seg.first << "," << seg.second << "] U ";
        }
        cout << "[] \n";
    }
    bool empty() {
        return LR.empty();
    }
};

struct segtree {
    vector<char> orig;
    vector<char> upd;
    intervals wrong;
    segtree(string s) {
        int sz = (int)s.size();
        orig.resize(sz*4,0);
        upd.resize(sz*4,0);
        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 check(int x, int xl, int xr) {
        if (upd[x] != orig[x]) {
            wrong.add(xl, xr);
        } else {
            wrong.remove(xl, xr);
        }
    }
    void pushdown(int x, int xl, int xr) {
        if (xl == xr) return;
        if (upd[x] == '0') return;
        wrong.remove(xl, xr);
        int xm = (xl + xr) >> 1;
        if (lc(x) < upd.size()) {
            upd[lc(x)] = upd[x];
            check(lc(x), xl, xm);
        }
        if (rc(x) < upd.size()) {
            upd[rc(x)] = upd[x];
            check(rc(x), xm+1, xr);
        }
        upd[x] = '0';
    }
    void update(int l, int r, int x, int xl, int xr, char c) {
        if (l > r) return;
        assert(x != 0);
        pushdown(x, xl, xr);
        if (l == xl && r == xr) {
            upd[x] = c;
            check(x, xl, xr);
        } else {
            int xm = (xl + xr) >> 1;
            update(l, min(xm,r), lc(x), xl, xm, c);
            update(max(xm+1,l), r, rc(x), xm+1, xr, c);
        }
    }
};

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) {
        segtree tree(a);
        int q;
        cin >> q;
        string t;
        cin >> t;
        for (int i=0; i<(int)t.size(); i++) {
            tree.update(i,i,1,0,n-1,t[i]);
        }
        cout << ( tree.wrong.empty() ? "Yes" : "No" ) << "\n"; 
        // tree.wrong.print();
        for (int i=0; i<q; i++) {
            int l, r;
            cin >> l >> r;
            l--, r--;
            char c;
            cin >> c;
            tree.update(l,r,1,0,n-1,c);
            cout << ( tree.wrong.empty() ? "Yes" : "No" ) << "\n"; 
            // tree.wrong.print();
        }
    } else { // F

    }
    return 0;
}

Compilation message

Main.cpp: In member function 'void segtree::pushdown(int, int, int)':
Main.cpp:80:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         if (lc(x) < upd.size()) {
      |             ~~~~~~^~~~~~~~~~~~
Main.cpp:84:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         if (rc(x) < upd.size()) {
      |             ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 799 ms 868 KB Output is correct
2 Correct 917 ms 2320 KB Output is correct
3 Correct 1161 ms 2260 KB Output is correct
4 Correct 604 ms 2328 KB Output is correct
5 Correct 596 ms 2236 KB Output is correct
6 Correct 621 ms 2288 KB Output is correct
7 Correct 608 ms 2352 KB Output is correct
8 Correct 677 ms 2364 KB Output is correct
9 Correct 685 ms 2548 KB Output is correct
10 Correct 710 ms 2352 KB Output is correct
11 Correct 736 ms 2380 KB Output is correct
12 Correct 699 ms 2320 KB Output is correct
13 Correct 723 ms 2440 KB Output is correct
14 Correct 723 ms 2428 KB Output is correct
15 Correct 743 ms 2368 KB Output is correct
16 Correct 737 ms 2356 KB Output is correct
17 Correct 725 ms 2424 KB Output is correct
18 Correct 991 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 799 ms 868 KB Output is correct
2 Correct 917 ms 2320 KB Output is correct
3 Correct 1161 ms 2260 KB Output is correct
4 Correct 604 ms 2328 KB Output is correct
5 Correct 596 ms 2236 KB Output is correct
6 Correct 621 ms 2288 KB Output is correct
7 Correct 608 ms 2352 KB Output is correct
8 Correct 677 ms 2364 KB Output is correct
9 Correct 685 ms 2548 KB Output is correct
10 Correct 710 ms 2352 KB Output is correct
11 Correct 736 ms 2380 KB Output is correct
12 Correct 699 ms 2320 KB Output is correct
13 Correct 723 ms 2440 KB Output is correct
14 Correct 723 ms 2428 KB Output is correct
15 Correct 743 ms 2368 KB Output is correct
16 Correct 737 ms 2356 KB Output is correct
17 Correct 725 ms 2424 KB Output is correct
18 Correct 991 ms 2252 KB Output is correct
19 Correct 5262 ms 13272 KB Output is correct
20 Correct 6298 ms 13088 KB Output is correct
21 Correct 1482 ms 8004 KB Output is correct
22 Correct 1950 ms 11444 KB Output is correct
23 Correct 1242 ms 3656 KB Output is correct
24 Correct 1247 ms 3664 KB Output is correct
25 Correct 1750 ms 13196 KB Output is correct
26 Correct 2103 ms 13236 KB Output is correct
27 Correct 2730 ms 7672 KB Output is correct
28 Correct 2857 ms 13120 KB Output is correct
29 Correct 2605 ms 7500 KB Output is correct
30 Correct 1653 ms 3480 KB Output is correct
31 Correct 2546 ms 7736 KB Output is correct
32 Correct 2490 ms 12188 KB Output is correct
33 Correct 1291 ms 3576 KB Output is correct
34 Correct 2664 ms 13300 KB Output is correct
35 Correct 1528 ms 10488 KB Output is correct
36 Correct 1288 ms 3664 KB Output is correct
37 Correct 1255 ms 3772 KB Output is correct
38 Correct 4003 ms 13016 KB Output is correct
39 Correct 627 ms 7172 KB Output is correct
40 Correct 1888 ms 11924 KB Output is correct
41 Correct 772 ms 13432 KB Output is correct
42 Correct 542 ms 12608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 799 ms 868 KB Output is correct
2 Correct 917 ms 2320 KB Output is correct
3 Correct 1161 ms 2260 KB Output is correct
4 Correct 604 ms 2328 KB Output is correct
5 Correct 596 ms 2236 KB Output is correct
6 Correct 621 ms 2288 KB Output is correct
7 Correct 608 ms 2352 KB Output is correct
8 Correct 677 ms 2364 KB Output is correct
9 Correct 685 ms 2548 KB Output is correct
10 Correct 710 ms 2352 KB Output is correct
11 Correct 736 ms 2380 KB Output is correct
12 Correct 699 ms 2320 KB Output is correct
13 Correct 723 ms 2440 KB Output is correct
14 Correct 723 ms 2428 KB Output is correct
15 Correct 743 ms 2368 KB Output is correct
16 Correct 737 ms 2356 KB Output is correct
17 Correct 725 ms 2424 KB Output is correct
18 Correct 991 ms 2252 KB Output is correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 799 ms 868 KB Output is correct
2 Correct 917 ms 2320 KB Output is correct
3 Correct 1161 ms 2260 KB Output is correct
4 Correct 604 ms 2328 KB Output is correct
5 Correct 596 ms 2236 KB Output is correct
6 Correct 621 ms 2288 KB Output is correct
7 Correct 608 ms 2352 KB Output is correct
8 Correct 677 ms 2364 KB Output is correct
9 Correct 685 ms 2548 KB Output is correct
10 Correct 710 ms 2352 KB Output is correct
11 Correct 736 ms 2380 KB Output is correct
12 Correct 699 ms 2320 KB Output is correct
13 Correct 723 ms 2440 KB Output is correct
14 Correct 723 ms 2428 KB Output is correct
15 Correct 743 ms 2368 KB Output is correct
16 Correct 737 ms 2356 KB Output is correct
17 Correct 725 ms 2424 KB Output is correct
18 Correct 991 ms 2252 KB Output is correct
19 Correct 5262 ms 13272 KB Output is correct
20 Correct 6298 ms 13088 KB Output is correct
21 Correct 1482 ms 8004 KB Output is correct
22 Correct 1950 ms 11444 KB Output is correct
23 Correct 1242 ms 3656 KB Output is correct
24 Correct 1247 ms 3664 KB Output is correct
25 Correct 1750 ms 13196 KB Output is correct
26 Correct 2103 ms 13236 KB Output is correct
27 Correct 2730 ms 7672 KB Output is correct
28 Correct 2857 ms 13120 KB Output is correct
29 Correct 2605 ms 7500 KB Output is correct
30 Correct 1653 ms 3480 KB Output is correct
31 Correct 2546 ms 7736 KB Output is correct
32 Correct 2490 ms 12188 KB Output is correct
33 Correct 1291 ms 3576 KB Output is correct
34 Correct 2664 ms 13300 KB Output is correct
35 Correct 1528 ms 10488 KB Output is correct
36 Correct 1288 ms 3664 KB Output is correct
37 Correct 1255 ms 3772 KB Output is correct
38 Correct 4003 ms 13016 KB Output is correct
39 Correct 627 ms 7172 KB Output is correct
40 Correct 1888 ms 11924 KB Output is correct
41 Correct 772 ms 13432 KB Output is correct
42 Correct 542 ms 12608 KB Output is correct
43 Incorrect 1 ms 212 KB Output isn't correct
44 Halted 0 ms 0 KB -