Submission #507634

# Submission time Handle Problem Language Result Execution time Memory
507634 2022-01-12T21:10:24 Z nichke Crossing (JOI21_crossing) C++14
100 / 100
566 ms 26732 KB
// I may fail a thousand times
// But there is no giving up
// IOI - here I come
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int BASE=3;
const int MOD1=(int)1e9+9;
const int MOD2=(int)1e9+6;
string s;
map<char,int> mp;
int lazy[(int)8e5+5];
int tree[(int)8e5+5][2];
int pref[(int)2e5+5][2];
string calc(string x,string y){
	string ret="";
	int sz=(int)x.length();
	for(int i=0;i<sz;i++){
		if(x[i]==y[i])ret+=x[i];
		else{
			char a=x[i];
			char b=y[i];
			if(a>b)swap(a,b);
			if(a=='I'&&b=='J')ret+='O';
			if(a=='I'&&b=='O')ret+='J';
			if(a=='J'&&b=='O')ret+='I';
		}
	}
	return ret;
}
int mul(int a,int b,int MOD){
	int ret=(a*b)%MOD;
	if(ret<0)ret+=MOD;
	return ret;
}
int add(int a,int b,int MOD){
	int ret=(a+b)%MOD;
	if(ret<0)ret+=MOD;
	return ret;
}
void build(int v,int l,int r){
	if(l==r){
		tree[v][0]=mul(mp[s[l-1]],add(pref[r][0],-pref[l-1][0],MOD1),MOD1);
		tree[v][1]=mul(mp[s[l-1]],add(pref[r][1],-pref[l-1][1],MOD2),MOD2);
		return;
	}
	int m=(l+r)/2;
	build(2*v,l,m);
	build(2*v+1,m+1,r);
	tree[v][0]=add(tree[2*v][0],tree[2*v+1][0],MOD1);
	tree[v][1]=add(tree[2*v][1],tree[2*v+1][1],MOD2);
}
void push(int v,int l,int r){
	if(l>r)return;
	if(lazy[v]!=-1){
		if(l!=r){
			lazy[2*v]=lazy[v];
			lazy[2*v+1]=lazy[v];
		}
		tree[v][0]=mul(lazy[v],add(pref[r][0],-pref[l-1][0],MOD1),MOD1);
		tree[v][1]=mul(lazy[v],add(pref[r][1],-pref[l-1][1],MOD2),MOD2);
		lazy[v]=-1;
	}
}
void upd(int v,int l,int r,int ul,int ur,int t){
	push(v,l,r);
	if(l>r||ul>ur||l>ur||r<ul)return;
	if(l>=ul&&r<=ur){
		lazy[v]=t;
		push(v,l,r);
		return;
	}
	int m=(l+r)/2;
	upd(2*v,l,m,ul,ur,t);
	upd(2*v+1,m+1,r,ul,ur,t);
	tree[v][0]=add(tree[2*v][0],tree[2*v+1][0],MOD1);
	tree[v][1]=add(tree[2*v][1],tree[2*v+1][1],MOD2);
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;cin>>n;
	mp['I']=0;
	mp['J']=1;
	mp['O']=2;
	vector<string> v(3);
	for(int i=0;i<3;i++)cin>>v[i];
	queue<string> q;
	for(int i=0;i<3;i++)q.push(v[i]);
	v.clear();
	map<string,int> vis;
	for(;!q.empty();){
		string x=q.front();q.pop();
		if(vis[x])continue;
		vis[x]=1;
		v.push_back(x);
		for(auto y:v){
			string z=calc(x,y);
			q.push(z);
		}
	}
	int curbase1=1,curbase2=1;
	for(int i=1;i<=n;i++){
		pref[i][0]=add(pref[i-1][0],curbase1,MOD1);
		pref[i][1]=add(pref[i-1][1],curbase2,MOD2);
		curbase1=mul(curbase1,BASE,MOD1);
		curbase2=mul(curbase2,BASE,MOD2);
	}
	vector<int> res0,res1;
	for(string s:v){
		int cur0,cur1;cur0=cur1=0;
		for(int i=0;i<(int)s.length();i++){
			cur0=add(cur0,mul(mp[s[i]],add(pref[i+1][0],-pref[i][0],MOD1),MOD1),MOD1);
			cur1=add(cur1,mul(mp[s[i]],add(pref[i+1][1],-pref[i][1],MOD2),MOD2),MOD2);
		}
		res0.push_back(cur0);
		res1.push_back(cur1);
	}
	int t;cin>>t;
	cin>>s;
	memset(lazy,-1,sizeof lazy);
	build(1,1,n);
	int flag=0;
	for(int i=0;i<(int)res0.size();i++){
		if(tree[1][0]==res0[i]&&tree[1][1]==res1[i]){
			flag=1;
		}
	}
	flag?cout<<"Yes\n":cout<<"No\n";
	for(;t;t--){
		int l,r;cin>>l>>r;
		char c;cin>>c;
		int x=mp[c];
		upd(1,1,n,l,r,x);
		int flag=0;
		for(int i=0;i<(int)res0.size();i++){
			if(tree[1][0]==res0[i]&&tree[1][1]==res1[i]){
				flag=1;
			}
		}
		flag?cout<<"Yes\n":cout<<"No\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 80 ms 7048 KB Output is correct
2 Correct 117 ms 7152 KB Output is correct
3 Correct 92 ms 7072 KB Output is correct
4 Correct 71 ms 7112 KB Output is correct
5 Correct 70 ms 7224 KB Output is correct
6 Correct 69 ms 7144 KB Output is correct
7 Correct 74 ms 7108 KB Output is correct
8 Correct 78 ms 7084 KB Output is correct
9 Correct 75 ms 7080 KB Output is correct
10 Correct 76 ms 7108 KB Output is correct
11 Correct 75 ms 7088 KB Output is correct
12 Correct 88 ms 7076 KB Output is correct
13 Correct 77 ms 7188 KB Output is correct
14 Correct 75 ms 7108 KB Output is correct
15 Correct 75 ms 7124 KB Output is correct
16 Correct 76 ms 7108 KB Output is correct
17 Correct 93 ms 7156 KB Output is correct
18 Correct 86 ms 7148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 7048 KB Output is correct
2 Correct 117 ms 7152 KB Output is correct
3 Correct 92 ms 7072 KB Output is correct
4 Correct 71 ms 7112 KB Output is correct
5 Correct 70 ms 7224 KB Output is correct
6 Correct 69 ms 7144 KB Output is correct
7 Correct 74 ms 7108 KB Output is correct
8 Correct 78 ms 7084 KB Output is correct
9 Correct 75 ms 7080 KB Output is correct
10 Correct 76 ms 7108 KB Output is correct
11 Correct 75 ms 7088 KB Output is correct
12 Correct 88 ms 7076 KB Output is correct
13 Correct 77 ms 7188 KB Output is correct
14 Correct 75 ms 7108 KB Output is correct
15 Correct 75 ms 7124 KB Output is correct
16 Correct 76 ms 7108 KB Output is correct
17 Correct 93 ms 7156 KB Output is correct
18 Correct 86 ms 7148 KB Output is correct
19 Correct 323 ms 19800 KB Output is correct
20 Correct 292 ms 19784 KB Output is correct
21 Correct 178 ms 19468 KB Output is correct
22 Correct 204 ms 19148 KB Output is correct
23 Correct 122 ms 7936 KB Output is correct
24 Correct 118 ms 7972 KB Output is correct
25 Correct 194 ms 19784 KB Output is correct
26 Correct 241 ms 19892 KB Output is correct
27 Correct 224 ms 19740 KB Output is correct
28 Correct 240 ms 19740 KB Output is correct
29 Correct 230 ms 19672 KB Output is correct
30 Correct 124 ms 7876 KB Output is correct
31 Correct 233 ms 19796 KB Output is correct
32 Correct 217 ms 19324 KB Output is correct
33 Correct 117 ms 7864 KB Output is correct
34 Correct 243 ms 19752 KB Output is correct
35 Correct 169 ms 18656 KB Output is correct
36 Correct 118 ms 7928 KB Output is correct
37 Correct 118 ms 7924 KB Output is correct
38 Correct 259 ms 19752 KB Output is correct
39 Correct 146 ms 19712 KB Output is correct
40 Correct 171 ms 17424 KB Output is correct
41 Correct 386 ms 23644 KB Output is correct
42 Correct 57 ms 22956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 7048 KB Output is correct
2 Correct 117 ms 7152 KB Output is correct
3 Correct 92 ms 7072 KB Output is correct
4 Correct 71 ms 7112 KB Output is correct
5 Correct 70 ms 7224 KB Output is correct
6 Correct 69 ms 7144 KB Output is correct
7 Correct 74 ms 7108 KB Output is correct
8 Correct 78 ms 7084 KB Output is correct
9 Correct 75 ms 7080 KB Output is correct
10 Correct 76 ms 7108 KB Output is correct
11 Correct 75 ms 7088 KB Output is correct
12 Correct 88 ms 7076 KB Output is correct
13 Correct 77 ms 7188 KB Output is correct
14 Correct 75 ms 7108 KB Output is correct
15 Correct 75 ms 7124 KB Output is correct
16 Correct 76 ms 7108 KB Output is correct
17 Correct 93 ms 7156 KB Output is correct
18 Correct 86 ms 7148 KB Output is correct
19 Correct 87 ms 7160 KB Output is correct
20 Correct 93 ms 7080 KB Output is correct
21 Correct 78 ms 7132 KB Output is correct
22 Correct 82 ms 7088 KB Output is correct
23 Correct 79 ms 7072 KB Output is correct
24 Correct 72 ms 7108 KB Output is correct
25 Correct 75 ms 7108 KB Output is correct
26 Correct 69 ms 7048 KB Output is correct
27 Correct 100 ms 7084 KB Output is correct
28 Correct 70 ms 7076 KB Output is correct
29 Correct 75 ms 7092 KB Output is correct
30 Correct 66 ms 7104 KB Output is correct
31 Correct 76 ms 7084 KB Output is correct
32 Correct 81 ms 7236 KB Output is correct
33 Correct 80 ms 7096 KB Output is correct
34 Correct 69 ms 7056 KB Output is correct
35 Correct 77 ms 7108 KB Output is correct
36 Correct 89 ms 7156 KB Output is correct
37 Correct 85 ms 7400 KB Output is correct
38 Correct 76 ms 7124 KB Output is correct
39 Correct 76 ms 7160 KB Output is correct
40 Correct 76 ms 7104 KB Output is correct
41 Correct 76 ms 7140 KB Output is correct
42 Correct 82 ms 7468 KB Output is correct
43 Correct 74 ms 7124 KB Output is correct
44 Correct 80 ms 7164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 7048 KB Output is correct
2 Correct 117 ms 7152 KB Output is correct
3 Correct 92 ms 7072 KB Output is correct
4 Correct 71 ms 7112 KB Output is correct
5 Correct 70 ms 7224 KB Output is correct
6 Correct 69 ms 7144 KB Output is correct
7 Correct 74 ms 7108 KB Output is correct
8 Correct 78 ms 7084 KB Output is correct
9 Correct 75 ms 7080 KB Output is correct
10 Correct 76 ms 7108 KB Output is correct
11 Correct 75 ms 7088 KB Output is correct
12 Correct 88 ms 7076 KB Output is correct
13 Correct 77 ms 7188 KB Output is correct
14 Correct 75 ms 7108 KB Output is correct
15 Correct 75 ms 7124 KB Output is correct
16 Correct 76 ms 7108 KB Output is correct
17 Correct 93 ms 7156 KB Output is correct
18 Correct 86 ms 7148 KB Output is correct
19 Correct 323 ms 19800 KB Output is correct
20 Correct 292 ms 19784 KB Output is correct
21 Correct 178 ms 19468 KB Output is correct
22 Correct 204 ms 19148 KB Output is correct
23 Correct 122 ms 7936 KB Output is correct
24 Correct 118 ms 7972 KB Output is correct
25 Correct 194 ms 19784 KB Output is correct
26 Correct 241 ms 19892 KB Output is correct
27 Correct 224 ms 19740 KB Output is correct
28 Correct 240 ms 19740 KB Output is correct
29 Correct 230 ms 19672 KB Output is correct
30 Correct 124 ms 7876 KB Output is correct
31 Correct 233 ms 19796 KB Output is correct
32 Correct 217 ms 19324 KB Output is correct
33 Correct 117 ms 7864 KB Output is correct
34 Correct 243 ms 19752 KB Output is correct
35 Correct 169 ms 18656 KB Output is correct
36 Correct 118 ms 7928 KB Output is correct
37 Correct 118 ms 7924 KB Output is correct
38 Correct 259 ms 19752 KB Output is correct
39 Correct 146 ms 19712 KB Output is correct
40 Correct 171 ms 17424 KB Output is correct
41 Correct 386 ms 23644 KB Output is correct
42 Correct 57 ms 22956 KB Output is correct
43 Correct 87 ms 7160 KB Output is correct
44 Correct 93 ms 7080 KB Output is correct
45 Correct 78 ms 7132 KB Output is correct
46 Correct 82 ms 7088 KB Output is correct
47 Correct 79 ms 7072 KB Output is correct
48 Correct 72 ms 7108 KB Output is correct
49 Correct 75 ms 7108 KB Output is correct
50 Correct 69 ms 7048 KB Output is correct
51 Correct 100 ms 7084 KB Output is correct
52 Correct 70 ms 7076 KB Output is correct
53 Correct 75 ms 7092 KB Output is correct
54 Correct 66 ms 7104 KB Output is correct
55 Correct 76 ms 7084 KB Output is correct
56 Correct 81 ms 7236 KB Output is correct
57 Correct 80 ms 7096 KB Output is correct
58 Correct 69 ms 7056 KB Output is correct
59 Correct 77 ms 7108 KB Output is correct
60 Correct 89 ms 7156 KB Output is correct
61 Correct 85 ms 7400 KB Output is correct
62 Correct 76 ms 7124 KB Output is correct
63 Correct 76 ms 7160 KB Output is correct
64 Correct 76 ms 7104 KB Output is correct
65 Correct 76 ms 7140 KB Output is correct
66 Correct 82 ms 7468 KB Output is correct
67 Correct 74 ms 7124 KB Output is correct
68 Correct 80 ms 7164 KB Output is correct
69 Correct 440 ms 24948 KB Output is correct
70 Correct 473 ms 26488 KB Output is correct
71 Correct 125 ms 10296 KB Output is correct
72 Correct 146 ms 10308 KB Output is correct
73 Correct 122 ms 10316 KB Output is correct
74 Correct 236 ms 22616 KB Output is correct
75 Correct 124 ms 10348 KB Output is correct
76 Correct 224 ms 24856 KB Output is correct
77 Correct 232 ms 23612 KB Output is correct
78 Correct 126 ms 10424 KB Output is correct
79 Correct 135 ms 10384 KB Output is correct
80 Correct 298 ms 23964 KB Output is correct
81 Correct 123 ms 10512 KB Output is correct
82 Correct 388 ms 26648 KB Output is correct
83 Correct 366 ms 26484 KB Output is correct
84 Correct 130 ms 10520 KB Output is correct
85 Correct 128 ms 10584 KB Output is correct
86 Correct 293 ms 24332 KB Output is correct
87 Correct 369 ms 26604 KB Output is correct
88 Correct 143 ms 10532 KB Output is correct
89 Correct 296 ms 25292 KB Output is correct
90 Correct 316 ms 26540 KB Output is correct
91 Correct 146 ms 10468 KB Output is correct
92 Correct 301 ms 24176 KB Output is correct
93 Correct 156 ms 10496 KB Output is correct
94 Correct 130 ms 10488 KB Output is correct
95 Correct 133 ms 10548 KB Output is correct
96 Correct 262 ms 23280 KB Output is correct
97 Correct 247 ms 26648 KB Output is correct
98 Correct 286 ms 19960 KB Output is correct
99 Correct 566 ms 26732 KB Output is correct
100 Correct 223 ms 26024 KB Output is correct