Submission #422411

# Submission time Handle Problem Language Result Execution time Memory
422411 2021-06-10T05:58:02 Z Return_0 Crossing (JOI21_crossing) C++17
100 / 100
506 ms 38856 KB
#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 time Memory Grader output
1 Correct 91 ms 7116 KB Output is correct
2 Correct 99 ms 7088 KB Output is correct
3 Correct 102 ms 7068 KB Output is correct
4 Correct 85 ms 7108 KB Output is correct
5 Correct 82 ms 7052 KB Output is correct
6 Correct 83 ms 7116 KB Output is correct
7 Correct 107 ms 7108 KB Output is correct
8 Correct 85 ms 7076 KB Output is correct
9 Correct 95 ms 7156 KB Output is correct
10 Correct 86 ms 7084 KB Output is correct
11 Correct 88 ms 7152 KB Output is correct
12 Correct 87 ms 7180 KB Output is correct
13 Correct 90 ms 7076 KB Output is correct
14 Correct 87 ms 7168 KB Output is correct
15 Correct 91 ms 7164 KB Output is correct
16 Correct 91 ms 7108 KB Output is correct
17 Correct 88 ms 7168 KB Output is correct
18 Correct 109 ms 7220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 7116 KB Output is correct
2 Correct 99 ms 7088 KB Output is correct
3 Correct 102 ms 7068 KB Output is correct
4 Correct 85 ms 7108 KB Output is correct
5 Correct 82 ms 7052 KB Output is correct
6 Correct 83 ms 7116 KB Output is correct
7 Correct 107 ms 7108 KB Output is correct
8 Correct 85 ms 7076 KB Output is correct
9 Correct 95 ms 7156 KB Output is correct
10 Correct 86 ms 7084 KB Output is correct
11 Correct 88 ms 7152 KB Output is correct
12 Correct 87 ms 7180 KB Output is correct
13 Correct 90 ms 7076 KB Output is correct
14 Correct 87 ms 7168 KB Output is correct
15 Correct 91 ms 7164 KB Output is correct
16 Correct 91 ms 7108 KB Output is correct
17 Correct 88 ms 7168 KB Output is correct
18 Correct 109 ms 7220 KB Output is correct
19 Correct 394 ms 38648 KB Output is correct
20 Correct 338 ms 38680 KB Output is correct
21 Correct 354 ms 36676 KB Output is correct
22 Correct 282 ms 33652 KB Output is correct
23 Correct 192 ms 8736 KB Output is correct
24 Correct 145 ms 8664 KB Output is correct
25 Correct 391 ms 38684 KB Output is correct
26 Correct 323 ms 38572 KB Output is correct
27 Correct 506 ms 38596 KB Output is correct
28 Correct 374 ms 38684 KB Output is correct
29 Correct 337 ms 37716 KB Output is correct
30 Correct 154 ms 8764 KB Output is correct
31 Correct 371 ms 38624 KB Output is correct
32 Correct 335 ms 35844 KB Output is correct
33 Correct 160 ms 8716 KB Output is correct
34 Correct 390 ms 38688 KB Output is correct
35 Correct 310 ms 30488 KB Output is correct
36 Correct 146 ms 8660 KB Output is correct
37 Correct 142 ms 8676 KB Output is correct
38 Correct 321 ms 38680 KB Output is correct
39 Correct 238 ms 38684 KB Output is correct
40 Correct 309 ms 27808 KB Output is correct
41 Correct 490 ms 38856 KB Output is correct
42 Correct 129 ms 38768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 7116 KB Output is correct
2 Correct 99 ms 7088 KB Output is correct
3 Correct 102 ms 7068 KB Output is correct
4 Correct 85 ms 7108 KB Output is correct
5 Correct 82 ms 7052 KB Output is correct
6 Correct 83 ms 7116 KB Output is correct
7 Correct 107 ms 7108 KB Output is correct
8 Correct 85 ms 7076 KB Output is correct
9 Correct 95 ms 7156 KB Output is correct
10 Correct 86 ms 7084 KB Output is correct
11 Correct 88 ms 7152 KB Output is correct
12 Correct 87 ms 7180 KB Output is correct
13 Correct 90 ms 7076 KB Output is correct
14 Correct 87 ms 7168 KB Output is correct
15 Correct 91 ms 7164 KB Output is correct
16 Correct 91 ms 7108 KB Output is correct
17 Correct 88 ms 7168 KB Output is correct
18 Correct 109 ms 7220 KB Output is correct
19 Correct 102 ms 7108 KB Output is correct
20 Correct 106 ms 7108 KB Output is correct
21 Correct 92 ms 7144 KB Output is correct
22 Correct 136 ms 7084 KB Output is correct
23 Correct 87 ms 7112 KB Output is correct
24 Correct 89 ms 7108 KB Output is correct
25 Correct 119 ms 7148 KB Output is correct
26 Correct 85 ms 7112 KB Output is correct
27 Correct 110 ms 7184 KB Output is correct
28 Correct 81 ms 7120 KB Output is correct
29 Correct 158 ms 7108 KB Output is correct
30 Correct 83 ms 7084 KB Output is correct
31 Correct 124 ms 7200 KB Output is correct
32 Correct 145 ms 7204 KB Output is correct
33 Correct 135 ms 7072 KB Output is correct
34 Correct 86 ms 7108 KB Output is correct
35 Correct 99 ms 7064 KB Output is correct
36 Correct 114 ms 7076 KB Output is correct
37 Correct 98 ms 7148 KB Output is correct
38 Correct 136 ms 7220 KB Output is correct
39 Correct 129 ms 7108 KB Output is correct
40 Correct 126 ms 7176 KB Output is correct
41 Correct 99 ms 7088 KB Output is correct
42 Correct 97 ms 7136 KB Output is correct
43 Correct 92 ms 7080 KB Output is correct
44 Correct 116 ms 7188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 7116 KB Output is correct
2 Correct 99 ms 7088 KB Output is correct
3 Correct 102 ms 7068 KB Output is correct
4 Correct 85 ms 7108 KB Output is correct
5 Correct 82 ms 7052 KB Output is correct
6 Correct 83 ms 7116 KB Output is correct
7 Correct 107 ms 7108 KB Output is correct
8 Correct 85 ms 7076 KB Output is correct
9 Correct 95 ms 7156 KB Output is correct
10 Correct 86 ms 7084 KB Output is correct
11 Correct 88 ms 7152 KB Output is correct
12 Correct 87 ms 7180 KB Output is correct
13 Correct 90 ms 7076 KB Output is correct
14 Correct 87 ms 7168 KB Output is correct
15 Correct 91 ms 7164 KB Output is correct
16 Correct 91 ms 7108 KB Output is correct
17 Correct 88 ms 7168 KB Output is correct
18 Correct 109 ms 7220 KB Output is correct
19 Correct 394 ms 38648 KB Output is correct
20 Correct 338 ms 38680 KB Output is correct
21 Correct 354 ms 36676 KB Output is correct
22 Correct 282 ms 33652 KB Output is correct
23 Correct 192 ms 8736 KB Output is correct
24 Correct 145 ms 8664 KB Output is correct
25 Correct 391 ms 38684 KB Output is correct
26 Correct 323 ms 38572 KB Output is correct
27 Correct 506 ms 38596 KB Output is correct
28 Correct 374 ms 38684 KB Output is correct
29 Correct 337 ms 37716 KB Output is correct
30 Correct 154 ms 8764 KB Output is correct
31 Correct 371 ms 38624 KB Output is correct
32 Correct 335 ms 35844 KB Output is correct
33 Correct 160 ms 8716 KB Output is correct
34 Correct 390 ms 38688 KB Output is correct
35 Correct 310 ms 30488 KB Output is correct
36 Correct 146 ms 8660 KB Output is correct
37 Correct 142 ms 8676 KB Output is correct
38 Correct 321 ms 38680 KB Output is correct
39 Correct 238 ms 38684 KB Output is correct
40 Correct 309 ms 27808 KB Output is correct
41 Correct 490 ms 38856 KB Output is correct
42 Correct 129 ms 38768 KB Output is correct
43 Correct 102 ms 7108 KB Output is correct
44 Correct 106 ms 7108 KB Output is correct
45 Correct 92 ms 7144 KB Output is correct
46 Correct 136 ms 7084 KB Output is correct
47 Correct 87 ms 7112 KB Output is correct
48 Correct 89 ms 7108 KB Output is correct
49 Correct 119 ms 7148 KB Output is correct
50 Correct 85 ms 7112 KB Output is correct
51 Correct 110 ms 7184 KB Output is correct
52 Correct 81 ms 7120 KB Output is correct
53 Correct 158 ms 7108 KB Output is correct
54 Correct 83 ms 7084 KB Output is correct
55 Correct 124 ms 7200 KB Output is correct
56 Correct 145 ms 7204 KB Output is correct
57 Correct 135 ms 7072 KB Output is correct
58 Correct 86 ms 7108 KB Output is correct
59 Correct 99 ms 7064 KB Output is correct
60 Correct 114 ms 7076 KB Output is correct
61 Correct 98 ms 7148 KB Output is correct
62 Correct 136 ms 7220 KB Output is correct
63 Correct 129 ms 7108 KB Output is correct
64 Correct 126 ms 7176 KB Output is correct
65 Correct 99 ms 7088 KB Output is correct
66 Correct 97 ms 7136 KB Output is correct
67 Correct 92 ms 7080 KB Output is correct
68 Correct 116 ms 7188 KB Output is correct
69 Correct 349 ms 33484 KB Output is correct
70 Correct 344 ms 38652 KB Output is correct
71 Correct 147 ms 8660 KB Output is correct
72 Correct 148 ms 8804 KB Output is correct
73 Correct 150 ms 8820 KB Output is correct
74 Correct 268 ms 33308 KB Output is correct
75 Correct 143 ms 8708 KB Output is correct
76 Correct 300 ms 38680 KB Output is correct
77 Correct 283 ms 33444 KB Output is correct
78 Correct 151 ms 8724 KB Output is correct
79 Correct 180 ms 8884 KB Output is correct
80 Correct 251 ms 29648 KB Output is correct
81 Correct 150 ms 8692 KB Output is correct
82 Correct 296 ms 38680 KB Output is correct
83 Correct 297 ms 36756 KB Output is correct
84 Correct 157 ms 8676 KB Output is correct
85 Correct 187 ms 8656 KB Output is correct
86 Correct 327 ms 31048 KB Output is correct
87 Correct 347 ms 38620 KB Output is correct
88 Correct 162 ms 8792 KB Output is correct
89 Correct 319 ms 34824 KB Output is correct
90 Correct 324 ms 38684 KB Output is correct
91 Correct 163 ms 8644 KB Output is correct
92 Correct 264 ms 30656 KB Output is correct
93 Correct 155 ms 8708 KB Output is correct
94 Correct 157 ms 8808 KB Output is correct
95 Correct 161 ms 8700 KB Output is correct
96 Correct 294 ms 38668 KB Output is correct
97 Correct 384 ms 38724 KB Output is correct
98 Correct 275 ms 27844 KB Output is correct
99 Correct 457 ms 38776 KB Output is correct
100 Correct 127 ms 38832 KB Output is correct