Submission #804710

# Submission time Handle Problem Language Result Execution time Memory
804710 2023-08-03T10:56:50 Z myst6 Crossing (JOI21_crossing) C++14
26 / 100
7000 ms 9860 KB
#pragma GCC optimize(2)

#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);
        }
    }
};

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;

    set<string> V;
    V.insert(a);
    V.insert(b);
    V.insert(c);
    bool upd = true;
    while (upd) {
        upd = false;
        for (auto it1=V.begin(); it1!=V.end(); it1++) {
            for (auto it2=V.begin(); it2!=V.end(); it2++) {
                if (it1 == it2) continue;
                string x = cross(*it1, *it2);
                if (!V.count(x)) {
                    V.insert(x);
                    upd = true;
                }
            }
        }
    }

    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.wrong.empty()) {
                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, int, int)':
Main.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         if (lc(x) < upd.size()) {
      |             ~~~~~~^~~~~~~~~~~~
Main.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         if (rc(x) < upd.size()) {
      |             ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 580 ms 836 KB Output is correct
2 Correct 670 ms 816 KB Output is correct
3 Correct 859 ms 788 KB Output is correct
4 Correct 354 ms 852 KB Output is correct
5 Correct 349 ms 832 KB Output is correct
6 Correct 366 ms 1016 KB Output is correct
7 Correct 347 ms 844 KB Output is correct
8 Correct 393 ms 908 KB Output is correct
9 Correct 392 ms 896 KB Output is correct
10 Correct 440 ms 788 KB Output is correct
11 Correct 441 ms 960 KB Output is correct
12 Correct 433 ms 868 KB Output is correct
13 Correct 437 ms 860 KB Output is correct
14 Correct 446 ms 864 KB Output is correct
15 Correct 457 ms 840 KB Output is correct
16 Correct 454 ms 832 KB Output is correct
17 Correct 436 ms 800 KB Output is correct
18 Correct 675 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 580 ms 836 KB Output is correct
2 Correct 670 ms 816 KB Output is correct
3 Correct 859 ms 788 KB Output is correct
4 Correct 354 ms 852 KB Output is correct
5 Correct 349 ms 832 KB Output is correct
6 Correct 366 ms 1016 KB Output is correct
7 Correct 347 ms 844 KB Output is correct
8 Correct 393 ms 908 KB Output is correct
9 Correct 392 ms 896 KB Output is correct
10 Correct 440 ms 788 KB Output is correct
11 Correct 441 ms 960 KB Output is correct
12 Correct 433 ms 868 KB Output is correct
13 Correct 437 ms 860 KB Output is correct
14 Correct 446 ms 864 KB Output is correct
15 Correct 457 ms 840 KB Output is correct
16 Correct 454 ms 832 KB Output is correct
17 Correct 436 ms 800 KB Output is correct
18 Correct 675 ms 1020 KB Output is correct
19 Correct 5175 ms 9696 KB Output is correct
20 Correct 6145 ms 9736 KB Output is correct
21 Correct 1204 ms 4740 KB Output is correct
22 Correct 1728 ms 8200 KB Output is correct
23 Correct 947 ms 1284 KB Output is correct
24 Correct 950 ms 1292 KB Output is correct
25 Correct 1469 ms 9648 KB Output is correct
26 Correct 1874 ms 9740 KB Output is correct
27 Correct 2404 ms 4224 KB Output is correct
28 Correct 2559 ms 9724 KB Output is correct
29 Correct 2257 ms 4112 KB Output is correct
30 Correct 1330 ms 1324 KB Output is correct
31 Correct 2276 ms 4080 KB Output is correct
32 Correct 2282 ms 8864 KB Output is correct
33 Correct 1022 ms 1288 KB Output is correct
34 Correct 2401 ms 9808 KB Output is correct
35 Correct 1331 ms 7468 KB Output is correct
36 Correct 988 ms 1296 KB Output is correct
37 Correct 1008 ms 1320 KB Output is correct
38 Correct 3699 ms 9820 KB Output is correct
39 Correct 279 ms 3664 KB Output is correct
40 Correct 1576 ms 8740 KB Output is correct
41 Correct 488 ms 9856 KB Output is correct
42 Correct 302 ms 9860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 580 ms 836 KB Output is correct
2 Correct 670 ms 816 KB Output is correct
3 Correct 859 ms 788 KB Output is correct
4 Correct 354 ms 852 KB Output is correct
5 Correct 349 ms 832 KB Output is correct
6 Correct 366 ms 1016 KB Output is correct
7 Correct 347 ms 844 KB Output is correct
8 Correct 393 ms 908 KB Output is correct
9 Correct 392 ms 896 KB Output is correct
10 Correct 440 ms 788 KB Output is correct
11 Correct 441 ms 960 KB Output is correct
12 Correct 433 ms 868 KB Output is correct
13 Correct 437 ms 860 KB Output is correct
14 Correct 446 ms 864 KB Output is correct
15 Correct 457 ms 840 KB Output is correct
16 Correct 454 ms 832 KB Output is correct
17 Correct 436 ms 800 KB Output is correct
18 Correct 675 ms 1020 KB Output is correct
19 Correct 4987 ms 2332 KB Output is correct
20 Execution timed out 7037 ms 2332 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 580 ms 836 KB Output is correct
2 Correct 670 ms 816 KB Output is correct
3 Correct 859 ms 788 KB Output is correct
4 Correct 354 ms 852 KB Output is correct
5 Correct 349 ms 832 KB Output is correct
6 Correct 366 ms 1016 KB Output is correct
7 Correct 347 ms 844 KB Output is correct
8 Correct 393 ms 908 KB Output is correct
9 Correct 392 ms 896 KB Output is correct
10 Correct 440 ms 788 KB Output is correct
11 Correct 441 ms 960 KB Output is correct
12 Correct 433 ms 868 KB Output is correct
13 Correct 437 ms 860 KB Output is correct
14 Correct 446 ms 864 KB Output is correct
15 Correct 457 ms 840 KB Output is correct
16 Correct 454 ms 832 KB Output is correct
17 Correct 436 ms 800 KB Output is correct
18 Correct 675 ms 1020 KB Output is correct
19 Correct 5175 ms 9696 KB Output is correct
20 Correct 6145 ms 9736 KB Output is correct
21 Correct 1204 ms 4740 KB Output is correct
22 Correct 1728 ms 8200 KB Output is correct
23 Correct 947 ms 1284 KB Output is correct
24 Correct 950 ms 1292 KB Output is correct
25 Correct 1469 ms 9648 KB Output is correct
26 Correct 1874 ms 9740 KB Output is correct
27 Correct 2404 ms 4224 KB Output is correct
28 Correct 2559 ms 9724 KB Output is correct
29 Correct 2257 ms 4112 KB Output is correct
30 Correct 1330 ms 1324 KB Output is correct
31 Correct 2276 ms 4080 KB Output is correct
32 Correct 2282 ms 8864 KB Output is correct
33 Correct 1022 ms 1288 KB Output is correct
34 Correct 2401 ms 9808 KB Output is correct
35 Correct 1331 ms 7468 KB Output is correct
36 Correct 988 ms 1296 KB Output is correct
37 Correct 1008 ms 1320 KB Output is correct
38 Correct 3699 ms 9820 KB Output is correct
39 Correct 279 ms 3664 KB Output is correct
40 Correct 1576 ms 8740 KB Output is correct
41 Correct 488 ms 9856 KB Output is correct
42 Correct 302 ms 9860 KB Output is correct
43 Correct 4987 ms 2332 KB Output is correct
44 Execution timed out 7037 ms 2332 KB Time limit exceeded
45 Halted 0 ms 0 KB -