답안 #547452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547452 2022-04-10T18:22:19 Z codr0 Crossing (JOI21_crossing) C++14
100 / 100
414 ms 38620 KB
// Code by Parsa Eslami
     
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define bit(i,j) ((j>>i)&1)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define err(x) cerr<<#x<<" : "<<x<<'\n'
#define MOD(x) if(x>=M) x-=M; if(x<0) x+=M;

using namespace std;
	int to(char x0){
		if(x0=='J') return 0;
		if(x0=='O') return 1;
		return 2;
	}
struct node{
	int sz;
	int num;
};
const int BASE=3;
const int MOD=1000696969;
const int N=2e5+4;
int pw[N],n;
int ps_pw[N];
vector<int> hsh;
node seg[4*N];
int lazy[4*N];
bool lzy[4*N];
struct X{
	int a[N];
	void set(string x0){
		FOR(i,0,n-1){
			a[i]=to(x0[i]);
		}
	}
	int get_hsh(){
		int rt=0;
		FOR(i,0,n-1) rt=(rt+a[i]*pw[i])%MOD;
		rt=(rt+MOD)%MOD;
		return rt;
	}
};
	X merge(X a,X b){
		X rt;
		FOR(i,0,n-1){
			rt.a[i]=(9-a.a[i]-b.a[i])%3;
		}
		return rt;
	}

	void build(int id,int l,int r){
		seg[id].sz=r-l;
		seg[id].num=0;
		if(l+1==r) return;
		int mid=(r+l)/2;
		build(2*id,l,mid);
		build(2*id+1,mid,r);
	}

	node merge(node a,node b){
		node rt;
		rt.sz=a.sz+b.sz;
		rt.num=(a.num+pw[a.sz]*b.num)%MOD;
		return rt;
	}

	void shift(int id){
		if(!lzy[id]) return;
		lzy[id]=0;
		lzy[2*id]=1;
		lzy[2*id+1]=1;
		lazy[2*id]=lazy[id];
		lazy[2*id+1]=lazy[id];
		seg[2*id].num=(ps_pw[seg[2*id].sz-1]*lazy[id])%MOD;
		seg[2*id+1].num=(ps_pw[seg[2*id+1].sz-1]*lazy[id])%MOD;
	}

	void upd(int id,int l,int r,int st,int en,int X){
		if(st>=r||en<=l) return;
		if(st<=l&&en>=r){
			seg[id].num=(ps_pw[seg[id].sz-1]*X)%MOD;
			lzy[id]=1;
			lazy[id]=X;
			return;
		}
		shift(id);
		int mid=(r+l)/2;
		upd(2*id,l,mid,st,en,X);
		upd(2*id+1,mid,r,st,en,X);
		seg[id]=merge(seg[2*id],seg[2*id+1]);
	}
	
	void check(){
		int Y=(seg[1].num+MOD)%MOD;
		for(int u0:hsh){
			u0=(u0+MOD)%MOD;
			if(u0==Y){
				cout<<"Yes\n";
				return;
			}
		}
		cout<<"No\n";
		return;
	}

	int32_t main(){
	ios_base::sync_with_stdio(0); cin.tie(0);	

	pw[0]=1; FOR(i,1,N-1) pw[i]=(pw[i-1]*BASE)%MOD;
	ps_pw[0]=1; FOR(i,1,N-1) ps_pw[i]=(ps_pw[i-1]+pw[i])%MOD;
	cin>>n;
	build(1,1,n+1);
	string x0;
	X A,B,C;
	cin>>x0;
	A.set(x0);
	cin>>x0;
	B.set(x0);
	cin>>x0;
	C.set(x0);
	X AB,BC,AC;
	AB=merge(A,B);
	AC=merge(A,C);
	BC=merge(B,C);
	X _C,_A,_B;
	_A=merge(A,BC);
	_B=merge(B,AC);
	_C=merge(C,AB);

	hsh.pb(A.get_hsh());
	hsh.pb(B.get_hsh());
	hsh.pb(C.get_hsh());
	hsh.pb(AB.get_hsh());
	hsh.pb(AC.get_hsh());
	hsh.pb(BC.get_hsh());
	hsh.pb(_A.get_hsh());
	hsh.pb(_B.get_hsh());
	hsh.pb(_C.get_hsh());

	int q; cin>>q;
	string W;
	cin>>W;
	FOR(i,0,n-1){
		upd(1,1,n+1,i+1,i+2,to(W[i]));
	}
	check();

	FOR(i,1,q){
		int l,r;
		char x0;
		cin>>l>>r>>x0;
		upd(1,1,n+1,l,r+1,to(x0));
		check();
	}




	return 0;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 22660 KB Output is correct
2 Correct 85 ms 22732 KB Output is correct
3 Correct 86 ms 22608 KB Output is correct
4 Correct 76 ms 22628 KB Output is correct
5 Correct 78 ms 22684 KB Output is correct
6 Correct 70 ms 22632 KB Output is correct
7 Correct 88 ms 22776 KB Output is correct
8 Correct 79 ms 22768 KB Output is correct
9 Correct 80 ms 22752 KB Output is correct
10 Correct 79 ms 22724 KB Output is correct
11 Correct 76 ms 22728 KB Output is correct
12 Correct 79 ms 22712 KB Output is correct
13 Correct 83 ms 22732 KB Output is correct
14 Correct 75 ms 22788 KB Output is correct
15 Correct 75 ms 22720 KB Output is correct
16 Correct 82 ms 22732 KB Output is correct
17 Correct 85 ms 22716 KB Output is correct
18 Correct 78 ms 22732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 22660 KB Output is correct
2 Correct 85 ms 22732 KB Output is correct
3 Correct 86 ms 22608 KB Output is correct
4 Correct 76 ms 22628 KB Output is correct
5 Correct 78 ms 22684 KB Output is correct
6 Correct 70 ms 22632 KB Output is correct
7 Correct 88 ms 22776 KB Output is correct
8 Correct 79 ms 22768 KB Output is correct
9 Correct 80 ms 22752 KB Output is correct
10 Correct 79 ms 22724 KB Output is correct
11 Correct 76 ms 22728 KB Output is correct
12 Correct 79 ms 22712 KB Output is correct
13 Correct 83 ms 22732 KB Output is correct
14 Correct 75 ms 22788 KB Output is correct
15 Correct 75 ms 22720 KB Output is correct
16 Correct 82 ms 22732 KB Output is correct
17 Correct 85 ms 22716 KB Output is correct
18 Correct 78 ms 22732 KB Output is correct
19 Correct 284 ms 38400 KB Output is correct
20 Correct 275 ms 37396 KB Output is correct
21 Correct 215 ms 38100 KB Output is correct
22 Correct 230 ms 37960 KB Output is correct
23 Correct 114 ms 24356 KB Output is correct
24 Correct 124 ms 24340 KB Output is correct
25 Correct 244 ms 38476 KB Output is correct
26 Correct 242 ms 38436 KB Output is correct
27 Correct 266 ms 38324 KB Output is correct
28 Correct 243 ms 38380 KB Output is correct
29 Correct 223 ms 38240 KB Output is correct
30 Correct 138 ms 24532 KB Output is correct
31 Correct 267 ms 38380 KB Output is correct
32 Correct 282 ms 38200 KB Output is correct
33 Correct 121 ms 24444 KB Output is correct
34 Correct 287 ms 38416 KB Output is correct
35 Correct 222 ms 37784 KB Output is correct
36 Correct 121 ms 24396 KB Output is correct
37 Correct 120 ms 24356 KB Output is correct
38 Correct 283 ms 37296 KB Output is correct
39 Correct 224 ms 37288 KB Output is correct
40 Correct 270 ms 31484 KB Output is correct
41 Correct 414 ms 38556 KB Output is correct
42 Correct 125 ms 36608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 22660 KB Output is correct
2 Correct 85 ms 22732 KB Output is correct
3 Correct 86 ms 22608 KB Output is correct
4 Correct 76 ms 22628 KB Output is correct
5 Correct 78 ms 22684 KB Output is correct
6 Correct 70 ms 22632 KB Output is correct
7 Correct 88 ms 22776 KB Output is correct
8 Correct 79 ms 22768 KB Output is correct
9 Correct 80 ms 22752 KB Output is correct
10 Correct 79 ms 22724 KB Output is correct
11 Correct 76 ms 22728 KB Output is correct
12 Correct 79 ms 22712 KB Output is correct
13 Correct 83 ms 22732 KB Output is correct
14 Correct 75 ms 22788 KB Output is correct
15 Correct 75 ms 22720 KB Output is correct
16 Correct 82 ms 22732 KB Output is correct
17 Correct 85 ms 22716 KB Output is correct
18 Correct 78 ms 22732 KB Output is correct
19 Correct 81 ms 22604 KB Output is correct
20 Correct 82 ms 22648 KB Output is correct
21 Correct 90 ms 22788 KB Output is correct
22 Correct 68 ms 22540 KB Output is correct
23 Correct 78 ms 22860 KB Output is correct
24 Correct 81 ms 22668 KB Output is correct
25 Correct 77 ms 22728 KB Output is correct
26 Correct 72 ms 22696 KB Output is correct
27 Correct 82 ms 22740 KB Output is correct
28 Correct 76 ms 22612 KB Output is correct
29 Correct 86 ms 22792 KB Output is correct
30 Correct 70 ms 22560 KB Output is correct
31 Correct 79 ms 22780 KB Output is correct
32 Correct 79 ms 22744 KB Output is correct
33 Correct 80 ms 22712 KB Output is correct
34 Correct 72 ms 22584 KB Output is correct
35 Correct 77 ms 22736 KB Output is correct
36 Correct 75 ms 22748 KB Output is correct
37 Correct 79 ms 22808 KB Output is correct
38 Correct 79 ms 22696 KB Output is correct
39 Correct 77 ms 22732 KB Output is correct
40 Correct 76 ms 22776 KB Output is correct
41 Correct 84 ms 22732 KB Output is correct
42 Correct 84 ms 22744 KB Output is correct
43 Correct 74 ms 22732 KB Output is correct
44 Correct 82 ms 22800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 22660 KB Output is correct
2 Correct 85 ms 22732 KB Output is correct
3 Correct 86 ms 22608 KB Output is correct
4 Correct 76 ms 22628 KB Output is correct
5 Correct 78 ms 22684 KB Output is correct
6 Correct 70 ms 22632 KB Output is correct
7 Correct 88 ms 22776 KB Output is correct
8 Correct 79 ms 22768 KB Output is correct
9 Correct 80 ms 22752 KB Output is correct
10 Correct 79 ms 22724 KB Output is correct
11 Correct 76 ms 22728 KB Output is correct
12 Correct 79 ms 22712 KB Output is correct
13 Correct 83 ms 22732 KB Output is correct
14 Correct 75 ms 22788 KB Output is correct
15 Correct 75 ms 22720 KB Output is correct
16 Correct 82 ms 22732 KB Output is correct
17 Correct 85 ms 22716 KB Output is correct
18 Correct 78 ms 22732 KB Output is correct
19 Correct 284 ms 38400 KB Output is correct
20 Correct 275 ms 37396 KB Output is correct
21 Correct 215 ms 38100 KB Output is correct
22 Correct 230 ms 37960 KB Output is correct
23 Correct 114 ms 24356 KB Output is correct
24 Correct 124 ms 24340 KB Output is correct
25 Correct 244 ms 38476 KB Output is correct
26 Correct 242 ms 38436 KB Output is correct
27 Correct 266 ms 38324 KB Output is correct
28 Correct 243 ms 38380 KB Output is correct
29 Correct 223 ms 38240 KB Output is correct
30 Correct 138 ms 24532 KB Output is correct
31 Correct 267 ms 38380 KB Output is correct
32 Correct 282 ms 38200 KB Output is correct
33 Correct 121 ms 24444 KB Output is correct
34 Correct 287 ms 38416 KB Output is correct
35 Correct 222 ms 37784 KB Output is correct
36 Correct 121 ms 24396 KB Output is correct
37 Correct 120 ms 24356 KB Output is correct
38 Correct 283 ms 37296 KB Output is correct
39 Correct 224 ms 37288 KB Output is correct
40 Correct 270 ms 31484 KB Output is correct
41 Correct 414 ms 38556 KB Output is correct
42 Correct 125 ms 36608 KB Output is correct
43 Correct 81 ms 22604 KB Output is correct
44 Correct 82 ms 22648 KB Output is correct
45 Correct 90 ms 22788 KB Output is correct
46 Correct 68 ms 22540 KB Output is correct
47 Correct 78 ms 22860 KB Output is correct
48 Correct 81 ms 22668 KB Output is correct
49 Correct 77 ms 22728 KB Output is correct
50 Correct 72 ms 22696 KB Output is correct
51 Correct 82 ms 22740 KB Output is correct
52 Correct 76 ms 22612 KB Output is correct
53 Correct 86 ms 22792 KB Output is correct
54 Correct 70 ms 22560 KB Output is correct
55 Correct 79 ms 22780 KB Output is correct
56 Correct 79 ms 22744 KB Output is correct
57 Correct 80 ms 22712 KB Output is correct
58 Correct 72 ms 22584 KB Output is correct
59 Correct 77 ms 22736 KB Output is correct
60 Correct 75 ms 22748 KB Output is correct
61 Correct 79 ms 22808 KB Output is correct
62 Correct 79 ms 22696 KB Output is correct
63 Correct 77 ms 22732 KB Output is correct
64 Correct 76 ms 22776 KB Output is correct
65 Correct 84 ms 22732 KB Output is correct
66 Correct 84 ms 22744 KB Output is correct
67 Correct 74 ms 22732 KB Output is correct
68 Correct 82 ms 22800 KB Output is correct
69 Correct 271 ms 37856 KB Output is correct
70 Correct 260 ms 37432 KB Output is correct
71 Correct 118 ms 24388 KB Output is correct
72 Correct 123 ms 24472 KB Output is correct
73 Correct 116 ms 24484 KB Output is correct
74 Correct 215 ms 37824 KB Output is correct
75 Correct 117 ms 24528 KB Output is correct
76 Correct 256 ms 38388 KB Output is correct
77 Correct 222 ms 37976 KB Output is correct
78 Correct 119 ms 24508 KB Output is correct
79 Correct 124 ms 24476 KB Output is correct
80 Correct 184 ms 37704 KB Output is correct
81 Correct 115 ms 24392 KB Output is correct
82 Correct 269 ms 38516 KB Output is correct
83 Correct 226 ms 38312 KB Output is correct
84 Correct 117 ms 24384 KB Output is correct
85 Correct 111 ms 24396 KB Output is correct
86 Correct 207 ms 37780 KB Output is correct
87 Correct 260 ms 38404 KB Output is correct
88 Correct 123 ms 24352 KB Output is correct
89 Correct 245 ms 37928 KB Output is correct
90 Correct 255 ms 38364 KB Output is correct
91 Correct 126 ms 24344 KB Output is correct
92 Correct 190 ms 37780 KB Output is correct
93 Correct 113 ms 24396 KB Output is correct
94 Correct 113 ms 24324 KB Output is correct
95 Correct 113 ms 24396 KB Output is correct
96 Correct 225 ms 37320 KB Output is correct
97 Correct 198 ms 37268 KB Output is correct
98 Correct 191 ms 31348 KB Output is correct
99 Correct 300 ms 38620 KB Output is correct
100 Correct 118 ms 36692 KB Output is correct