Submission #419694

# Submission time Handle Problem Language Result Execution time Memory
419694 2021-06-07T11:40:19 Z zaneyu Crossing (JOI21_crossing) C++14
0 / 100
190 ms 8536 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+9;
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]);
	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";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 167 ms 7868 KB Output is correct
2 Correct 190 ms 8536 KB Output is correct
3 Correct 182 ms 3644 KB Output is correct
4 Incorrect 171 ms 8464 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 167 ms 7868 KB Output is correct
2 Correct 190 ms 8536 KB Output is correct
3 Correct 182 ms 3644 KB Output is correct
4 Incorrect 171 ms 8464 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 167 ms 7868 KB Output is correct
2 Correct 190 ms 8536 KB Output is correct
3 Correct 182 ms 3644 KB Output is correct
4 Incorrect 171 ms 8464 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 167 ms 7868 KB Output is correct
2 Correct 190 ms 8536 KB Output is correct
3 Correct 182 ms 3644 KB Output is correct
4 Incorrect 171 ms 8464 KB Output isn't correct
5 Halted 0 ms 0 KB -