Submission #881315

# Submission time Handle Problem Language Result Execution time Memory
881315 2023-12-01T06:22:48 Z Alish Crossing (JOI21_crossing) C++17
100 / 100
284 ms 26440 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long int	ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;


#define F		        first
#define S		        second
#define pb		        push_back
#define endl            '\n'
#define Mp		        make_pair
#define all(x)          x.begin(), x.end()
#define debug(x)        cerr << #x << " = " << x << endl;
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("connect.in" , "r" , stdin) ; freopen("connect.out" , "w" , stdout);


ll mod = 1000696969;


const int N = 2e5+23;
ll base=737;

ll seg[4*N], lpz[4*N];
string s[3];
ll pw[N];
int n, q;
ll temp[N];
ll temphsh[N];
set<ll> hsh;

string t;

ll blo[3][N];


int get(char c){
    if(c=='I') return 0;
    if(c=='O') return 1;
    return 2;
}



void Shift(int l, int r, int ind){
    if(r-l==1)return;
    if(lpz[ind]==-1) return;
    int mid=(r+l)>>1;

    lpz[2*ind+1]=lpz[ind];
    lpz[2*ind+2]=lpz[ind];

    seg[2*ind+1]=blo[lpz[ind]][mid-l-1];
    seg[2*ind+2]=blo[lpz[ind]][r-mid-1];
    lpz[ind]=-1;

}

void upd(int lx, int rx,  int v, int l=0, int r=n, int ind=0){
    Shift(l, r, ind);
    if(lx>=r || rx<=l) return ;
    if(lx<=l && rx>=r){
        seg[ind]=blo[v][r-l-1];
        lpz[ind]=v;
        return;
    }
    int mid=(r+l)>>1;
    upd(lx, rx, v, l, mid, 2*ind+1); upd(lx, rx, v, mid, r, 2*ind+2);
    seg[ind]=(seg[2*ind+1]+seg[2*ind+2]*pw[mid-l]%mod)%mod;
}

void build(int l=0, int r=n, int ind=0){

    lpz[ind]=-1;
    if(r-l==1){
        seg[ind]=temp[l];
        return;
    }
    int mid=(r+l)>>1;
    build(l, mid, 2*ind+1); build(mid, r, 2*ind+2);
    seg[ind]=(seg[2*ind+1]+seg[2*ind+2]*pw[mid-l]%mod)%mod;


}

void getC(int i, int l=0, int r=n, int ind=0){
    Shift(l, r, ind);
    if(r-l==1){
        cout<<seg[ind];
        return;
    }
    int mid=(r+l)>>1;
    if(i<mid) getC(i, l, mid, 2*ind+1);
    else getC(i, mid, r, 2*ind+2);
}

int main()
{
    fast_io
    pw[0]=1;
    for (int i=1; i<N; i++)pw[i]=pw[i-1]*base%mod;
    for (int k=0; k<3; k++)for (int i=0; i<N; i++){
        blo[k][i]=k*pw[i]%mod;
        if(i) blo[k][i]=(blo[k][i]+blo[k][i-1])%mod;
    }
    cin>>n;
    for (int i=0; i<3; i++) cin>>s[i];

    for(int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            for (int k=0; k<3; k++){

                for (int g=0; g<n; g++){
                    ll a=(3-(3-get(s[i][g])-get(s[j][g])+6)%3-get(s[k][g])+6)%3;
                    temphsh[g]=a*pw[g]%mod;
                    if(g) temphsh[g]=(temphsh[g-1]+temphsh[g])%mod;
                }
                hsh.insert(temphsh[n-1]);
            }
        }
    }

    cin>>q;
    cin>>t;
    for (int i=0; i<n; i++)temp[i]=get(t[i]);

    build();

    if(hsh.find(seg[0])!=hsh.end()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    while(q--){
        int l, r;
        char c;
        cin>>l>>r>>c;
        l--;
        int t=get(c);
        upd(l, r, t);
        if(hsh.find(seg[0])!=hsh.end()) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


}
# Verdict Execution time Memory Grader output
1 Correct 71 ms 13392 KB Output is correct
2 Correct 81 ms 13464 KB Output is correct
3 Correct 82 ms 13324 KB Output is correct
4 Correct 71 ms 13392 KB Output is correct
5 Correct 70 ms 13456 KB Output is correct
6 Correct 70 ms 13248 KB Output is correct
7 Correct 70 ms 13436 KB Output is correct
8 Correct 77 ms 13420 KB Output is correct
9 Correct 73 ms 13392 KB Output is correct
10 Correct 76 ms 13396 KB Output is correct
11 Correct 76 ms 13652 KB Output is correct
12 Correct 73 ms 13284 KB Output is correct
13 Correct 73 ms 13424 KB Output is correct
14 Correct 74 ms 13392 KB Output is correct
15 Correct 74 ms 13396 KB Output is correct
16 Correct 74 ms 13396 KB Output is correct
17 Correct 76 ms 13392 KB Output is correct
18 Correct 74 ms 13392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 13392 KB Output is correct
2 Correct 81 ms 13464 KB Output is correct
3 Correct 82 ms 13324 KB Output is correct
4 Correct 71 ms 13392 KB Output is correct
5 Correct 70 ms 13456 KB Output is correct
6 Correct 70 ms 13248 KB Output is correct
7 Correct 70 ms 13436 KB Output is correct
8 Correct 77 ms 13420 KB Output is correct
9 Correct 73 ms 13392 KB Output is correct
10 Correct 76 ms 13396 KB Output is correct
11 Correct 76 ms 13652 KB Output is correct
12 Correct 73 ms 13284 KB Output is correct
13 Correct 73 ms 13424 KB Output is correct
14 Correct 74 ms 13392 KB Output is correct
15 Correct 74 ms 13396 KB Output is correct
16 Correct 74 ms 13396 KB Output is correct
17 Correct 76 ms 13392 KB Output is correct
18 Correct 74 ms 13392 KB Output is correct
19 Correct 264 ms 22740 KB Output is correct
20 Correct 259 ms 22936 KB Output is correct
21 Correct 195 ms 24400 KB Output is correct
22 Correct 181 ms 24072 KB Output is correct
23 Correct 121 ms 14900 KB Output is correct
24 Correct 122 ms 15032 KB Output is correct
25 Correct 201 ms 24572 KB Output is correct
26 Correct 218 ms 24480 KB Output is correct
27 Correct 234 ms 25160 KB Output is correct
28 Correct 220 ms 24556 KB Output is correct
29 Correct 217 ms 24704 KB Output is correct
30 Correct 133 ms 15444 KB Output is correct
31 Correct 219 ms 24484 KB Output is correct
32 Correct 225 ms 24596 KB Output is correct
33 Correct 122 ms 15120 KB Output is correct
34 Correct 221 ms 24480 KB Output is correct
35 Correct 174 ms 24176 KB Output is correct
36 Correct 120 ms 15036 KB Output is correct
37 Correct 121 ms 14896 KB Output is correct
38 Correct 249 ms 24636 KB Output is correct
39 Correct 186 ms 24484 KB Output is correct
40 Correct 175 ms 19840 KB Output is correct
41 Correct 279 ms 25336 KB Output is correct
42 Correct 97 ms 24472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 13392 KB Output is correct
2 Correct 81 ms 13464 KB Output is correct
3 Correct 82 ms 13324 KB Output is correct
4 Correct 71 ms 13392 KB Output is correct
5 Correct 70 ms 13456 KB Output is correct
6 Correct 70 ms 13248 KB Output is correct
7 Correct 70 ms 13436 KB Output is correct
8 Correct 77 ms 13420 KB Output is correct
9 Correct 73 ms 13392 KB Output is correct
10 Correct 76 ms 13396 KB Output is correct
11 Correct 76 ms 13652 KB Output is correct
12 Correct 73 ms 13284 KB Output is correct
13 Correct 73 ms 13424 KB Output is correct
14 Correct 74 ms 13392 KB Output is correct
15 Correct 74 ms 13396 KB Output is correct
16 Correct 74 ms 13396 KB Output is correct
17 Correct 76 ms 13392 KB Output is correct
18 Correct 74 ms 13392 KB Output is correct
19 Correct 80 ms 13392 KB Output is correct
20 Correct 86 ms 13392 KB Output is correct
21 Correct 82 ms 13648 KB Output is correct
22 Correct 72 ms 14764 KB Output is correct
23 Correct 74 ms 14932 KB Output is correct
24 Correct 73 ms 14932 KB Output is correct
25 Correct 79 ms 14928 KB Output is correct
26 Correct 69 ms 14920 KB Output is correct
27 Correct 76 ms 14928 KB Output is correct
28 Correct 83 ms 14676 KB Output is correct
29 Correct 75 ms 14832 KB Output is correct
30 Correct 67 ms 14672 KB Output is correct
31 Correct 77 ms 14928 KB Output is correct
32 Correct 77 ms 14928 KB Output is correct
33 Correct 77 ms 14952 KB Output is correct
34 Correct 70 ms 14672 KB Output is correct
35 Correct 81 ms 14912 KB Output is correct
36 Correct 78 ms 14932 KB Output is correct
37 Correct 78 ms 14936 KB Output is correct
38 Correct 82 ms 15000 KB Output is correct
39 Correct 78 ms 15024 KB Output is correct
40 Correct 78 ms 14836 KB Output is correct
41 Correct 80 ms 14932 KB Output is correct
42 Correct 79 ms 14928 KB Output is correct
43 Correct 74 ms 14860 KB Output is correct
44 Correct 77 ms 14872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 13392 KB Output is correct
2 Correct 81 ms 13464 KB Output is correct
3 Correct 82 ms 13324 KB Output is correct
4 Correct 71 ms 13392 KB Output is correct
5 Correct 70 ms 13456 KB Output is correct
6 Correct 70 ms 13248 KB Output is correct
7 Correct 70 ms 13436 KB Output is correct
8 Correct 77 ms 13420 KB Output is correct
9 Correct 73 ms 13392 KB Output is correct
10 Correct 76 ms 13396 KB Output is correct
11 Correct 76 ms 13652 KB Output is correct
12 Correct 73 ms 13284 KB Output is correct
13 Correct 73 ms 13424 KB Output is correct
14 Correct 74 ms 13392 KB Output is correct
15 Correct 74 ms 13396 KB Output is correct
16 Correct 74 ms 13396 KB Output is correct
17 Correct 76 ms 13392 KB Output is correct
18 Correct 74 ms 13392 KB Output is correct
19 Correct 264 ms 22740 KB Output is correct
20 Correct 259 ms 22936 KB Output is correct
21 Correct 195 ms 24400 KB Output is correct
22 Correct 181 ms 24072 KB Output is correct
23 Correct 121 ms 14900 KB Output is correct
24 Correct 122 ms 15032 KB Output is correct
25 Correct 201 ms 24572 KB Output is correct
26 Correct 218 ms 24480 KB Output is correct
27 Correct 234 ms 25160 KB Output is correct
28 Correct 220 ms 24556 KB Output is correct
29 Correct 217 ms 24704 KB Output is correct
30 Correct 133 ms 15444 KB Output is correct
31 Correct 219 ms 24484 KB Output is correct
32 Correct 225 ms 24596 KB Output is correct
33 Correct 122 ms 15120 KB Output is correct
34 Correct 221 ms 24480 KB Output is correct
35 Correct 174 ms 24176 KB Output is correct
36 Correct 120 ms 15036 KB Output is correct
37 Correct 121 ms 14896 KB Output is correct
38 Correct 249 ms 24636 KB Output is correct
39 Correct 186 ms 24484 KB Output is correct
40 Correct 175 ms 19840 KB Output is correct
41 Correct 279 ms 25336 KB Output is correct
42 Correct 97 ms 24472 KB Output is correct
43 Correct 80 ms 13392 KB Output is correct
44 Correct 86 ms 13392 KB Output is correct
45 Correct 82 ms 13648 KB Output is correct
46 Correct 72 ms 14764 KB Output is correct
47 Correct 74 ms 14932 KB Output is correct
48 Correct 73 ms 14932 KB Output is correct
49 Correct 79 ms 14928 KB Output is correct
50 Correct 69 ms 14920 KB Output is correct
51 Correct 76 ms 14928 KB Output is correct
52 Correct 83 ms 14676 KB Output is correct
53 Correct 75 ms 14832 KB Output is correct
54 Correct 67 ms 14672 KB Output is correct
55 Correct 77 ms 14928 KB Output is correct
56 Correct 77 ms 14928 KB Output is correct
57 Correct 77 ms 14952 KB Output is correct
58 Correct 70 ms 14672 KB Output is correct
59 Correct 81 ms 14912 KB Output is correct
60 Correct 78 ms 14932 KB Output is correct
61 Correct 78 ms 14936 KB Output is correct
62 Correct 82 ms 15000 KB Output is correct
63 Correct 78 ms 15024 KB Output is correct
64 Correct 78 ms 14836 KB Output is correct
65 Correct 80 ms 14932 KB Output is correct
66 Correct 79 ms 14928 KB Output is correct
67 Correct 74 ms 14860 KB Output is correct
68 Correct 77 ms 14872 KB Output is correct
69 Correct 235 ms 25532 KB Output is correct
70 Correct 272 ms 26272 KB Output is correct
71 Correct 122 ms 15872 KB Output is correct
72 Correct 136 ms 15944 KB Output is correct
73 Correct 123 ms 15952 KB Output is correct
74 Correct 188 ms 25700 KB Output is correct
75 Correct 123 ms 15700 KB Output is correct
76 Correct 204 ms 26264 KB Output is correct
77 Correct 187 ms 25736 KB Output is correct
78 Correct 126 ms 15696 KB Output is correct
79 Correct 128 ms 15720 KB Output is correct
80 Correct 188 ms 25356 KB Output is correct
81 Correct 124 ms 15768 KB Output is correct
82 Correct 209 ms 26172 KB Output is correct
83 Correct 201 ms 25916 KB Output is correct
84 Correct 124 ms 15700 KB Output is correct
85 Correct 123 ms 15836 KB Output is correct
86 Correct 209 ms 25624 KB Output is correct
87 Correct 228 ms 26324 KB Output is correct
88 Correct 132 ms 15920 KB Output is correct
89 Correct 208 ms 25852 KB Output is correct
90 Correct 226 ms 26268 KB Output is correct
91 Correct 134 ms 15704 KB Output is correct
92 Correct 185 ms 25504 KB Output is correct
93 Correct 125 ms 15772 KB Output is correct
94 Correct 124 ms 15804 KB Output is correct
95 Correct 123 ms 15924 KB Output is correct
96 Correct 230 ms 26084 KB Output is correct
97 Correct 188 ms 26276 KB Output is correct
98 Correct 185 ms 21376 KB Output is correct
99 Correct 284 ms 26440 KB Output is correct
100 Correct 97 ms 25764 KB Output is correct