Submission #425422

# Submission time Handle Problem Language Result Execution time Memory
425422 2021-06-13T02:56:27 Z CSQ31 Crossing (JOI21_crossing) C++14
100 / 100
756 ms 35844 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 2e5+5;
string make(string a,string b){
	int n = sz(a);
	string res(n,'a');
	for(int i=0;i<n;i++){
		if(a[i] == b[i])res[i] = a[i];
		else{
			if((a[i] == 'I' && b[i] == 'O') || (a[i] == 'O' && b[i] == 'I'))res[i] = 'J';
			if((a[i] == 'J' && b[i] == 'I') || (a[i] == 'I' && b[i] == 'J'))res[i] = 'O';
			if((a[i] == 'O' && b[i] == 'J') || (a[i] == 'J' && b[i] == 'O'))res[i] = 'I';
			
		}
	}
	return res;
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll MOD[2],pw[2][MAXN];
ll base;
PII hh(string s){
	PII res = {0,0};
	for(int i=0;i<sz(s);i++){
		res.fi+=((s[i]-'A')*pw[0][i])%MOD[0];
		res.se+=((s[i]-'A')*pw[1][i])%MOD[1];
		if(res.fi>=MOD[0])res.fi-=MOD[0];
		if(res.se>=MOD[1])res.se-=MOD[1];
	}
	return res;
}
ll binpow(ll n,ll k,ll mod){
	ll res = 1;
	while(k){
		if(k&1)res*=n;
		n*=n;
		k/=2;
		res%=mod;
		n%=mod;
	}
	return res;
}
vector<vector<PII>> pref(4,vector<PII>(MAXN));
vector<PII>t(4*MAXN);
vector<int>lazy(4*MAXN,-1);
void pushdown(int v,int l,int r){
	int tm = (l+r)/2;
	if(lazy[v] != -1){
		int c = lazy[v];
		lazy[2*v] = lazy[2*v+1] = c;
		t[2*v].fi = (pref[c][tm].fi - pref[c][l-1].fi+MOD[0])%MOD[0];
		t[2*v].se = (pref[c][tm].se - pref[c][l-1].se+MOD[1])%MOD[1];
		t[2*v+1].fi = (pref[c][r].fi - pref[c][tm].fi+MOD[0])%MOD[0];
		t[2*v+1].se = (pref[c][r].se - pref[c][tm].se+MOD[1])%MOD[1];
		lazy[v] = -1;
	}
}
void upd(int v,int l,int r,int tl,int tr,int c){
	if(l > r)return;
	if(l == tl && r == tr){
		lazy[v] = c;
		t[v].fi = (pref[c][r].fi - pref[c][l-1].fi+MOD[0])%MOD[0];
		t[v].se = (pref[c][r].se - pref[c][l-1].se+MOD[1])%MOD[1];	
		return;	
	}
	pushdown(v,tl,tr);
	int tm = (tl+tr)/2;
	upd(2*v,l,min(r,tm),tl,tm,c);
	upd(2*v+1,max(tm+1,l),r,tm+1,tr,c);
	t[v].fi = (t[2*v].fi+t[2*v+1].fi)%MOD[0];
	t[v].se = (t[2*v].se+t[2*v+1].se)%MOD[1];
}
PII query(int v,int l,int r,int tl,int tr){
	if(l>r)return {0,0};
	if(l==tl && r==tr){
		return t[v];
	}
	int tm =(tl+tr);
	pushdown(v,tl,tr);
	PII a = query(2*v,l,min(r,tm),tl,tm);
	PII b = query(2*v+1,max(tm+1,l),r,tm+1,tr);
	return {(a.fi+b.fi)%MOD[0],(a.se+b.se)%MOD[1]};
}


int main()
{
	owo
	int n,q;
	cin>>n;
	MOD[0] = 1e6+3;
	MOD[1] = uniform_int_distribution<ll>(1e8,1e9)(rng);
	base = uniform_int_distribution<ll>(1e6,1e9+6)(rng);
	pw[0][0] = pw[1][0] = 1;
	for(int i=0;i<2;i++)
		for(int j=1;j<n;j++)pw[i][j] = pw[i][j-1] * base %MOD[i];
		
		
	string a,b,c,t;
	cin>>a>>b>>c>>q>>t;
	vector<string>cur = {a,b,c};
	set<PII>seen;
	seen.insert(hh(a));
	seen.insert(hh(b));
	seen.insert(hh(c));
	int idx=0;
	while(true){
		vector<string>tmp;
		bool ok =0;
		for(int i=idx+1;i<sz(cur);i++){
			string res = make(cur[idx],cur[i]);
			PII r = hh(res);
			if(!seen.count(r)){
				ok = 1;
			   seen.insert(r);
			   cur.pb(res);
		   }
		}
		idx++;
		if(!ok)break;
	}
	string J = "JOI";
	for(int i=0;i<3;i++){
		for(int j=1;j<=n;j++){
			pref[i][j].fi+=((J[i]-'A')*pw[0][j-1])%MOD[0];
			pref[i][j].se+=((J[i]-'A')*pw[1][j-1])%MOD[1];
			pref[i][j].fi+=pref[i][j-1].fi;
			pref[i][j].se+=pref[i][j-1].se;
			if(pref[i][j].fi>=MOD[0])pref[i][j].fi-=MOD[0];
			if(pref[i][j].se>=MOD[1])pref[i][j].se-=MOD[1];
			
		}
	}
	for(int i=1;i<=n;i++){
		pref[3][i].fi+=pref[3][i-1].fi;
		pref[3][i].se+=pref[3][i-1].se;
		pref[3][i].fi+=(t[i-1]-'A')*pw[0][i-1]%MOD[0];
		pref[3][i].se+=(t[i-1]-'A')*pw[1][i-1]%MOD[1];
		pref[3][i].fi%=MOD[0];
		pref[3][i].se%=MOD[1];
	}
	upd(1,1,n,1,n,3);
	if(seen.count(query(1,1,n,1,n)))cout<<"Yes"<<'\n';
	else cout<<"No"<<'\n';
	while(q--){
		int l,r;
		char c;
		cin>>l>>r>>c;
		if(c=='J')upd(1,l,r,1,n,0);
		if(c=='O')upd(1,l,r,1,n,1);
		if(c=='I')upd(1,l,r,1,n,2);
		PII nw = query(1,1,n,1,n);
		if(seen.count(nw))cout<<"Yes"<<'\n';
		else cout<<"No"<<'\n';
		//divide by base^l :waturr: need inverse
	}
	//cout<<sz(seen)<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29032 KB Output is correct
2 Correct 128 ms 29172 KB Output is correct
3 Correct 139 ms 29064 KB Output is correct
4 Correct 108 ms 29040 KB Output is correct
5 Correct 127 ms 29060 KB Output is correct
6 Correct 110 ms 29048 KB Output is correct
7 Correct 131 ms 29064 KB Output is correct
8 Correct 134 ms 29064 KB Output is correct
9 Correct 124 ms 29212 KB Output is correct
10 Correct 116 ms 29064 KB Output is correct
11 Correct 121 ms 29048 KB Output is correct
12 Correct 131 ms 29072 KB Output is correct
13 Correct 121 ms 29112 KB Output is correct
14 Correct 120 ms 29012 KB Output is correct
15 Correct 117 ms 29068 KB Output is correct
16 Correct 115 ms 29112 KB Output is correct
17 Correct 117 ms 29196 KB Output is correct
18 Correct 130 ms 29056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29032 KB Output is correct
2 Correct 128 ms 29172 KB Output is correct
3 Correct 139 ms 29064 KB Output is correct
4 Correct 108 ms 29040 KB Output is correct
5 Correct 127 ms 29060 KB Output is correct
6 Correct 110 ms 29048 KB Output is correct
7 Correct 131 ms 29064 KB Output is correct
8 Correct 134 ms 29064 KB Output is correct
9 Correct 124 ms 29212 KB Output is correct
10 Correct 116 ms 29064 KB Output is correct
11 Correct 121 ms 29048 KB Output is correct
12 Correct 131 ms 29072 KB Output is correct
13 Correct 121 ms 29112 KB Output is correct
14 Correct 120 ms 29012 KB Output is correct
15 Correct 117 ms 29068 KB Output is correct
16 Correct 115 ms 29112 KB Output is correct
17 Correct 117 ms 29196 KB Output is correct
18 Correct 130 ms 29056 KB Output is correct
19 Correct 659 ms 34424 KB Output is correct
20 Correct 537 ms 34412 KB Output is correct
21 Correct 313 ms 34056 KB Output is correct
22 Correct 347 ms 33588 KB Output is correct
23 Correct 184 ms 29316 KB Output is correct
24 Correct 182 ms 29364 KB Output is correct
25 Correct 322 ms 34312 KB Output is correct
26 Correct 422 ms 34360 KB Output is correct
27 Correct 551 ms 34328 KB Output is correct
28 Correct 527 ms 34328 KB Output is correct
29 Correct 436 ms 34376 KB Output is correct
30 Correct 207 ms 29348 KB Output is correct
31 Correct 507 ms 34408 KB Output is correct
32 Correct 481 ms 33996 KB Output is correct
33 Correct 197 ms 29336 KB Output is correct
34 Correct 455 ms 34336 KB Output is correct
35 Correct 321 ms 32952 KB Output is correct
36 Correct 182 ms 29352 KB Output is correct
37 Correct 198 ms 29320 KB Output is correct
38 Correct 411 ms 34548 KB Output is correct
39 Correct 209 ms 34368 KB Output is correct
40 Correct 373 ms 32716 KB Output is correct
41 Correct 579 ms 34584 KB Output is correct
42 Correct 113 ms 34576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29032 KB Output is correct
2 Correct 128 ms 29172 KB Output is correct
3 Correct 139 ms 29064 KB Output is correct
4 Correct 108 ms 29040 KB Output is correct
5 Correct 127 ms 29060 KB Output is correct
6 Correct 110 ms 29048 KB Output is correct
7 Correct 131 ms 29064 KB Output is correct
8 Correct 134 ms 29064 KB Output is correct
9 Correct 124 ms 29212 KB Output is correct
10 Correct 116 ms 29064 KB Output is correct
11 Correct 121 ms 29048 KB Output is correct
12 Correct 131 ms 29072 KB Output is correct
13 Correct 121 ms 29112 KB Output is correct
14 Correct 120 ms 29012 KB Output is correct
15 Correct 117 ms 29068 KB Output is correct
16 Correct 115 ms 29112 KB Output is correct
17 Correct 117 ms 29196 KB Output is correct
18 Correct 130 ms 29056 KB Output is correct
19 Correct 129 ms 29064 KB Output is correct
20 Correct 147 ms 29060 KB Output is correct
21 Correct 120 ms 29132 KB Output is correct
22 Correct 106 ms 29056 KB Output is correct
23 Correct 116 ms 29096 KB Output is correct
24 Correct 116 ms 29092 KB Output is correct
25 Correct 120 ms 29064 KB Output is correct
26 Correct 113 ms 29044 KB Output is correct
27 Correct 119 ms 29020 KB Output is correct
28 Correct 121 ms 29060 KB Output is correct
29 Correct 128 ms 29212 KB Output is correct
30 Correct 107 ms 29060 KB Output is correct
31 Correct 119 ms 29140 KB Output is correct
32 Correct 145 ms 29024 KB Output is correct
33 Correct 123 ms 29208 KB Output is correct
34 Correct 107 ms 29076 KB Output is correct
35 Correct 125 ms 29040 KB Output is correct
36 Correct 121 ms 29132 KB Output is correct
37 Correct 119 ms 29172 KB Output is correct
38 Correct 120 ms 29140 KB Output is correct
39 Correct 116 ms 29064 KB Output is correct
40 Correct 124 ms 29168 KB Output is correct
41 Correct 121 ms 29048 KB Output is correct
42 Correct 119 ms 29096 KB Output is correct
43 Correct 113 ms 29056 KB Output is correct
44 Correct 122 ms 29116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29032 KB Output is correct
2 Correct 128 ms 29172 KB Output is correct
3 Correct 139 ms 29064 KB Output is correct
4 Correct 108 ms 29040 KB Output is correct
5 Correct 127 ms 29060 KB Output is correct
6 Correct 110 ms 29048 KB Output is correct
7 Correct 131 ms 29064 KB Output is correct
8 Correct 134 ms 29064 KB Output is correct
9 Correct 124 ms 29212 KB Output is correct
10 Correct 116 ms 29064 KB Output is correct
11 Correct 121 ms 29048 KB Output is correct
12 Correct 131 ms 29072 KB Output is correct
13 Correct 121 ms 29112 KB Output is correct
14 Correct 120 ms 29012 KB Output is correct
15 Correct 117 ms 29068 KB Output is correct
16 Correct 115 ms 29112 KB Output is correct
17 Correct 117 ms 29196 KB Output is correct
18 Correct 130 ms 29056 KB Output is correct
19 Correct 659 ms 34424 KB Output is correct
20 Correct 537 ms 34412 KB Output is correct
21 Correct 313 ms 34056 KB Output is correct
22 Correct 347 ms 33588 KB Output is correct
23 Correct 184 ms 29316 KB Output is correct
24 Correct 182 ms 29364 KB Output is correct
25 Correct 322 ms 34312 KB Output is correct
26 Correct 422 ms 34360 KB Output is correct
27 Correct 551 ms 34328 KB Output is correct
28 Correct 527 ms 34328 KB Output is correct
29 Correct 436 ms 34376 KB Output is correct
30 Correct 207 ms 29348 KB Output is correct
31 Correct 507 ms 34408 KB Output is correct
32 Correct 481 ms 33996 KB Output is correct
33 Correct 197 ms 29336 KB Output is correct
34 Correct 455 ms 34336 KB Output is correct
35 Correct 321 ms 32952 KB Output is correct
36 Correct 182 ms 29352 KB Output is correct
37 Correct 198 ms 29320 KB Output is correct
38 Correct 411 ms 34548 KB Output is correct
39 Correct 209 ms 34368 KB Output is correct
40 Correct 373 ms 32716 KB Output is correct
41 Correct 579 ms 34584 KB Output is correct
42 Correct 113 ms 34576 KB Output is correct
43 Correct 129 ms 29064 KB Output is correct
44 Correct 147 ms 29060 KB Output is correct
45 Correct 120 ms 29132 KB Output is correct
46 Correct 106 ms 29056 KB Output is correct
47 Correct 116 ms 29096 KB Output is correct
48 Correct 116 ms 29092 KB Output is correct
49 Correct 120 ms 29064 KB Output is correct
50 Correct 113 ms 29044 KB Output is correct
51 Correct 119 ms 29020 KB Output is correct
52 Correct 121 ms 29060 KB Output is correct
53 Correct 128 ms 29212 KB Output is correct
54 Correct 107 ms 29060 KB Output is correct
55 Correct 119 ms 29140 KB Output is correct
56 Correct 145 ms 29024 KB Output is correct
57 Correct 123 ms 29208 KB Output is correct
58 Correct 107 ms 29076 KB Output is correct
59 Correct 125 ms 29040 KB Output is correct
60 Correct 121 ms 29132 KB Output is correct
61 Correct 119 ms 29172 KB Output is correct
62 Correct 120 ms 29140 KB Output is correct
63 Correct 116 ms 29064 KB Output is correct
64 Correct 124 ms 29168 KB Output is correct
65 Correct 121 ms 29048 KB Output is correct
66 Correct 119 ms 29096 KB Output is correct
67 Correct 113 ms 29056 KB Output is correct
68 Correct 122 ms 29116 KB Output is correct
69 Correct 600 ms 34636 KB Output is correct
70 Correct 623 ms 35464 KB Output is correct
71 Correct 184 ms 29312 KB Output is correct
72 Correct 187 ms 29348 KB Output is correct
73 Correct 195 ms 29448 KB Output is correct
74 Correct 316 ms 33640 KB Output is correct
75 Correct 189 ms 29320 KB Output is correct
76 Correct 329 ms 34400 KB Output is correct
77 Correct 391 ms 33536 KB Output is correct
78 Correct 188 ms 29384 KB Output is correct
79 Correct 225 ms 29340 KB Output is correct
80 Correct 405 ms 33648 KB Output is correct
81 Correct 218 ms 29508 KB Output is correct
82 Correct 512 ms 35476 KB Output is correct
83 Correct 555 ms 35076 KB Output is correct
84 Correct 203 ms 29388 KB Output is correct
85 Correct 182 ms 29348 KB Output is correct
86 Correct 636 ms 33872 KB Output is correct
87 Correct 590 ms 35588 KB Output is correct
88 Correct 223 ms 29412 KB Output is correct
89 Correct 499 ms 34652 KB Output is correct
90 Correct 558 ms 35468 KB Output is correct
91 Correct 262 ms 29332 KB Output is correct
92 Correct 452 ms 33764 KB Output is correct
93 Correct 201 ms 29452 KB Output is correct
94 Correct 200 ms 29416 KB Output is correct
95 Correct 194 ms 29432 KB Output is correct
96 Correct 418 ms 34308 KB Output is correct
97 Correct 268 ms 35588 KB Output is correct
98 Correct 411 ms 33288 KB Output is correct
99 Correct 756 ms 35844 KB Output is correct
100 Correct 206 ms 35732 KB Output is correct