답안 #419726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
419726 2021-06-07T11:56:27 Z zaneyu Crossing (JOI21_crossing) C++14
49 / 100
697 ms 17960 KB
/*input
4
JOJO
JJOI
OJOO
3
IJOJ
1 4 O
2 2 J
2 4 I
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("Ofast")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (ll)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-4;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
	return (a*b)%MOD;
}
ll mypow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=mult(res,a);
		a=mult(a,a);
		b/=2;
	}
	return res;
}
int pww[maxn];
string arr[3];
string bl="JOI";
string op(string a,string b){
	string ans="";
	REP(i,sz(a)){
		if(a[i]==b[i]) ans.pb(a[i]);
		else{
			REP(k,3){
				if(bl[k]!=a[i] and bl[k]!=b[i]) ans.pb(bl[k]);
			}
		}
	}
	return ans;
}
ll inv(int x){
	return mypow(x,MOD-2);
}
struct node{
	int sum,lazy,len;
}seg[4*maxn];
ll i3=inv(3);
void build(int idx,int l,int r){
	seg[idx].len=(r-l+1);
	if(l==r) return;
	int mid=(l+r)/2;
	build(idx*2,l,mid);
	build(idx*2+1,mid+1,r);
}
void pushdown(int idx,int l,int r){
	if(seg[idx].lazy==0) return;
	seg[idx].sum=mult(mult(pww[seg[idx].len]-1,i3),seg[idx].lazy);
	if(l!=r){
		seg[idx*2].lazy=seg[idx].lazy;
		seg[idx*2+1].lazy=seg[idx].lazy;
	}
	seg[idx].lazy=0;
}
node merge(node a,node b){
	node c;
	c.sum=(a.sum+mult(b.sum,pww[a.len]))%MOD;
	c.len=a.len+b.len;
	return c;
}
void upd(int idx,int l,int r,int ql,int qr,int x){
	pushdown(idx,l,r);
	if(r<ql or l>qr) return;
	if(ql<=l and r<=qr){
		seg[idx].lazy=x;
		pushdown(idx,l,r);
		return;
	}
	int mid=(l+r)/2;
	upd(idx*2,l,mid,ql,qr,x);
	upd(idx*2+1,mid+1,r,ql,qr,x);
	seg[idx]=merge(seg[idx*2],seg[idx*2+1]);
}
map<char,int> mp;
int hsh(string s){
	int pw=1;
	ll ans=0;
	for(auto x:s){
		ans+=mult(pw,mp[x]);
		ans%=MOD;
		pw=mult(pw,4);
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	int n;
	cin>>n;
	REP(i,3) cin>>arr[i];
	
	mp['J']=1,mp['O']=2,mp['I']=3;
	vector<string> v;
	map<int,int> cnt;
	REP(i,3){
		cnt[hsh(arr[i])]++;
		REP(j,i){
			string z=op(arr[i],arr[j]);
			cnt[hsh(z)]++;
		}
	}
	pww[0]=1;
	REP1(i,n) pww[i]=mult(pww[i-1],4);
	vector<int> b;
	REP(i,3) b.pb(i);
	do{
		string cur="";
		for(auto x:b){
			if(!sz(cur)) cur=arr[x];
			else cur=op(cur,arr[x]);
		}
		cnt[hsh(cur)]++;
	}while(next_permutation(ALL(b)));
	int q;
	string s;
	cin>>q>>s;
	build(1,0,n-1);
	REP(i,n) upd(1,0,n-1,i,i,mp[s[i]]);
	if(cnt[seg[1].sum]){
		cout<<"Yes\n";
	}
	else cout<<"No\n";
	while(q--){
		int l,r;
		char c;
		cin>>l>>r>>c;
		--l,--r;
		upd(1,0,n-1,l,r,mp[c]);
		if(cnt[seg[1].sum]){
			cout<<"Yes\n";
		}
		else cout<<"No\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 7876 KB Output is correct
2 Correct 233 ms 8532 KB Output is correct
3 Correct 161 ms 3664 KB Output is correct
4 Correct 181 ms 8476 KB Output is correct
5 Correct 228 ms 8576 KB Output is correct
6 Correct 165 ms 7872 KB Output is correct
7 Correct 212 ms 8192 KB Output is correct
8 Correct 199 ms 8680 KB Output is correct
9 Correct 221 ms 8404 KB Output is correct
10 Correct 268 ms 9576 KB Output is correct
11 Correct 196 ms 8900 KB Output is correct
12 Correct 199 ms 9548 KB Output is correct
13 Correct 220 ms 8908 KB Output is correct
14 Correct 227 ms 9568 KB Output is correct
15 Correct 233 ms 8980 KB Output is correct
16 Correct 235 ms 9496 KB Output is correct
17 Correct 191 ms 8944 KB Output is correct
18 Correct 138 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 7876 KB Output is correct
2 Correct 233 ms 8532 KB Output is correct
3 Correct 161 ms 3664 KB Output is correct
4 Correct 181 ms 8476 KB Output is correct
5 Correct 228 ms 8576 KB Output is correct
6 Correct 165 ms 7872 KB Output is correct
7 Correct 212 ms 8192 KB Output is correct
8 Correct 199 ms 8680 KB Output is correct
9 Correct 221 ms 8404 KB Output is correct
10 Correct 268 ms 9576 KB Output is correct
11 Correct 196 ms 8900 KB Output is correct
12 Correct 199 ms 9548 KB Output is correct
13 Correct 220 ms 8908 KB Output is correct
14 Correct 227 ms 9568 KB Output is correct
15 Correct 233 ms 8980 KB Output is correct
16 Correct 235 ms 9496 KB Output is correct
17 Correct 191 ms 8944 KB Output is correct
18 Correct 138 ms 2384 KB Output is correct
19 Correct 697 ms 15864 KB Output is correct
20 Correct 617 ms 16492 KB Output is correct
21 Correct 477 ms 17016 KB Output is correct
22 Correct 455 ms 15376 KB Output is correct
23 Correct 350 ms 10644 KB Output is correct
24 Correct 302 ms 9696 KB Output is correct
25 Correct 502 ms 17780 KB Output is correct
26 Correct 495 ms 16248 KB Output is correct
27 Correct 555 ms 17960 KB Output is correct
28 Correct 504 ms 16268 KB Output is correct
29 Correct 544 ms 17660 KB Output is correct
30 Correct 297 ms 10784 KB Output is correct
31 Correct 539 ms 17952 KB Output is correct
32 Correct 475 ms 15952 KB Output is correct
33 Correct 261 ms 9668 KB Output is correct
34 Correct 535 ms 16384 KB Output is correct
35 Correct 412 ms 15868 KB Output is correct
36 Correct 257 ms 9852 KB Output is correct
37 Correct 270 ms 9812 KB Output is correct
38 Correct 509 ms 14512 KB Output is correct
39 Correct 424 ms 13364 KB Output is correct
40 Correct 415 ms 13008 KB Output is correct
41 Correct 504 ms 9252 KB Output is correct
42 Correct 180 ms 9196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 7876 KB Output is correct
2 Correct 233 ms 8532 KB Output is correct
3 Correct 161 ms 3664 KB Output is correct
4 Correct 181 ms 8476 KB Output is correct
5 Correct 228 ms 8576 KB Output is correct
6 Correct 165 ms 7872 KB Output is correct
7 Correct 212 ms 8192 KB Output is correct
8 Correct 199 ms 8680 KB Output is correct
9 Correct 221 ms 8404 KB Output is correct
10 Correct 268 ms 9576 KB Output is correct
11 Correct 196 ms 8900 KB Output is correct
12 Correct 199 ms 9548 KB Output is correct
13 Correct 220 ms 8908 KB Output is correct
14 Correct 227 ms 9568 KB Output is correct
15 Correct 233 ms 8980 KB Output is correct
16 Correct 235 ms 9496 KB Output is correct
17 Correct 191 ms 8944 KB Output is correct
18 Correct 138 ms 2384 KB Output is correct
19 Correct 211 ms 8120 KB Output is correct
20 Correct 169 ms 3632 KB Output is correct
21 Correct 263 ms 9080 KB Output is correct
22 Correct 156 ms 7644 KB Output is correct
23 Correct 197 ms 9180 KB Output is correct
24 Correct 176 ms 8256 KB Output is correct
25 Correct 188 ms 9164 KB Output is correct
26 Correct 177 ms 8132 KB Output is correct
27 Correct 180 ms 9040 KB Output is correct
28 Correct 196 ms 8312 KB Output is correct
29 Correct 179 ms 8592 KB Output is correct
30 Correct 167 ms 7856 KB Output is correct
31 Correct 194 ms 9224 KB Output is correct
32 Correct 220 ms 9196 KB Output is correct
33 Correct 227 ms 8760 KB Output is correct
34 Correct 177 ms 8048 KB Output is correct
35 Correct 210 ms 9480 KB Output is correct
36 Correct 186 ms 9012 KB Output is correct
37 Correct 194 ms 9544 KB Output is correct
38 Correct 198 ms 8928 KB Output is correct
39 Correct 206 ms 9532 KB Output is correct
40 Correct 190 ms 8924 KB Output is correct
41 Correct 198 ms 9652 KB Output is correct
42 Correct 180 ms 9012 KB Output is correct
43 Correct 169 ms 8388 KB Output is correct
44 Correct 220 ms 8812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 7876 KB Output is correct
2 Correct 233 ms 8532 KB Output is correct
3 Correct 161 ms 3664 KB Output is correct
4 Correct 181 ms 8476 KB Output is correct
5 Correct 228 ms 8576 KB Output is correct
6 Correct 165 ms 7872 KB Output is correct
7 Correct 212 ms 8192 KB Output is correct
8 Correct 199 ms 8680 KB Output is correct
9 Correct 221 ms 8404 KB Output is correct
10 Correct 268 ms 9576 KB Output is correct
11 Correct 196 ms 8900 KB Output is correct
12 Correct 199 ms 9548 KB Output is correct
13 Correct 220 ms 8908 KB Output is correct
14 Correct 227 ms 9568 KB Output is correct
15 Correct 233 ms 8980 KB Output is correct
16 Correct 235 ms 9496 KB Output is correct
17 Correct 191 ms 8944 KB Output is correct
18 Correct 138 ms 2384 KB Output is correct
19 Correct 697 ms 15864 KB Output is correct
20 Correct 617 ms 16492 KB Output is correct
21 Correct 477 ms 17016 KB Output is correct
22 Correct 455 ms 15376 KB Output is correct
23 Correct 350 ms 10644 KB Output is correct
24 Correct 302 ms 9696 KB Output is correct
25 Correct 502 ms 17780 KB Output is correct
26 Correct 495 ms 16248 KB Output is correct
27 Correct 555 ms 17960 KB Output is correct
28 Correct 504 ms 16268 KB Output is correct
29 Correct 544 ms 17660 KB Output is correct
30 Correct 297 ms 10784 KB Output is correct
31 Correct 539 ms 17952 KB Output is correct
32 Correct 475 ms 15952 KB Output is correct
33 Correct 261 ms 9668 KB Output is correct
34 Correct 535 ms 16384 KB Output is correct
35 Correct 412 ms 15868 KB Output is correct
36 Correct 257 ms 9852 KB Output is correct
37 Correct 270 ms 9812 KB Output is correct
38 Correct 509 ms 14512 KB Output is correct
39 Correct 424 ms 13364 KB Output is correct
40 Correct 415 ms 13008 KB Output is correct
41 Correct 504 ms 9252 KB Output is correct
42 Correct 180 ms 9196 KB Output is correct
43 Correct 211 ms 8120 KB Output is correct
44 Correct 169 ms 3632 KB Output is correct
45 Correct 263 ms 9080 KB Output is correct
46 Correct 156 ms 7644 KB Output is correct
47 Correct 197 ms 9180 KB Output is correct
48 Correct 176 ms 8256 KB Output is correct
49 Correct 188 ms 9164 KB Output is correct
50 Correct 177 ms 8132 KB Output is correct
51 Correct 180 ms 9040 KB Output is correct
52 Correct 196 ms 8312 KB Output is correct
53 Correct 179 ms 8592 KB Output is correct
54 Correct 167 ms 7856 KB Output is correct
55 Correct 194 ms 9224 KB Output is correct
56 Correct 220 ms 9196 KB Output is correct
57 Correct 227 ms 8760 KB Output is correct
58 Correct 177 ms 8048 KB Output is correct
59 Correct 210 ms 9480 KB Output is correct
60 Correct 186 ms 9012 KB Output is correct
61 Correct 194 ms 9544 KB Output is correct
62 Correct 198 ms 8928 KB Output is correct
63 Correct 206 ms 9532 KB Output is correct
64 Correct 190 ms 8924 KB Output is correct
65 Correct 198 ms 9652 KB Output is correct
66 Correct 180 ms 9012 KB Output is correct
67 Correct 169 ms 8388 KB Output is correct
68 Correct 220 ms 8812 KB Output is correct
69 Correct 607 ms 14952 KB Output is correct
70 Correct 629 ms 16440 KB Output is correct
71 Correct 283 ms 9924 KB Output is correct
72 Correct 264 ms 9840 KB Output is correct
73 Correct 292 ms 9756 KB Output is correct
74 Correct 444 ms 16496 KB Output is correct
75 Correct 301 ms 10676 KB Output is correct
76 Correct 522 ms 17600 KB Output is correct
77 Correct 457 ms 15496 KB Output is correct
78 Correct 272 ms 9800 KB Output is correct
79 Correct 264 ms 9824 KB Output is correct
80 Correct 420 ms 15952 KB Output is correct
81 Correct 287 ms 10720 KB Output is correct
82 Correct 566 ms 17692 KB Output is correct
83 Correct 500 ms 15836 KB Output is correct
84 Correct 300 ms 9776 KB Output is correct
85 Correct 264 ms 9772 KB Output is correct
86 Correct 466 ms 15284 KB Output is correct
87 Correct 520 ms 16124 KB Output is correct
88 Correct 273 ms 9264 KB Output is correct
89 Correct 450 ms 15668 KB Output is correct
90 Correct 504 ms 16416 KB Output is correct
91 Correct 288 ms 9244 KB Output is correct
92 Correct 457 ms 15976 KB Output is correct
93 Correct 276 ms 9816 KB Output is correct
94 Correct 287 ms 9748 KB Output is correct
95 Correct 262 ms 9812 KB Output is correct
96 Correct 502 ms 14584 KB Output is correct
97 Correct 430 ms 14524 KB Output is correct
98 Incorrect 439 ms 13004 KB Output isn't correct
99 Halted 0 ms 0 KB -