답안 #507625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
507625 2022-01-12T20:57:35 Z nichke Crossing (JOI21_crossing) C++14
26 / 100
334 ms 17652 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=101;
const int MOD1=(int)1e9+9;
const int MOD2=(int)1e9+7;
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['J']=0;
	mp['O']=1;
	mp['I']=2;
	vector<string> v(3);
	map<string,int> vis;
	for(int i=0;i<3;i++)cin>>v[i],vis[v[i]]=1;
	for(int i=0;i<(int)v.size();i++){
		for(int j=0;j<(int)v.size();j++){
			string nxt=calc(v[i],v[j]);
			if(vis[nxt])continue;
			v.push_back(nxt);
			vis[nxt]=1;
		}
	}
	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;
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 784 KB Output is correct
2 Correct 84 ms 856 KB Output is correct
3 Correct 86 ms 820 KB Output is correct
4 Correct 69 ms 872 KB Output is correct
5 Correct 69 ms 900 KB Output is correct
6 Correct 67 ms 792 KB Output is correct
7 Correct 69 ms 828 KB Output is correct
8 Correct 74 ms 848 KB Output is correct
9 Correct 76 ms 904 KB Output is correct
10 Correct 72 ms 972 KB Output is correct
11 Correct 71 ms 876 KB Output is correct
12 Correct 71 ms 828 KB Output is correct
13 Correct 74 ms 928 KB Output is correct
14 Correct 75 ms 920 KB Output is correct
15 Correct 73 ms 928 KB Output is correct
16 Correct 73 ms 884 KB Output is correct
17 Correct 72 ms 884 KB Output is correct
18 Correct 81 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 784 KB Output is correct
2 Correct 84 ms 856 KB Output is correct
3 Correct 86 ms 820 KB Output is correct
4 Correct 69 ms 872 KB Output is correct
5 Correct 69 ms 900 KB Output is correct
6 Correct 67 ms 792 KB Output is correct
7 Correct 69 ms 828 KB Output is correct
8 Correct 74 ms 848 KB Output is correct
9 Correct 76 ms 904 KB Output is correct
10 Correct 72 ms 972 KB Output is correct
11 Correct 71 ms 876 KB Output is correct
12 Correct 71 ms 828 KB Output is correct
13 Correct 74 ms 928 KB Output is correct
14 Correct 75 ms 920 KB Output is correct
15 Correct 73 ms 928 KB Output is correct
16 Correct 73 ms 884 KB Output is correct
17 Correct 72 ms 884 KB Output is correct
18 Correct 81 ms 868 KB Output is correct
19 Correct 334 ms 17608 KB Output is correct
20 Correct 309 ms 14420 KB Output is correct
21 Correct 212 ms 17436 KB Output is correct
22 Correct 205 ms 17104 KB Output is correct
23 Correct 112 ms 1832 KB Output is correct
24 Correct 115 ms 1852 KB Output is correct
25 Correct 210 ms 17612 KB Output is correct
26 Correct 236 ms 17652 KB Output is correct
27 Correct 232 ms 17564 KB Output is correct
28 Correct 284 ms 17612 KB Output is correct
29 Correct 221 ms 17520 KB Output is correct
30 Correct 126 ms 1828 KB Output is correct
31 Correct 227 ms 17592 KB Output is correct
32 Correct 252 ms 17292 KB Output is correct
33 Correct 114 ms 1936 KB Output is correct
34 Correct 253 ms 17616 KB Output is correct
35 Correct 181 ms 16524 KB Output is correct
36 Correct 112 ms 1856 KB Output is correct
37 Correct 117 ms 1820 KB Output is correct
38 Correct 258 ms 14424 KB Output is correct
39 Incorrect 149 ms 13572 KB Output isn't correct
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 784 KB Output is correct
2 Correct 84 ms 856 KB Output is correct
3 Correct 86 ms 820 KB Output is correct
4 Correct 69 ms 872 KB Output is correct
5 Correct 69 ms 900 KB Output is correct
6 Correct 67 ms 792 KB Output is correct
7 Correct 69 ms 828 KB Output is correct
8 Correct 74 ms 848 KB Output is correct
9 Correct 76 ms 904 KB Output is correct
10 Correct 72 ms 972 KB Output is correct
11 Correct 71 ms 876 KB Output is correct
12 Correct 71 ms 828 KB Output is correct
13 Correct 74 ms 928 KB Output is correct
14 Correct 75 ms 920 KB Output is correct
15 Correct 73 ms 928 KB Output is correct
16 Correct 73 ms 884 KB Output is correct
17 Correct 72 ms 884 KB Output is correct
18 Correct 81 ms 868 KB Output is correct
19 Correct 80 ms 936 KB Output is correct
20 Correct 87 ms 856 KB Output is correct
21 Correct 72 ms 884 KB Output is correct
22 Correct 62 ms 860 KB Output is correct
23 Correct 71 ms 820 KB Output is correct
24 Correct 70 ms 840 KB Output is correct
25 Correct 81 ms 860 KB Output is correct
26 Correct 66 ms 884 KB Output is correct
27 Correct 71 ms 912 KB Output is correct
28 Correct 64 ms 840 KB Output is correct
29 Correct 71 ms 872 KB Output is correct
30 Correct 71 ms 904 KB Output is correct
31 Correct 73 ms 844 KB Output is correct
32 Correct 71 ms 872 KB Output is correct
33 Correct 90 ms 908 KB Output is correct
34 Correct 67 ms 844 KB Output is correct
35 Correct 72 ms 836 KB Output is correct
36 Correct 73 ms 848 KB Output is correct
37 Correct 71 ms 916 KB Output is correct
38 Correct 71 ms 884 KB Output is correct
39 Correct 74 ms 840 KB Output is correct
40 Correct 72 ms 836 KB Output is correct
41 Correct 77 ms 836 KB Output is correct
42 Correct 75 ms 900 KB Output is correct
43 Correct 69 ms 836 KB Output is correct
44 Correct 73 ms 912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 784 KB Output is correct
2 Correct 84 ms 856 KB Output is correct
3 Correct 86 ms 820 KB Output is correct
4 Correct 69 ms 872 KB Output is correct
5 Correct 69 ms 900 KB Output is correct
6 Correct 67 ms 792 KB Output is correct
7 Correct 69 ms 828 KB Output is correct
8 Correct 74 ms 848 KB Output is correct
9 Correct 76 ms 904 KB Output is correct
10 Correct 72 ms 972 KB Output is correct
11 Correct 71 ms 876 KB Output is correct
12 Correct 71 ms 828 KB Output is correct
13 Correct 74 ms 928 KB Output is correct
14 Correct 75 ms 920 KB Output is correct
15 Correct 73 ms 928 KB Output is correct
16 Correct 73 ms 884 KB Output is correct
17 Correct 72 ms 884 KB Output is correct
18 Correct 81 ms 868 KB Output is correct
19 Correct 334 ms 17608 KB Output is correct
20 Correct 309 ms 14420 KB Output is correct
21 Correct 212 ms 17436 KB Output is correct
22 Correct 205 ms 17104 KB Output is correct
23 Correct 112 ms 1832 KB Output is correct
24 Correct 115 ms 1852 KB Output is correct
25 Correct 210 ms 17612 KB Output is correct
26 Correct 236 ms 17652 KB Output is correct
27 Correct 232 ms 17564 KB Output is correct
28 Correct 284 ms 17612 KB Output is correct
29 Correct 221 ms 17520 KB Output is correct
30 Correct 126 ms 1828 KB Output is correct
31 Correct 227 ms 17592 KB Output is correct
32 Correct 252 ms 17292 KB Output is correct
33 Correct 114 ms 1936 KB Output is correct
34 Correct 253 ms 17616 KB Output is correct
35 Correct 181 ms 16524 KB Output is correct
36 Correct 112 ms 1856 KB Output is correct
37 Correct 117 ms 1820 KB Output is correct
38 Correct 258 ms 14424 KB Output is correct
39 Incorrect 149 ms 13572 KB Output isn't correct
40 Halted 0 ms 0 KB -