답안 #425421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
425421 2021-06-13T02:54:20 Z CSQ31 Crossing (JOI21_crossing) C++14
26 / 100
488 ms 62948 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(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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 26716 KB Output is correct
2 Correct 130 ms 26764 KB Output is correct
3 Correct 154 ms 26748 KB Output is correct
4 Correct 112 ms 26744 KB Output is correct
5 Correct 109 ms 26728 KB Output is correct
6 Correct 112 ms 26676 KB Output is correct
7 Correct 111 ms 26696 KB Output is correct
8 Correct 114 ms 26704 KB Output is correct
9 Correct 117 ms 26760 KB Output is correct
10 Correct 123 ms 26780 KB Output is correct
11 Correct 116 ms 26756 KB Output is correct
12 Correct 122 ms 26668 KB Output is correct
13 Correct 144 ms 26676 KB Output is correct
14 Correct 114 ms 26772 KB Output is correct
15 Correct 115 ms 26756 KB Output is correct
16 Correct 115 ms 26764 KB Output is correct
17 Correct 118 ms 26672 KB Output is correct
18 Correct 137 ms 26760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 26716 KB Output is correct
2 Correct 130 ms 26764 KB Output is correct
3 Correct 154 ms 26748 KB Output is correct
4 Correct 112 ms 26744 KB Output is correct
5 Correct 109 ms 26728 KB Output is correct
6 Correct 112 ms 26676 KB Output is correct
7 Correct 111 ms 26696 KB Output is correct
8 Correct 114 ms 26704 KB Output is correct
9 Correct 117 ms 26760 KB Output is correct
10 Correct 123 ms 26780 KB Output is correct
11 Correct 116 ms 26756 KB Output is correct
12 Correct 122 ms 26668 KB Output is correct
13 Correct 144 ms 26676 KB Output is correct
14 Correct 114 ms 26772 KB Output is correct
15 Correct 115 ms 26756 KB Output is correct
16 Correct 115 ms 26764 KB Output is correct
17 Correct 118 ms 26672 KB Output is correct
18 Correct 137 ms 26760 KB Output is correct
19 Correct 68 ms 32236 KB Output is correct
20 Correct 488 ms 32024 KB Output is correct
21 Runtime error 83 ms 62948 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 26716 KB Output is correct
2 Correct 130 ms 26764 KB Output is correct
3 Correct 154 ms 26748 KB Output is correct
4 Correct 112 ms 26744 KB Output is correct
5 Correct 109 ms 26728 KB Output is correct
6 Correct 112 ms 26676 KB Output is correct
7 Correct 111 ms 26696 KB Output is correct
8 Correct 114 ms 26704 KB Output is correct
9 Correct 117 ms 26760 KB Output is correct
10 Correct 123 ms 26780 KB Output is correct
11 Correct 116 ms 26756 KB Output is correct
12 Correct 122 ms 26668 KB Output is correct
13 Correct 144 ms 26676 KB Output is correct
14 Correct 114 ms 26772 KB Output is correct
15 Correct 115 ms 26756 KB Output is correct
16 Correct 115 ms 26764 KB Output is correct
17 Correct 118 ms 26672 KB Output is correct
18 Correct 137 ms 26760 KB Output is correct
19 Correct 124 ms 26716 KB Output is correct
20 Correct 139 ms 26800 KB Output is correct
21 Correct 117 ms 26780 KB Output is correct
22 Correct 124 ms 26624 KB Output is correct
23 Correct 120 ms 26744 KB Output is correct
24 Correct 114 ms 26676 KB Output is correct
25 Correct 117 ms 26756 KB Output is correct
26 Correct 131 ms 26760 KB Output is correct
27 Correct 119 ms 26688 KB Output is correct
28 Correct 111 ms 26728 KB Output is correct
29 Correct 144 ms 26748 KB Output is correct
30 Correct 106 ms 26708 KB Output is correct
31 Correct 119 ms 26684 KB Output is correct
32 Correct 122 ms 26708 KB Output is correct
33 Correct 127 ms 26736 KB Output is correct
34 Correct 110 ms 26732 KB Output is correct
35 Correct 124 ms 26716 KB Output is correct
36 Correct 124 ms 26736 KB Output is correct
37 Correct 130 ms 26756 KB Output is correct
38 Correct 119 ms 26700 KB Output is correct
39 Correct 122 ms 26728 KB Output is correct
40 Correct 138 ms 26744 KB Output is correct
41 Correct 120 ms 26696 KB Output is correct
42 Correct 133 ms 26744 KB Output is correct
43 Correct 136 ms 26736 KB Output is correct
44 Correct 118 ms 26732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 26716 KB Output is correct
2 Correct 130 ms 26764 KB Output is correct
3 Correct 154 ms 26748 KB Output is correct
4 Correct 112 ms 26744 KB Output is correct
5 Correct 109 ms 26728 KB Output is correct
6 Correct 112 ms 26676 KB Output is correct
7 Correct 111 ms 26696 KB Output is correct
8 Correct 114 ms 26704 KB Output is correct
9 Correct 117 ms 26760 KB Output is correct
10 Correct 123 ms 26780 KB Output is correct
11 Correct 116 ms 26756 KB Output is correct
12 Correct 122 ms 26668 KB Output is correct
13 Correct 144 ms 26676 KB Output is correct
14 Correct 114 ms 26772 KB Output is correct
15 Correct 115 ms 26756 KB Output is correct
16 Correct 115 ms 26764 KB Output is correct
17 Correct 118 ms 26672 KB Output is correct
18 Correct 137 ms 26760 KB Output is correct
19 Correct 68 ms 32236 KB Output is correct
20 Correct 488 ms 32024 KB Output is correct
21 Runtime error 83 ms 62948 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -