Submission #422411

#TimeUsernameProblemLanguageResultExecution timeMemory
422411Return_0Crossing (JOI21_crossing)C++17
100 / 100
506 ms38856 KiB
#pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")

#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 long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); cout.flush();
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< (x) << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()

cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;

template <class A,class B> ostream& operator << (ostream& out,const pair<A,B>&a){return out<<'('<<a.first<<", "<<a.second<<')';}
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out<< '['; for (int i = -1; ++i < int(a.size());) out<< a[i] << (i + 1 < int(a.size()) ? ", " : ""); return out<<']'; }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 2e5 + 7, md[2] = {1610612741, 1100000123};

struct Hash {
	ll x, y;
	inline Hash (cl &_x = 0, cl &_y = 0) : x(_x), y(_y) {}
	inline ll operator ()(Hash a) const { return x * 31LL + y; }
	friend bool operator < (const Hash &a, const Hash &b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
	friend bool operator == (const Hash &a, const Hash &b) { return (a.x == b.x && a.y == b.y); }
	friend Hash operator * (const Hash &a, cl &b) { return Hash((a.x * b) % md[0], (a.y * b) % md[1]); }
	friend Hash operator + (const Hash &a, cl &b) { return Hash((a.x + b) % md[0], (a.y + b) % md[1]); }
	friend Hash operator + (const Hash &a, const Hash &b) { return Hash((a.x + b.x) % md[0], (a.y + b.y) % md[1]); }
	friend Hash operator * (const Hash &a, const Hash &b) { return Hash((a.x * b.x) % md[0], (a.y * b.y) % md[1]); }
	friend Hash operator - (const Hash &a, const Hash &b) { return Hash((a.x - b.x + md[0]) % md[0], (a.y - b.y + md[1]) % md[1]); }
} base (5, 53), pw [N], hs [N];

inline Hash hstr (const vector <ll> &vec) {
	Hash ret;
	for (auto &x : vec) ret = (ret * base) + (x + 1);
	return ret;
}

inline vector <ll> f (const vector <ll> &v1, const vector <ll> &v2) {
	vector <ll> ret (SZ(v1), 0);
	for (ll i = 0; i < SZ(v1); i++) ret[i] = 2 * (v1[i] + v2[i]) % 3;
	return ret;
}

ll n, q;
string S;
vector <ll> s [3], t;
unordered_set <Hash, Hash> st;

struct segtree {
	ll l, r, lz;
	Hash h;
	segtree *lt, *rt;
	inline segtree (cl &L = 0, cl &R = N - 2) : l(L), r(R), lz(0) {}

	inline void node_upd () { h = (lt->h * pw[r - rt->l]) + rt->h; }

	void build () {
		if (r - l == 1) { h = hs[1] * (t[l] + 1); return; }
		lt = new segtree (l, mid);
		rt = new segtree (mid, r);
		lt->build();
		rt->build();
		node_upd();
	}

	inline void push (cl &x) { h = hs[r - l] * x; lz = x; }
	inline void shift () { if (lz) { lt->push(lz); rt->push(lz); lz = 0; } }

	void upd (cl &ql, cl &qr, cl &x) {
		if (r <= ql || qr <= l) return;
		if (ql <= l && r <= qr) { push(x); return; }
		shift();
		lt->upd(ql, qr, x);
		rt->upd(ql, qr, x);
		node_upd();
	}
} seg;

int main ()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	pw[0] = Hash(1, 1); for (ll i = 1; i < N; i++) pw[i] = pw[i - 1] * base;
	hs[1] = Hash(1, 1); for (ll i = 1; i < N; i++) hs[i] = (hs[i - 1] * base) + 1;

	cin>> n;

	auto convert = [&](const string &str) {
		vector <ll> ret (SZ(str), 0);
		for (ll i = 0; i < n; i++) ret[i] = 2 * (str[i] == 'J') + (str[i] == 'O');
		return ret;
	};
	
	for (ll i = 0; i < 3; i++) cin>> S, s[i] = convert(S);

	st.insert(hstr(	s[0]					));
	st.insert(hstr( s[1]					));
	st.insert(hstr( s[2]					));
	st.insert(hstr( f(s[0], s[1]) 			));
	st.insert(hstr( f(s[0], s[2]) 			));
	st.insert(hstr( f(s[1], s[2]) 			));
	st.insert(hstr( f(f(s[0], s[1]), s[2]) 	));
	st.insert(hstr( f(f(s[0], s[2]), s[1])	));
	st.insert(hstr( f(f(s[1], s[2]), s[0]) 	));

	cin>> q >> S;
	t = convert(S);
	seg.r = n; seg.build();

	cout<< (st.count(seg.h) ? "Yes\n" : "No\n");
	for (ll l, r; q--;) {
		char c;
		cin>> l >> r >> c; l--;
		seg.upd(l, r, 2 * (c == 'J') + (c == 'O') + 1);
		cout<< (st.count(seg.h) ? "Yes\n" : "No\n");
	}

	cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}
/*
4
JOJO
JJOI
OJOO
3
IJOJ
1 4 O
2 2 J
2 4 I

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...