Submission #1013904

# Submission time Handle Problem Language Result Execution time Memory
1013904 2024-07-04T07:59:29 Z Baytoro Crossing (JOI21_crossing) C++17
100 / 100
2048 ms 90420 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
//#define int ll
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
struct node {
    int ok;
    char c;
};
struct segtree {
    vector<node> tree;
    vector<int> lazy;
    node combine(node a, node b) {
        node res={0,'x'};

        res.ok=a.ok&b.ok;

        if(a.c=='x' || b.c=='x' || a.c!=b.c) res.c='x';
        else res.c=a.c;

        return res;
    }
    void build(int x, int l, int r, string &a, string &b) {
        if(l==r) {
            if(a[l]==b[l])
                tree[x].ok=1;
            else
                tree[x].ok=0;
            tree[x].c=a[l];
            return;
        }
        int md=(l+r)/2;
        build(2*x,l,md,a,b);
        build(2*x+1,md+1,r,a,b);

        tree[x]=combine(tree[2*x],tree[2*x+1]);
    }
    void init(int x, string a, string b) {
        tree.resize(x*4);
        lazy.assign(x*4,-1);
        build(1,0,x-1,a,b);
    }
    void push(int x,int l, int r) {
        if(tree[x].c==lazy[x])
            tree[x].ok=1;
        else
            tree[x].ok=0;
        if(2*x+1<tree.size()) {
            lazy[2*x]=lazy[x];
            lazy[2*x+1]=lazy[x];
        }
        lazy[x]=-1;
    }
    void update(int lx, int rx, char c, int x, int l, int r) {
        if(lazy[x]!=-1) {
            push(x,l,r);
        }
        if(l>rx || r<lx) return;
        if(lx<=l && r<=rx) {
            lazy[x]=c;
            push(x,l,r);
            return;
        }

        int md=(l+r)/2;


        update(lx,rx,c,2*x,l,md);
        update(lx,rx,c,2*x+1,md+1,r);

        tree[x]=combine(tree[2*x],tree[2*x+1]);

    }
    bool get() {
        return tree[1].ok;
    }
};
string comb(string a, string b) {
    for(int i=0;i<a.size();i++) {
        if(a[i]==b[i]) continue;
        if('J'!=a[i] && 'J'!=b[i]) a[i]='J';
        else if('O'!=a[i] && 'O'!=b[i]) a[i]='O';
        else if('I'!=a[i] && 'I'!=b[i]) a[i]='I';
    }
    return a;
}
void solve() {
    int n;cin>>n;
    string a,b,c;cin>>a>>b>>c;
    int q;cin>>q;
    string s;cin>>s;
    vector<segtree> st(9);
    st[0].init(n,a,s); //cout<<a<<endl;
    st[1].init(n,b,s); //cout<<b<<endl;
    st[2].init(n,c,s); //cout<<c<<endl;

    st[3].init(n,comb(a,b),s); //cout<<comb(a,b)<<endl;
    st[4].init(n,comb(a,c),s); //cout<<comb(a,c)<<endl;
    st[5].init(n,comb(b,c),s); //cout<<comb(b,c)<<endl;

    st[6].init(n,comb(comb(a,b),c),s); //cout<<comb(comb(a,b),c)<<endl;
    st[7].init(n,comb(comb(c,b),a),s); //cout<<comb(comb(c,b),a)<<endl;
    st[8].init(n,comb(comb(a,c),b),s); //cout<<comb(comb(a,c),b)<<endl;
    //st.init(n,a,s);
    bool ans=0;
    for(int i=0;i<9;i++) ans|=st[i].get();
    cout<<(ans?"Yes":"No")<<endl;

    while(q--) {
        int l, r;cin>>l>>r;l--,r--;
        char c;cin>>c;
        ans=0;
        for(int i=0;i<9;i++)
            st[i].update(l,r,c,1,0,n-1);
        for(int i=0;i<9;i++)
            ans|=st[i].get();
        cout<<(ans?"Yes":"No")<<endl;
    }
}
signed main(){
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
}
//#endif

Compilation message

Main.cpp: In member function 'void segtree::push(int, int, int)':
Main.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if(2*x+1<tree.size()) {
      |            ~~~~~^~~~~~~~~~~~
Main.cpp: In function 'std::string comb(std::string, std::string)':
Main.cpp:83:18: 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 365 ms 2392 KB Output is correct
2 Correct 460 ms 2384 KB Output is correct
3 Correct 474 ms 2388 KB Output is correct
4 Correct 408 ms 2280 KB Output is correct
5 Correct 408 ms 2384 KB Output is correct
6 Correct 369 ms 2392 KB Output is correct
7 Correct 393 ms 2384 KB Output is correct
8 Correct 460 ms 2388 KB Output is correct
9 Correct 401 ms 2388 KB Output is correct
10 Correct 393 ms 2432 KB Output is correct
11 Correct 407 ms 2536 KB Output is correct
12 Correct 408 ms 2556 KB Output is correct
13 Correct 430 ms 2528 KB Output is correct
14 Correct 403 ms 2396 KB Output is correct
15 Correct 395 ms 2584 KB Output is correct
16 Correct 424 ms 2568 KB Output is correct
17 Correct 402 ms 2388 KB Output is correct
18 Correct 396 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 2392 KB Output is correct
2 Correct 460 ms 2384 KB Output is correct
3 Correct 474 ms 2388 KB Output is correct
4 Correct 408 ms 2280 KB Output is correct
5 Correct 408 ms 2384 KB Output is correct
6 Correct 369 ms 2392 KB Output is correct
7 Correct 393 ms 2384 KB Output is correct
8 Correct 460 ms 2388 KB Output is correct
9 Correct 401 ms 2388 KB Output is correct
10 Correct 393 ms 2432 KB Output is correct
11 Correct 407 ms 2536 KB Output is correct
12 Correct 408 ms 2556 KB Output is correct
13 Correct 430 ms 2528 KB Output is correct
14 Correct 403 ms 2396 KB Output is correct
15 Correct 395 ms 2584 KB Output is correct
16 Correct 424 ms 2568 KB Output is correct
17 Correct 402 ms 2388 KB Output is correct
18 Correct 396 ms 2384 KB Output is correct
19 Correct 1518 ms 90180 KB Output is correct
20 Correct 1263 ms 90120 KB Output is correct
21 Correct 1092 ms 84852 KB Output is correct
22 Correct 1036 ms 76316 KB Output is correct
23 Correct 626 ms 7704 KB Output is correct
24 Correct 592 ms 7760 KB Output is correct
25 Correct 1095 ms 90140 KB Output is correct
26 Correct 1186 ms 90180 KB Output is correct
27 Correct 1054 ms 89988 KB Output is correct
28 Correct 1224 ms 90012 KB Output is correct
29 Correct 1053 ms 87608 KB Output is correct
30 Correct 681 ms 7708 KB Output is correct
31 Correct 1054 ms 90148 KB Output is correct
32 Correct 1118 ms 82400 KB Output is correct
33 Correct 596 ms 7636 KB Output is correct
34 Correct 1146 ms 90288 KB Output is correct
35 Correct 889 ms 67824 KB Output is correct
36 Correct 560 ms 7708 KB Output is correct
37 Correct 569 ms 7764 KB Output is correct
38 Correct 1171 ms 89928 KB Output is correct
39 Correct 832 ms 90040 KB Output is correct
40 Correct 1242 ms 60408 KB Output is correct
41 Correct 2048 ms 90420 KB Output is correct
42 Correct 366 ms 89504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 2392 KB Output is correct
2 Correct 460 ms 2384 KB Output is correct
3 Correct 474 ms 2388 KB Output is correct
4 Correct 408 ms 2280 KB Output is correct
5 Correct 408 ms 2384 KB Output is correct
6 Correct 369 ms 2392 KB Output is correct
7 Correct 393 ms 2384 KB Output is correct
8 Correct 460 ms 2388 KB Output is correct
9 Correct 401 ms 2388 KB Output is correct
10 Correct 393 ms 2432 KB Output is correct
11 Correct 407 ms 2536 KB Output is correct
12 Correct 408 ms 2556 KB Output is correct
13 Correct 430 ms 2528 KB Output is correct
14 Correct 403 ms 2396 KB Output is correct
15 Correct 395 ms 2584 KB Output is correct
16 Correct 424 ms 2568 KB Output is correct
17 Correct 402 ms 2388 KB Output is correct
18 Correct 396 ms 2384 KB Output is correct
19 Correct 445 ms 2552 KB Output is correct
20 Correct 490 ms 2384 KB Output is correct
21 Correct 450 ms 2560 KB Output is correct
22 Correct 362 ms 2268 KB Output is correct
23 Correct 429 ms 2384 KB Output is correct
24 Correct 418 ms 2384 KB Output is correct
25 Correct 416 ms 2388 KB Output is correct
26 Correct 430 ms 2368 KB Output is correct
27 Correct 459 ms 2428 KB Output is correct
28 Correct 452 ms 2384 KB Output is correct
29 Correct 447 ms 2564 KB Output is correct
30 Correct 370 ms 2372 KB Output is correct
31 Correct 440 ms 2384 KB Output is correct
32 Correct 468 ms 2388 KB Output is correct
33 Correct 433 ms 2388 KB Output is correct
34 Correct 409 ms 2584 KB Output is correct
35 Correct 412 ms 2384 KB Output is correct
36 Correct 449 ms 2548 KB Output is correct
37 Correct 438 ms 2384 KB Output is correct
38 Correct 439 ms 2476 KB Output is correct
39 Correct 429 ms 2388 KB Output is correct
40 Correct 472 ms 2384 KB Output is correct
41 Correct 473 ms 2380 KB Output is correct
42 Correct 449 ms 2560 KB Output is correct
43 Correct 410 ms 2540 KB Output is correct
44 Correct 468 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 2392 KB Output is correct
2 Correct 460 ms 2384 KB Output is correct
3 Correct 474 ms 2388 KB Output is correct
4 Correct 408 ms 2280 KB Output is correct
5 Correct 408 ms 2384 KB Output is correct
6 Correct 369 ms 2392 KB Output is correct
7 Correct 393 ms 2384 KB Output is correct
8 Correct 460 ms 2388 KB Output is correct
9 Correct 401 ms 2388 KB Output is correct
10 Correct 393 ms 2432 KB Output is correct
11 Correct 407 ms 2536 KB Output is correct
12 Correct 408 ms 2556 KB Output is correct
13 Correct 430 ms 2528 KB Output is correct
14 Correct 403 ms 2396 KB Output is correct
15 Correct 395 ms 2584 KB Output is correct
16 Correct 424 ms 2568 KB Output is correct
17 Correct 402 ms 2388 KB Output is correct
18 Correct 396 ms 2384 KB Output is correct
19 Correct 1518 ms 90180 KB Output is correct
20 Correct 1263 ms 90120 KB Output is correct
21 Correct 1092 ms 84852 KB Output is correct
22 Correct 1036 ms 76316 KB Output is correct
23 Correct 626 ms 7704 KB Output is correct
24 Correct 592 ms 7760 KB Output is correct
25 Correct 1095 ms 90140 KB Output is correct
26 Correct 1186 ms 90180 KB Output is correct
27 Correct 1054 ms 89988 KB Output is correct
28 Correct 1224 ms 90012 KB Output is correct
29 Correct 1053 ms 87608 KB Output is correct
30 Correct 681 ms 7708 KB Output is correct
31 Correct 1054 ms 90148 KB Output is correct
32 Correct 1118 ms 82400 KB Output is correct
33 Correct 596 ms 7636 KB Output is correct
34 Correct 1146 ms 90288 KB Output is correct
35 Correct 889 ms 67824 KB Output is correct
36 Correct 560 ms 7708 KB Output is correct
37 Correct 569 ms 7764 KB Output is correct
38 Correct 1171 ms 89928 KB Output is correct
39 Correct 832 ms 90040 KB Output is correct
40 Correct 1242 ms 60408 KB Output is correct
41 Correct 2048 ms 90420 KB Output is correct
42 Correct 366 ms 89504 KB Output is correct
43 Correct 445 ms 2552 KB Output is correct
44 Correct 490 ms 2384 KB Output is correct
45 Correct 450 ms 2560 KB Output is correct
46 Correct 362 ms 2268 KB Output is correct
47 Correct 429 ms 2384 KB Output is correct
48 Correct 418 ms 2384 KB Output is correct
49 Correct 416 ms 2388 KB Output is correct
50 Correct 430 ms 2368 KB Output is correct
51 Correct 459 ms 2428 KB Output is correct
52 Correct 452 ms 2384 KB Output is correct
53 Correct 447 ms 2564 KB Output is correct
54 Correct 370 ms 2372 KB Output is correct
55 Correct 440 ms 2384 KB Output is correct
56 Correct 468 ms 2388 KB Output is correct
57 Correct 433 ms 2388 KB Output is correct
58 Correct 409 ms 2584 KB Output is correct
59 Correct 412 ms 2384 KB Output is correct
60 Correct 449 ms 2548 KB Output is correct
61 Correct 438 ms 2384 KB Output is correct
62 Correct 439 ms 2476 KB Output is correct
63 Correct 429 ms 2388 KB Output is correct
64 Correct 472 ms 2384 KB Output is correct
65 Correct 473 ms 2380 KB Output is correct
66 Correct 449 ms 2560 KB Output is correct
67 Correct 410 ms 2540 KB Output is correct
68 Correct 468 ms 2384 KB Output is correct
69 Correct 1418 ms 75592 KB Output is correct
70 Correct 1290 ms 89952 KB Output is correct
71 Correct 664 ms 7584 KB Output is correct
72 Correct 656 ms 7716 KB Output is correct
73 Correct 644 ms 8000 KB Output is correct
74 Correct 1091 ms 75416 KB Output is correct
75 Correct 587 ms 7644 KB Output is correct
76 Correct 1268 ms 90172 KB Output is correct
77 Correct 1166 ms 75676 KB Output is correct
78 Correct 732 ms 7660 KB Output is correct
79 Correct 648 ms 7632 KB Output is correct
80 Correct 1076 ms 64940 KB Output is correct
81 Correct 659 ms 7744 KB Output is correct
82 Correct 1141 ms 90132 KB Output is correct
83 Correct 1201 ms 84780 KB Output is correct
84 Correct 625 ms 7520 KB Output is correct
85 Correct 650 ms 7856 KB Output is correct
86 Correct 1180 ms 69152 KB Output is correct
87 Correct 1325 ms 90136 KB Output is correct
88 Correct 653 ms 7852 KB Output is correct
89 Correct 1190 ms 79704 KB Output is correct
90 Correct 1301 ms 90212 KB Output is correct
91 Correct 660 ms 7760 KB Output is correct
92 Correct 1058 ms 68064 KB Output is correct
93 Correct 664 ms 7760 KB Output is correct
94 Correct 641 ms 7648 KB Output is correct
95 Correct 679 ms 7648 KB Output is correct
96 Correct 1151 ms 89788 KB Output is correct
97 Correct 734 ms 90184 KB Output is correct
98 Correct 1181 ms 60560 KB Output is correct
99 Correct 1789 ms 90336 KB Output is correct
100 Correct 362 ms 89496 KB Output is correct