Submission #423208

# Submission time Handle Problem Language Result Execution time Memory
423208 2021-06-10T20:02:03 Z MKopchev Crossing (JOI21_crossing) C++14
100 / 100
767 ms 19492 KB
#include<bits/stdc++.h>
using namespace std;

const int base=23,mod=1e9+9,nmax=2e5+42;

int n;
string inp[3];

long long pwr[nmax],mem_pref[nmax];

string t;

set<string> valid;

int order[3]={0,1,2};

int hsh(char c)
{
    if(c=='J')return 1;
    if(c=='O')return 2;
    return 3;
}

struct info
{
    int lazy;
    long long sum;
    int SZ;
};
info tree[4*nmax];

info actual(info cur)
{
    if(cur.lazy)
    {
        cur.sum=cur.lazy*mem_pref[cur.SZ-1]%mod;
        cur.lazy=0;
    }
    return cur;
}
info my_merge(info a,info b)
{
    a=actual(a);
    b=actual(b);

    a.sum=(a.sum*pwr[b.SZ]+b.sum)%mod;
    a.SZ=(a.SZ+b.SZ);

    return a;
}

void build(int node,int l,int r)
{
    if(l==r)
    {
        tree[node].sum=hsh(t[l]);
        tree[node].SZ=1;
        return;
    }

    int av=(l+r)/2;

    build(node*2,l,av);
    build(node*2+1,av+1,r);

    tree[node]=my_merge(tree[node*2],tree[node*2+1]);
}

void push(int node)
{
    if(tree[node].lazy)
    {
        tree[node*2].lazy=tree[node].lazy;
        tree[node*2+1].lazy=tree[node].lazy;

        tree[node].lazy=0;
    }
}
void update(int node,int l,int r,int lq,int rq,int val)
{
    if(l==lq&&r==rq)
    {
        tree[node].lazy=val;
        return;
    }

    push(node);

    int av=(l+r)/2;

    if(lq<=av)update(node*2,l,av,lq,min(av,rq),val);
    if(av<rq)update(node*2+1,av+1,r,max(av+1,lq),rq,val);

    tree[node]=my_merge(tree[node*2],tree[node*2+1]);
}
set<long long> valid_hsh;

void check()
{
    if(valid_hsh.count(actual(tree[1]).sum))cout<<"Yes\n";
    else cout<<"No\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    pwr[0]=1;
    for(int i=1;i<nmax;i++)pwr[i]=pwr[i-1]*base%mod;

    mem_pref[0]=1;
    for(int i=1;i<nmax;i++)
    {
        mem_pref[i]=(mem_pref[i-1]+pwr[i])%mod;
    }

    cin>>n;

    for(int i=0;i<3;i++)cin>>inp[i];

    do
    {
        string cur="";

        for(int i=0;i<=5;i++)
        {
            if(i==0)cur=inp[order[i]];
            else
            {
                int other=order[i%3];

                for(int k=0;k<n;k++)
                {
                    if(cur[k]!=inp[other][k])
                    {
                        cur[k]=1LL*'I'+'J'+'O'-cur[k]-inp[other][k];
                    }
                }
            }

            valid.insert(cur);
        }
    }
    while(next_permutation(order,order+3));

    for(auto w:valid)
    {
        long long cur=0;

        for(auto v:w)
            cur=(cur*base+hsh(v))%mod;

        valid_hsh.insert(cur);
    }

    int q;
    cin>>q;

    cin>>t;

    build(1,0,n-1);

    check();

    for(int i=1;i<=q;i++)
    {
        int l,r;
        char c;

        cin>>l>>r>>c;

        update(1,0,n-1,l-1,r-1,hsh(c));

        check();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 393 ms 3976 KB Output is correct
2 Correct 424 ms 4048 KB Output is correct
3 Correct 434 ms 4228 KB Output is correct
4 Correct 394 ms 3964 KB Output is correct
5 Correct 401 ms 4036 KB Output is correct
6 Correct 387 ms 3984 KB Output is correct
7 Correct 406 ms 4136 KB Output is correct
8 Correct 408 ms 4064 KB Output is correct
9 Correct 413 ms 4040 KB Output is correct
10 Correct 414 ms 3992 KB Output is correct
11 Correct 407 ms 4036 KB Output is correct
12 Correct 415 ms 4064 KB Output is correct
13 Correct 406 ms 4036 KB Output is correct
14 Correct 414 ms 4184 KB Output is correct
15 Correct 411 ms 3996 KB Output is correct
16 Correct 412 ms 4016 KB Output is correct
17 Correct 414 ms 4044 KB Output is correct
18 Correct 420 ms 4036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 3976 KB Output is correct
2 Correct 424 ms 4048 KB Output is correct
3 Correct 434 ms 4228 KB Output is correct
4 Correct 394 ms 3964 KB Output is correct
5 Correct 401 ms 4036 KB Output is correct
6 Correct 387 ms 3984 KB Output is correct
7 Correct 406 ms 4136 KB Output is correct
8 Correct 408 ms 4064 KB Output is correct
9 Correct 413 ms 4040 KB Output is correct
10 Correct 414 ms 3992 KB Output is correct
11 Correct 407 ms 4036 KB Output is correct
12 Correct 415 ms 4064 KB Output is correct
13 Correct 406 ms 4036 KB Output is correct
14 Correct 414 ms 4184 KB Output is correct
15 Correct 411 ms 3996 KB Output is correct
16 Correct 412 ms 4016 KB Output is correct
17 Correct 414 ms 4044 KB Output is correct
18 Correct 420 ms 4036 KB Output is correct
19 Correct 700 ms 17672 KB Output is correct
20 Correct 692 ms 17792 KB Output is correct
21 Correct 545 ms 17556 KB Output is correct
22 Correct 538 ms 17440 KB Output is correct
23 Correct 497 ms 4776 KB Output is correct
24 Correct 493 ms 4932 KB Output is correct
25 Correct 583 ms 17564 KB Output is correct
26 Correct 592 ms 17716 KB Output is correct
27 Correct 620 ms 17704 KB Output is correct
28 Correct 625 ms 17548 KB Output is correct
29 Correct 614 ms 17556 KB Output is correct
30 Correct 517 ms 4820 KB Output is correct
31 Correct 627 ms 17688 KB Output is correct
32 Correct 592 ms 17528 KB Output is correct
33 Correct 496 ms 4932 KB Output is correct
34 Correct 613 ms 17620 KB Output is correct
35 Correct 524 ms 17304 KB Output is correct
36 Correct 488 ms 4816 KB Output is correct
37 Correct 501 ms 5072 KB Output is correct
38 Correct 625 ms 17576 KB Output is correct
39 Correct 535 ms 17572 KB Output is correct
40 Correct 565 ms 11184 KB Output is correct
41 Correct 722 ms 17976 KB Output is correct
42 Correct 380 ms 17828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 3976 KB Output is correct
2 Correct 424 ms 4048 KB Output is correct
3 Correct 434 ms 4228 KB Output is correct
4 Correct 394 ms 3964 KB Output is correct
5 Correct 401 ms 4036 KB Output is correct
6 Correct 387 ms 3984 KB Output is correct
7 Correct 406 ms 4136 KB Output is correct
8 Correct 408 ms 4064 KB Output is correct
9 Correct 413 ms 4040 KB Output is correct
10 Correct 414 ms 3992 KB Output is correct
11 Correct 407 ms 4036 KB Output is correct
12 Correct 415 ms 4064 KB Output is correct
13 Correct 406 ms 4036 KB Output is correct
14 Correct 414 ms 4184 KB Output is correct
15 Correct 411 ms 3996 KB Output is correct
16 Correct 412 ms 4016 KB Output is correct
17 Correct 414 ms 4044 KB Output is correct
18 Correct 420 ms 4036 KB Output is correct
19 Correct 407 ms 3908 KB Output is correct
20 Correct 433 ms 4124 KB Output is correct
21 Correct 409 ms 4096 KB Output is correct
22 Correct 372 ms 3908 KB Output is correct
23 Correct 412 ms 4036 KB Output is correct
24 Correct 397 ms 4092 KB Output is correct
25 Correct 423 ms 4036 KB Output is correct
26 Correct 395 ms 4224 KB Output is correct
27 Correct 412 ms 3916 KB Output is correct
28 Correct 382 ms 3984 KB Output is correct
29 Correct 412 ms 4032 KB Output is correct
30 Correct 371 ms 3996 KB Output is correct
31 Correct 414 ms 4036 KB Output is correct
32 Correct 410 ms 4036 KB Output is correct
33 Correct 419 ms 4056 KB Output is correct
34 Correct 386 ms 3984 KB Output is correct
35 Correct 412 ms 3972 KB Output is correct
36 Correct 411 ms 4024 KB Output is correct
37 Correct 417 ms 3984 KB Output is correct
38 Correct 415 ms 4036 KB Output is correct
39 Correct 409 ms 4036 KB Output is correct
40 Correct 418 ms 4036 KB Output is correct
41 Correct 409 ms 4036 KB Output is correct
42 Correct 412 ms 3980 KB Output is correct
43 Correct 400 ms 3976 KB Output is correct
44 Correct 415 ms 4012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 3976 KB Output is correct
2 Correct 424 ms 4048 KB Output is correct
3 Correct 434 ms 4228 KB Output is correct
4 Correct 394 ms 3964 KB Output is correct
5 Correct 401 ms 4036 KB Output is correct
6 Correct 387 ms 3984 KB Output is correct
7 Correct 406 ms 4136 KB Output is correct
8 Correct 408 ms 4064 KB Output is correct
9 Correct 413 ms 4040 KB Output is correct
10 Correct 414 ms 3992 KB Output is correct
11 Correct 407 ms 4036 KB Output is correct
12 Correct 415 ms 4064 KB Output is correct
13 Correct 406 ms 4036 KB Output is correct
14 Correct 414 ms 4184 KB Output is correct
15 Correct 411 ms 3996 KB Output is correct
16 Correct 412 ms 4016 KB Output is correct
17 Correct 414 ms 4044 KB Output is correct
18 Correct 420 ms 4036 KB Output is correct
19 Correct 700 ms 17672 KB Output is correct
20 Correct 692 ms 17792 KB Output is correct
21 Correct 545 ms 17556 KB Output is correct
22 Correct 538 ms 17440 KB Output is correct
23 Correct 497 ms 4776 KB Output is correct
24 Correct 493 ms 4932 KB Output is correct
25 Correct 583 ms 17564 KB Output is correct
26 Correct 592 ms 17716 KB Output is correct
27 Correct 620 ms 17704 KB Output is correct
28 Correct 625 ms 17548 KB Output is correct
29 Correct 614 ms 17556 KB Output is correct
30 Correct 517 ms 4820 KB Output is correct
31 Correct 627 ms 17688 KB Output is correct
32 Correct 592 ms 17528 KB Output is correct
33 Correct 496 ms 4932 KB Output is correct
34 Correct 613 ms 17620 KB Output is correct
35 Correct 524 ms 17304 KB Output is correct
36 Correct 488 ms 4816 KB Output is correct
37 Correct 501 ms 5072 KB Output is correct
38 Correct 625 ms 17576 KB Output is correct
39 Correct 535 ms 17572 KB Output is correct
40 Correct 565 ms 11184 KB Output is correct
41 Correct 722 ms 17976 KB Output is correct
42 Correct 380 ms 17828 KB Output is correct
43 Correct 407 ms 3908 KB Output is correct
44 Correct 433 ms 4124 KB Output is correct
45 Correct 409 ms 4096 KB Output is correct
46 Correct 372 ms 3908 KB Output is correct
47 Correct 412 ms 4036 KB Output is correct
48 Correct 397 ms 4092 KB Output is correct
49 Correct 423 ms 4036 KB Output is correct
50 Correct 395 ms 4224 KB Output is correct
51 Correct 412 ms 3916 KB Output is correct
52 Correct 382 ms 3984 KB Output is correct
53 Correct 412 ms 4032 KB Output is correct
54 Correct 371 ms 3996 KB Output is correct
55 Correct 414 ms 4036 KB Output is correct
56 Correct 410 ms 4036 KB Output is correct
57 Correct 419 ms 4056 KB Output is correct
58 Correct 386 ms 3984 KB Output is correct
59 Correct 412 ms 3972 KB Output is correct
60 Correct 411 ms 4024 KB Output is correct
61 Correct 417 ms 3984 KB Output is correct
62 Correct 415 ms 4036 KB Output is correct
63 Correct 409 ms 4036 KB Output is correct
64 Correct 418 ms 4036 KB Output is correct
65 Correct 409 ms 4036 KB Output is correct
66 Correct 412 ms 3980 KB Output is correct
67 Correct 400 ms 3976 KB Output is correct
68 Correct 415 ms 4012 KB Output is correct
69 Correct 652 ms 18760 KB Output is correct
70 Correct 747 ms 19228 KB Output is correct
71 Correct 492 ms 4932 KB Output is correct
72 Correct 492 ms 4976 KB Output is correct
73 Correct 491 ms 4844 KB Output is correct
74 Correct 555 ms 17684 KB Output is correct
75 Correct 490 ms 4804 KB Output is correct
76 Correct 605 ms 18024 KB Output is correct
77 Correct 577 ms 17900 KB Output is correct
78 Correct 486 ms 4812 KB Output is correct
79 Correct 495 ms 4892 KB Output is correct
80 Correct 572 ms 18588 KB Output is correct
81 Correct 488 ms 4968 KB Output is correct
82 Correct 635 ms 19112 KB Output is correct
83 Correct 610 ms 18920 KB Output is correct
84 Correct 498 ms 4932 KB Output is correct
85 Correct 508 ms 4936 KB Output is correct
86 Correct 639 ms 18504 KB Output is correct
87 Correct 671 ms 19172 KB Output is correct
88 Correct 523 ms 4908 KB Output is correct
89 Correct 626 ms 18792 KB Output is correct
90 Correct 648 ms 19180 KB Output is correct
91 Correct 529 ms 4944 KB Output is correct
92 Correct 602 ms 18456 KB Output is correct
93 Correct 502 ms 4876 KB Output is correct
94 Correct 508 ms 4992 KB Output is correct
95 Correct 513 ms 5156 KB Output is correct
96 Correct 628 ms 17564 KB Output is correct
97 Correct 580 ms 19164 KB Output is correct
98 Correct 620 ms 12116 KB Output is correct
99 Correct 767 ms 19388 KB Output is correct
100 Correct 424 ms 19492 KB Output is correct