Submission #881390

# Submission time Handle Problem Language Result Execution time Memory
881390 2023-12-01T08:17:47 Z 1L1YA Crossing (JOI21_crossing) C++17
100 / 100
526 ms 34200 KB
//1L1YA
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define Pb           push_back
#define dokme(x)     cout << x << endl, exit(0)
#define pii          pair<int,int>
#define F            first
#define S            second
#define endl         '\n'
#define sep          ' '
#define all(x)       x.begin(),x.end()
#define FastIO       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lc           id<<1
#define rc           lc|1

const ll mod=1e9+9;
const ll oo=4e18;
const int N=2e5+5;
const int lg=23;
const int base=111;

ll n,q,h[3][3][N],hsh[4][N],lz[N<<2],seg[N<<2];
string t,s[3][3];

ll Pow(ll a,ll b){
    ll ans=1;
    for(;b;b>>=1,a=a*a%mod)
        if(b&1)
            ans=ans*a%mod;
    return ans;
}

ll inv(ll x){
    return Pow(x,mod-2);
}

void change(string &s){
    for(int i=1;i<=n;i++)
        if(s[i]=='J')
            s[i]='b';
        else if(s[i]=='O')
            s[i]='c';
        else
            s[i]='d';
}

void shift(int id,int l,int r){
    if(!lz[id])
        return;
    int mid=l+r>>1;
    seg[lc]=hsh[lz[id]][mid-l];lz[lc]=lz[id];
    seg[rc]=hsh[lz[id]][r-mid];lz[rc]=lz[id];
    lz[id]=0;
}

void update(int ql,int qr,int val,int id=1,int l=1,int r=n+1){
    if(qr<=l || ql>=r)    return;
    if(ql<=l && r<=qr){
        seg[id]=hsh[val][r-l];
        lz[id]=val;
        return;
    }
    int mid=l+r>>1;
    shift(id,l,r);
    update(ql,qr,val,lc,l,mid);
    update(ql,qr,val,rc,mid,r);
    seg[id]=(seg[lc]*Pow(base,r-mid)%mod+seg[rc])%mod;
}

int main(){
    FastIO

    cin >> n >> s[0][0] >> s[0][1] >> s[0][2];
    s[0][0]='#'+s[0][0];s[0][1]='#'+s[0][1];s[0][2]='#'+s[0][2];
    change(s[0][0]);change(s[0][1]);change(s[0][2]);
    for(int k=1;k<3;k++){
        s[k][0]=s[k-1][0];s[k][1]=s[k-1][1];s[k][2]=s[k-1][2];
        for(int i=1;i<=n;i++){
            if(s[k-1][1][i]==s[k-1][2][i])
                s[k][0][i]=s[k-1][1][i];
            else{
                s[k][0][i]=(char)(((s[k-1][1][i]-'a')^(s[k-1][2][i]-'a'))+'a');
            }
            if(s[k-1][0][i]==s[k-1][2][i])
                s[k][1][i]=s[k-1][0][i];
            else{
                s[k][1][i]=(char)(((s[k-1][0][i]-'a')^(s[k-1][2][i]-'a'))+'a');
            }
            if(s[k-1][1][i]==s[k-1][0][i])
                s[k][2][i]=s[k-1][1][i];
            else{
                s[k][2][i]=(char)(((s[k-1][1][i]-'a')^(s[k-1][0][i]-'a'))+'a');
            }
        }
    }
    for(int j=1;j<=3;j++)
        for(int i=1;i<=n;i++)
            hsh[j][i]=(hsh[j][i-1]*base+j)%mod;
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            for(int k=1;k<=n;k++)
                h[i][j][k]=(h[i][j][k-1]*base+s[i][j][k]-'a')%mod;
    cin >> q >> t;
    bool fl=0;
    t='#'+t;
    change(t);
    for(int i=1;i<=n;i++)
        update(i,i+1,t[i]-'a');
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)    
            if(seg[1]==h[i][j][n])
                fl=1;
    if(fl)    cout << "Yes" << endl;
    else    cout << "No" << endl;
    while(q--){
        int l,r;
        char c;
        cin >> l >> r >> c;
        if(c=='J')    c='b';
        else if(c=='O')    c='c';
        else    c='d';
        update(l,r+1,c-'a');
        fl=0;
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                if(seg[1]==h[i][j][n])
                    fl=1;
        if(fl)    cout << "Yes" << endl;
        else    cout << "No" << endl;
    }

    return 0;
}

Compilation message

Main.cpp: In function 'void shift(int, int, int)':
Main.cpp:51:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |     int mid=l+r>>1;
      |             ~^~
Main.cpp: In function 'void update(int, int, int, int, int, int)':
Main.cpp:64:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |     int mid=l+r>>1;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1916 KB Output is correct
2 Correct 81 ms 2132 KB Output is correct
3 Correct 78 ms 2132 KB Output is correct
4 Correct 67 ms 2128 KB Output is correct
5 Correct 81 ms 2008 KB Output is correct
6 Correct 66 ms 1928 KB Output is correct
7 Correct 68 ms 2128 KB Output is correct
8 Correct 79 ms 1980 KB Output is correct
9 Correct 71 ms 2068 KB Output is correct
10 Correct 73 ms 2408 KB Output is correct
11 Correct 72 ms 1988 KB Output is correct
12 Correct 71 ms 2096 KB Output is correct
13 Correct 73 ms 2128 KB Output is correct
14 Correct 72 ms 2004 KB Output is correct
15 Correct 72 ms 2124 KB Output is correct
16 Correct 71 ms 2128 KB Output is correct
17 Correct 72 ms 2128 KB Output is correct
18 Correct 77 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1916 KB Output is correct
2 Correct 81 ms 2132 KB Output is correct
3 Correct 78 ms 2132 KB Output is correct
4 Correct 67 ms 2128 KB Output is correct
5 Correct 81 ms 2008 KB Output is correct
6 Correct 66 ms 1928 KB Output is correct
7 Correct 68 ms 2128 KB Output is correct
8 Correct 79 ms 1980 KB Output is correct
9 Correct 71 ms 2068 KB Output is correct
10 Correct 73 ms 2408 KB Output is correct
11 Correct 72 ms 1988 KB Output is correct
12 Correct 71 ms 2096 KB Output is correct
13 Correct 73 ms 2128 KB Output is correct
14 Correct 72 ms 2004 KB Output is correct
15 Correct 72 ms 2124 KB Output is correct
16 Correct 71 ms 2128 KB Output is correct
17 Correct 72 ms 2128 KB Output is correct
18 Correct 77 ms 2128 KB Output is correct
19 Correct 482 ms 32860 KB Output is correct
20 Correct 510 ms 32860 KB Output is correct
21 Correct 361 ms 33392 KB Output is correct
22 Correct 345 ms 32384 KB Output is correct
23 Correct 151 ms 8812 KB Output is correct
24 Correct 156 ms 8856 KB Output is correct
25 Correct 385 ms 34112 KB Output is correct
26 Correct 380 ms 34160 KB Output is correct
27 Correct 401 ms 33964 KB Output is correct
28 Correct 402 ms 34136 KB Output is correct
29 Correct 393 ms 33944 KB Output is correct
30 Correct 163 ms 8752 KB Output is correct
31 Correct 400 ms 33964 KB Output is correct
32 Correct 365 ms 33272 KB Output is correct
33 Correct 152 ms 8788 KB Output is correct
34 Correct 406 ms 33988 KB Output is correct
35 Correct 310 ms 30952 KB Output is correct
36 Correct 163 ms 9004 KB Output is correct
37 Correct 148 ms 8876 KB Output is correct
38 Correct 437 ms 33364 KB Output is correct
39 Correct 363 ms 32944 KB Output is correct
40 Correct 289 ms 26860 KB Output is correct
41 Correct 503 ms 34200 KB Output is correct
42 Correct 199 ms 32504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1916 KB Output is correct
2 Correct 81 ms 2132 KB Output is correct
3 Correct 78 ms 2132 KB Output is correct
4 Correct 67 ms 2128 KB Output is correct
5 Correct 81 ms 2008 KB Output is correct
6 Correct 66 ms 1928 KB Output is correct
7 Correct 68 ms 2128 KB Output is correct
8 Correct 79 ms 1980 KB Output is correct
9 Correct 71 ms 2068 KB Output is correct
10 Correct 73 ms 2408 KB Output is correct
11 Correct 72 ms 1988 KB Output is correct
12 Correct 71 ms 2096 KB Output is correct
13 Correct 73 ms 2128 KB Output is correct
14 Correct 72 ms 2004 KB Output is correct
15 Correct 72 ms 2124 KB Output is correct
16 Correct 71 ms 2128 KB Output is correct
17 Correct 72 ms 2128 KB Output is correct
18 Correct 77 ms 2128 KB Output is correct
19 Correct 76 ms 2388 KB Output is correct
20 Correct 81 ms 2388 KB Output is correct
21 Correct 71 ms 2548 KB Output is correct
22 Correct 67 ms 2412 KB Output is correct
23 Correct 76 ms 2640 KB Output is correct
24 Correct 68 ms 2384 KB Output is correct
25 Correct 72 ms 2588 KB Output is correct
26 Correct 64 ms 2384 KB Output is correct
27 Correct 71 ms 2616 KB Output is correct
28 Correct 70 ms 2384 KB Output is correct
29 Correct 85 ms 2480 KB Output is correct
30 Correct 65 ms 2388 KB Output is correct
31 Correct 71 ms 2640 KB Output is correct
32 Correct 69 ms 2640 KB Output is correct
33 Correct 77 ms 2620 KB Output is correct
34 Correct 63 ms 2468 KB Output is correct
35 Correct 71 ms 2644 KB Output is correct
36 Correct 72 ms 2504 KB Output is correct
37 Correct 72 ms 2644 KB Output is correct
38 Correct 78 ms 2552 KB Output is correct
39 Correct 71 ms 2496 KB Output is correct
40 Correct 72 ms 2640 KB Output is correct
41 Correct 74 ms 2716 KB Output is correct
42 Correct 72 ms 2584 KB Output is correct
43 Correct 68 ms 2388 KB Output is correct
44 Correct 72 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1916 KB Output is correct
2 Correct 81 ms 2132 KB Output is correct
3 Correct 78 ms 2132 KB Output is correct
4 Correct 67 ms 2128 KB Output is correct
5 Correct 81 ms 2008 KB Output is correct
6 Correct 66 ms 1928 KB Output is correct
7 Correct 68 ms 2128 KB Output is correct
8 Correct 79 ms 1980 KB Output is correct
9 Correct 71 ms 2068 KB Output is correct
10 Correct 73 ms 2408 KB Output is correct
11 Correct 72 ms 1988 KB Output is correct
12 Correct 71 ms 2096 KB Output is correct
13 Correct 73 ms 2128 KB Output is correct
14 Correct 72 ms 2004 KB Output is correct
15 Correct 72 ms 2124 KB Output is correct
16 Correct 71 ms 2128 KB Output is correct
17 Correct 72 ms 2128 KB Output is correct
18 Correct 77 ms 2128 KB Output is correct
19 Correct 482 ms 32860 KB Output is correct
20 Correct 510 ms 32860 KB Output is correct
21 Correct 361 ms 33392 KB Output is correct
22 Correct 345 ms 32384 KB Output is correct
23 Correct 151 ms 8812 KB Output is correct
24 Correct 156 ms 8856 KB Output is correct
25 Correct 385 ms 34112 KB Output is correct
26 Correct 380 ms 34160 KB Output is correct
27 Correct 401 ms 33964 KB Output is correct
28 Correct 402 ms 34136 KB Output is correct
29 Correct 393 ms 33944 KB Output is correct
30 Correct 163 ms 8752 KB Output is correct
31 Correct 400 ms 33964 KB Output is correct
32 Correct 365 ms 33272 KB Output is correct
33 Correct 152 ms 8788 KB Output is correct
34 Correct 406 ms 33988 KB Output is correct
35 Correct 310 ms 30952 KB Output is correct
36 Correct 163 ms 9004 KB Output is correct
37 Correct 148 ms 8876 KB Output is correct
38 Correct 437 ms 33364 KB Output is correct
39 Correct 363 ms 32944 KB Output is correct
40 Correct 289 ms 26860 KB Output is correct
41 Correct 503 ms 34200 KB Output is correct
42 Correct 199 ms 32504 KB Output is correct
43 Correct 76 ms 2388 KB Output is correct
44 Correct 81 ms 2388 KB Output is correct
45 Correct 71 ms 2548 KB Output is correct
46 Correct 67 ms 2412 KB Output is correct
47 Correct 76 ms 2640 KB Output is correct
48 Correct 68 ms 2384 KB Output is correct
49 Correct 72 ms 2588 KB Output is correct
50 Correct 64 ms 2384 KB Output is correct
51 Correct 71 ms 2616 KB Output is correct
52 Correct 70 ms 2384 KB Output is correct
53 Correct 85 ms 2480 KB Output is correct
54 Correct 65 ms 2388 KB Output is correct
55 Correct 71 ms 2640 KB Output is correct
56 Correct 69 ms 2640 KB Output is correct
57 Correct 77 ms 2620 KB Output is correct
58 Correct 63 ms 2468 KB Output is correct
59 Correct 71 ms 2644 KB Output is correct
60 Correct 72 ms 2504 KB Output is correct
61 Correct 72 ms 2644 KB Output is correct
62 Correct 78 ms 2552 KB Output is correct
63 Correct 71 ms 2496 KB Output is correct
64 Correct 72 ms 2640 KB Output is correct
65 Correct 74 ms 2716 KB Output is correct
66 Correct 72 ms 2584 KB Output is correct
67 Correct 68 ms 2388 KB Output is correct
68 Correct 72 ms 2640 KB Output is correct
69 Correct 395 ms 31824 KB Output is correct
70 Correct 489 ms 33260 KB Output is correct
71 Correct 150 ms 8732 KB Output is correct
72 Correct 152 ms 8860 KB Output is correct
73 Correct 152 ms 8788 KB Output is correct
74 Correct 331 ms 31924 KB Output is correct
75 Correct 157 ms 8860 KB Output is correct
76 Correct 384 ms 34132 KB Output is correct
77 Correct 341 ms 32120 KB Output is correct
78 Correct 155 ms 8788 KB Output is correct
79 Correct 151 ms 8860 KB Output is correct
80 Correct 297 ms 30908 KB Output is correct
81 Correct 170 ms 9080 KB Output is correct
82 Correct 378 ms 34112 KB Output is correct
83 Correct 357 ms 33436 KB Output is correct
84 Correct 152 ms 8760 KB Output is correct
85 Correct 157 ms 8788 KB Output is correct
86 Correct 349 ms 31348 KB Output is correct
87 Correct 402 ms 33964 KB Output is correct
88 Correct 162 ms 8784 KB Output is correct
89 Correct 349 ms 32720 KB Output is correct
90 Correct 399 ms 34176 KB Output is correct
91 Correct 179 ms 8788 KB Output is correct
92 Correct 311 ms 31264 KB Output is correct
93 Correct 151 ms 8876 KB Output is correct
94 Correct 150 ms 8784 KB Output is correct
95 Correct 163 ms 8840 KB Output is correct
96 Correct 430 ms 33100 KB Output is correct
97 Correct 372 ms 33008 KB Output is correct
98 Correct 289 ms 26460 KB Output is correct
99 Correct 526 ms 34136 KB Output is correct
100 Correct 203 ms 32428 KB Output is correct