// EXPLOSION!
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<chrono>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define cont continue
#define endl '\n'
//#define ednl '\n'
#define test int testc;cin>>testc;while(testc--)
#define pr(a, b) trav(x,a)cerr << x << b; cerr << endl;
#define message cout << "Hello World" << endl;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4000000000000000000LL;
const ll inf = 1000000007;//998244353
void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) {
F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; }
}void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; }
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef arwaeystoamneg
if (sz(s))
{
freopen((s + ".in").c_str(), "r", stdin);
if (s != "test1")
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
}
template<int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
mint() { v = 0; }
mint(ll _v) {
v = int((-MOD < _v&& _v < MOD) ? _v : _v % MOD);
if (v < 0) v += MOD;
}
friend bool operator==(const mint& a, const mint& b) {
return a.v == b.v;
}
friend bool operator!=(const mint& a, const mint& b) {
return !(a == b);
}
friend bool operator<(const mint& a, const mint& b) {
return a.v < b.v;
}
mint& operator+=(const mint& m) {
if ((v += m.v) >= MOD) v -= MOD;
return *this;
}
mint& operator-=(const mint& m) {
if ((v -= m.v) < 0) v += MOD;
return *this;
}
mint& operator*=(const mint& m) {
v = int((ll)v * m.v % MOD); return *this;
}
mint& operator/=(const mint& m) { return (*this) *= inv(m); }
friend mint power(mint a, ll p) {// MAKE SURE YOU ARE USING THE CORRECT VERSION OF POW!!!!!!!!
mint ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
return ans;
}
friend mint inv(const mint& a) {
assert(a.v != 0);
return power(a, MOD - 2);
}
mint operator-() const { return mint(-v); }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
};
typedef mint<inf, 5> mi; // 5 is primitive root for both common mods
map<char, int>key = { {'J',1},{'O',2},{'I',3} };
const int MAX = 200006;
mi base1 = 5, base2 = 7;
mi power1[MAX], power2[MAX];
struct T
{
int len;
mi h1, h2;
T()
{
h1 = h2 = len = 0;
}
T(int x)
{
len = 1;
h1 = h2 = x;
}
T operator+(const T& x)const
{
T ans;
ans.len = len + x.len;
ans.h1 = power1[len] * x.h1 + h1;
ans.h2 = power2[len] * x.h2 + h2;
return ans;
}
bool operator<(const T& x)const
{
if (x.len == len)
{
if (h1 == x.h1)
{
return (int)h2 < (int)x.h2;
}
return (int)h1 < (int)x.h1;
}
return len < x.len;
}
};
int n, q;
int a[MAX], b[MAX], c[MAX], t[MAX];
int ans[MAX], temp[MAX];
int get(int x, int y)
{
return (x == y ? x : 6 - x - y);
}
void cross(int* a, int* b)
{
int ptr = 0;
F0R(i, n)
{
ans[ptr++] = (get(a[i], b[i]));
}
}
void init(int* a)
{
string in;
cin >> in;
F0R(i, n)a[i] = key[in[i]];
}
T get(int* a)
{
T ans;
F0R(i, n)
{
ans = ans + a[i];
}
return ans;
}
set<T>res;
T base[MAX];
class segment_tree_lazy
{
struct item
{
T h;
int update;
};
item single(int i)
{
return { i,0 };
}
item merge(item x, item y)
{
item ans;
ans.update = 0;
ans.h = x.h + y.h;
return ans;
}
vector<item> tree;
vector<item>A;
int height;
item neutral = { T(),0 };
void push(int i, int tl, int tr)
{
if (tree[i].update)
{
tree[i].h.len = base[tree[i].h.len].len;
tree[i].h.h1 = base[tree[i].h.len].h1 * tree[i].update;
tree[i].h.h2 = base[tree[i].h.len].h2 * tree[i].update;
if (tl != tr)
{
tree[2 * i + 1].update = tree[i].update;
tree[2 * i + 2].update = tree[i].update;
}
tree[i].update = 0;
}
}
public:void build(vll& B)
{
int n = B.size();
height = log2(n - 1) + 1;
A.rsz(n);
tree.rsz((1 << height + 1) - 1);
F0R(i, n)A[i] = single(B[i]);
A.rsz(1 << height, neutral);
build(A, 0, 0, (1 << height) - 1);
}
void build(vector<item>& A, int v, int tl, int tr)
{
if (tl == tr)
tree[v] = A[tl];
else
{
int mid = (tl + tr) / 2;
build(A, 2 * v + 1, tl, mid);
build(A, 2 * v + 2, mid + 1, tr);
tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
}
public:T query(int l, int r)
{
return query(0, 0, (1 << height) - 1, l, r).h;
}
item query(int v, int tl, int tr, int l, int r)
{
if (r<tl || l>tr)return neutral;
push(v, tl, tr);
if (l <= tl && r >= tr)
{
return tree[v];
}
int mid = (tl + tr) / 2;
return merge(query(2 * v + 1, tl, mid, l, r), query(2 * v + 2, mid + 1, tr, l, r));
}
public:void update(int l, int r, int val)
{
update(0, 0, (1 << height) - 1, l, r, val);
}
void update(int v, int tl, int tr, int l, int r, int val)
{
push(v, tl, tr);
if (tl > r || tr < l)return;
if (tl >= l && tr <= r)
{
tree[v].update = val;
push(v, tl, tr);
//tree[v].sum = ((ll)tr - tl + 1) * val;
}
else
{
int mid = (tl + tr) / 2;
update(2 * v + 1, tl, mid, l, r, val);
update(2 * v + 2, mid + 1, tr, l, r, val);
tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
}
};
int main()
{
setIO("test1");
cin >> n;
init(a);
init(b);
init(c);
cin >> q;
init(t);
power1[0] = 1;
F0R(i, n + 1)power1[i + 1] = power1[i] * base1;
power2[0] = 1;
F0R(i, n + 1)power2[i + 1] = power2[i] * base2;
res.insert(get(a));
res.insert(get(b));
res.insert(get(c));
cross(a, b);
res.insert(get(ans));
F0R(i, n)temp[i] = ans[i];
cross(temp, c);
res.insert(get(ans));
cross(a, c);
res.insert(get(ans));
F0R(i, n)temp[i] = ans[i];
cross(temp, b);
res.insert(get(ans));
cross(b, c);
res.insert(get(ans));
F0R(i, n)temp[i] = ans[i];
cross(temp, a);
res.insert(get(ans));
T tempor = T();
F0R(i, n + 3)
{
base[i] = tempor;
tempor = tempor + 1;
}
segment_tree_lazy st;
vll tempo(n);
F0R(i, n)tempo[i] = t[i];
st.build(tempo);
T hash = st.query(0, n - 1);
cout << (res.find(hash) == res.end() ? "No" : "Yes") << endl;
while (q--)
{
int l, r;
char t;
cin >> l >> r >> t;
int x = key[t];
l--, r--;
T temp = st.query(l, r);
hash.h1 -= temp.h1 * power1[l];
hash.h2 -= temp.h2 * power2[l];
st.update(l, r, x);
temp = st.query(l, r);
hash.h1 += temp.h1 * power1[l];
hash.h2 += temp.h2 * power2[l];
cout << (res.find(hash) == res.end() ? "No" : "Yes") << endl;
}
}
Compilation message
Main.cpp: In member function 'void segment_tree_lazy::build(vll&)':
Main.cpp:219:24: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
219 | tree.rsz((1 << height + 1) - 1);
| ~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
4768 KB |
Output is correct |
2 |
Correct |
239 ms |
4932 KB |
Output is correct |
3 |
Correct |
255 ms |
4836 KB |
Output is correct |
4 |
Correct |
204 ms |
4888 KB |
Output is correct |
5 |
Correct |
198 ms |
4820 KB |
Output is correct |
6 |
Correct |
190 ms |
4708 KB |
Output is correct |
7 |
Correct |
209 ms |
4756 KB |
Output is correct |
8 |
Correct |
238 ms |
4828 KB |
Output is correct |
9 |
Correct |
206 ms |
4852 KB |
Output is correct |
10 |
Correct |
202 ms |
4836 KB |
Output is correct |
11 |
Correct |
206 ms |
4788 KB |
Output is correct |
12 |
Correct |
206 ms |
4840 KB |
Output is correct |
13 |
Correct |
207 ms |
4804 KB |
Output is correct |
14 |
Correct |
203 ms |
4844 KB |
Output is correct |
15 |
Correct |
208 ms |
4772 KB |
Output is correct |
16 |
Correct |
211 ms |
4832 KB |
Output is correct |
17 |
Correct |
206 ms |
4764 KB |
Output is correct |
18 |
Correct |
246 ms |
4860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
4768 KB |
Output is correct |
2 |
Correct |
239 ms |
4932 KB |
Output is correct |
3 |
Correct |
255 ms |
4836 KB |
Output is correct |
4 |
Correct |
204 ms |
4888 KB |
Output is correct |
5 |
Correct |
198 ms |
4820 KB |
Output is correct |
6 |
Correct |
190 ms |
4708 KB |
Output is correct |
7 |
Correct |
209 ms |
4756 KB |
Output is correct |
8 |
Correct |
238 ms |
4828 KB |
Output is correct |
9 |
Correct |
206 ms |
4852 KB |
Output is correct |
10 |
Correct |
202 ms |
4836 KB |
Output is correct |
11 |
Correct |
206 ms |
4788 KB |
Output is correct |
12 |
Correct |
206 ms |
4840 KB |
Output is correct |
13 |
Correct |
207 ms |
4804 KB |
Output is correct |
14 |
Correct |
203 ms |
4844 KB |
Output is correct |
15 |
Correct |
208 ms |
4772 KB |
Output is correct |
16 |
Correct |
211 ms |
4832 KB |
Output is correct |
17 |
Correct |
206 ms |
4764 KB |
Output is correct |
18 |
Correct |
246 ms |
4860 KB |
Output is correct |
19 |
Correct |
822 ms |
26344 KB |
Output is correct |
20 |
Correct |
886 ms |
26276 KB |
Output is correct |
21 |
Correct |
510 ms |
25676 KB |
Output is correct |
22 |
Correct |
520 ms |
24820 KB |
Output is correct |
23 |
Correct |
367 ms |
5916 KB |
Output is correct |
24 |
Correct |
365 ms |
5884 KB |
Output is correct |
25 |
Correct |
655 ms |
26268 KB |
Output is correct |
26 |
Correct |
584 ms |
26300 KB |
Output is correct |
27 |
Correct |
693 ms |
26276 KB |
Output is correct |
28 |
Correct |
652 ms |
26228 KB |
Output is correct |
29 |
Correct |
626 ms |
26008 KB |
Output is correct |
30 |
Correct |
410 ms |
5872 KB |
Output is correct |
31 |
Correct |
646 ms |
26280 KB |
Output is correct |
32 |
Correct |
625 ms |
25464 KB |
Output is correct |
33 |
Correct |
367 ms |
5908 KB |
Output is correct |
34 |
Correct |
618 ms |
26356 KB |
Output is correct |
35 |
Correct |
567 ms |
23960 KB |
Output is correct |
36 |
Correct |
365 ms |
5924 KB |
Output is correct |
37 |
Correct |
361 ms |
5924 KB |
Output is correct |
38 |
Correct |
810 ms |
26280 KB |
Output is correct |
39 |
Correct |
422 ms |
26232 KB |
Output is correct |
40 |
Correct |
534 ms |
15344 KB |
Output is correct |
41 |
Correct |
973 ms |
26272 KB |
Output is correct |
42 |
Correct |
295 ms |
26252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
4768 KB |
Output is correct |
2 |
Correct |
239 ms |
4932 KB |
Output is correct |
3 |
Correct |
255 ms |
4836 KB |
Output is correct |
4 |
Correct |
204 ms |
4888 KB |
Output is correct |
5 |
Correct |
198 ms |
4820 KB |
Output is correct |
6 |
Correct |
190 ms |
4708 KB |
Output is correct |
7 |
Correct |
209 ms |
4756 KB |
Output is correct |
8 |
Correct |
238 ms |
4828 KB |
Output is correct |
9 |
Correct |
206 ms |
4852 KB |
Output is correct |
10 |
Correct |
202 ms |
4836 KB |
Output is correct |
11 |
Correct |
206 ms |
4788 KB |
Output is correct |
12 |
Correct |
206 ms |
4840 KB |
Output is correct |
13 |
Correct |
207 ms |
4804 KB |
Output is correct |
14 |
Correct |
203 ms |
4844 KB |
Output is correct |
15 |
Correct |
208 ms |
4772 KB |
Output is correct |
16 |
Correct |
211 ms |
4832 KB |
Output is correct |
17 |
Correct |
206 ms |
4764 KB |
Output is correct |
18 |
Correct |
246 ms |
4860 KB |
Output is correct |
19 |
Correct |
224 ms |
4804 KB |
Output is correct |
20 |
Correct |
256 ms |
4928 KB |
Output is correct |
21 |
Correct |
206 ms |
4772 KB |
Output is correct |
22 |
Correct |
187 ms |
4736 KB |
Output is correct |
23 |
Correct |
204 ms |
4812 KB |
Output is correct |
24 |
Correct |
197 ms |
4720 KB |
Output is correct |
25 |
Correct |
205 ms |
4804 KB |
Output is correct |
26 |
Correct |
196 ms |
4848 KB |
Output is correct |
27 |
Correct |
208 ms |
4780 KB |
Output is correct |
28 |
Correct |
194 ms |
4972 KB |
Output is correct |
29 |
Correct |
207 ms |
4804 KB |
Output is correct |
30 |
Correct |
191 ms |
4788 KB |
Output is correct |
31 |
Correct |
212 ms |
4944 KB |
Output is correct |
32 |
Correct |
238 ms |
4828 KB |
Output is correct |
33 |
Correct |
207 ms |
4804 KB |
Output is correct |
34 |
Correct |
222 ms |
4884 KB |
Output is correct |
35 |
Correct |
207 ms |
4752 KB |
Output is correct |
36 |
Correct |
207 ms |
4856 KB |
Output is correct |
37 |
Correct |
212 ms |
4860 KB |
Output is correct |
38 |
Correct |
208 ms |
4844 KB |
Output is correct |
39 |
Correct |
251 ms |
4792 KB |
Output is correct |
40 |
Correct |
219 ms |
4804 KB |
Output is correct |
41 |
Correct |
203 ms |
4804 KB |
Output is correct |
42 |
Correct |
212 ms |
4844 KB |
Output is correct |
43 |
Correct |
200 ms |
4804 KB |
Output is correct |
44 |
Correct |
211 ms |
4828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
4768 KB |
Output is correct |
2 |
Correct |
239 ms |
4932 KB |
Output is correct |
3 |
Correct |
255 ms |
4836 KB |
Output is correct |
4 |
Correct |
204 ms |
4888 KB |
Output is correct |
5 |
Correct |
198 ms |
4820 KB |
Output is correct |
6 |
Correct |
190 ms |
4708 KB |
Output is correct |
7 |
Correct |
209 ms |
4756 KB |
Output is correct |
8 |
Correct |
238 ms |
4828 KB |
Output is correct |
9 |
Correct |
206 ms |
4852 KB |
Output is correct |
10 |
Correct |
202 ms |
4836 KB |
Output is correct |
11 |
Correct |
206 ms |
4788 KB |
Output is correct |
12 |
Correct |
206 ms |
4840 KB |
Output is correct |
13 |
Correct |
207 ms |
4804 KB |
Output is correct |
14 |
Correct |
203 ms |
4844 KB |
Output is correct |
15 |
Correct |
208 ms |
4772 KB |
Output is correct |
16 |
Correct |
211 ms |
4832 KB |
Output is correct |
17 |
Correct |
206 ms |
4764 KB |
Output is correct |
18 |
Correct |
246 ms |
4860 KB |
Output is correct |
19 |
Correct |
822 ms |
26344 KB |
Output is correct |
20 |
Correct |
886 ms |
26276 KB |
Output is correct |
21 |
Correct |
510 ms |
25676 KB |
Output is correct |
22 |
Correct |
520 ms |
24820 KB |
Output is correct |
23 |
Correct |
367 ms |
5916 KB |
Output is correct |
24 |
Correct |
365 ms |
5884 KB |
Output is correct |
25 |
Correct |
655 ms |
26268 KB |
Output is correct |
26 |
Correct |
584 ms |
26300 KB |
Output is correct |
27 |
Correct |
693 ms |
26276 KB |
Output is correct |
28 |
Correct |
652 ms |
26228 KB |
Output is correct |
29 |
Correct |
626 ms |
26008 KB |
Output is correct |
30 |
Correct |
410 ms |
5872 KB |
Output is correct |
31 |
Correct |
646 ms |
26280 KB |
Output is correct |
32 |
Correct |
625 ms |
25464 KB |
Output is correct |
33 |
Correct |
367 ms |
5908 KB |
Output is correct |
34 |
Correct |
618 ms |
26356 KB |
Output is correct |
35 |
Correct |
567 ms |
23960 KB |
Output is correct |
36 |
Correct |
365 ms |
5924 KB |
Output is correct |
37 |
Correct |
361 ms |
5924 KB |
Output is correct |
38 |
Correct |
810 ms |
26280 KB |
Output is correct |
39 |
Correct |
422 ms |
26232 KB |
Output is correct |
40 |
Correct |
534 ms |
15344 KB |
Output is correct |
41 |
Correct |
973 ms |
26272 KB |
Output is correct |
42 |
Correct |
295 ms |
26252 KB |
Output is correct |
43 |
Correct |
224 ms |
4804 KB |
Output is correct |
44 |
Correct |
256 ms |
4928 KB |
Output is correct |
45 |
Correct |
206 ms |
4772 KB |
Output is correct |
46 |
Correct |
187 ms |
4736 KB |
Output is correct |
47 |
Correct |
204 ms |
4812 KB |
Output is correct |
48 |
Correct |
197 ms |
4720 KB |
Output is correct |
49 |
Correct |
205 ms |
4804 KB |
Output is correct |
50 |
Correct |
196 ms |
4848 KB |
Output is correct |
51 |
Correct |
208 ms |
4780 KB |
Output is correct |
52 |
Correct |
194 ms |
4972 KB |
Output is correct |
53 |
Correct |
207 ms |
4804 KB |
Output is correct |
54 |
Correct |
191 ms |
4788 KB |
Output is correct |
55 |
Correct |
212 ms |
4944 KB |
Output is correct |
56 |
Correct |
238 ms |
4828 KB |
Output is correct |
57 |
Correct |
207 ms |
4804 KB |
Output is correct |
58 |
Correct |
222 ms |
4884 KB |
Output is correct |
59 |
Correct |
207 ms |
4752 KB |
Output is correct |
60 |
Correct |
207 ms |
4856 KB |
Output is correct |
61 |
Correct |
212 ms |
4860 KB |
Output is correct |
62 |
Correct |
208 ms |
4844 KB |
Output is correct |
63 |
Correct |
251 ms |
4792 KB |
Output is correct |
64 |
Correct |
219 ms |
4804 KB |
Output is correct |
65 |
Correct |
203 ms |
4804 KB |
Output is correct |
66 |
Correct |
212 ms |
4844 KB |
Output is correct |
67 |
Correct |
200 ms |
4804 KB |
Output is correct |
68 |
Correct |
211 ms |
4828 KB |
Output is correct |
69 |
Correct |
739 ms |
24700 KB |
Output is correct |
70 |
Correct |
882 ms |
26272 KB |
Output is correct |
71 |
Correct |
365 ms |
5924 KB |
Output is correct |
72 |
Correct |
366 ms |
5900 KB |
Output is correct |
73 |
Correct |
363 ms |
6004 KB |
Output is correct |
74 |
Correct |
492 ms |
24700 KB |
Output is correct |
75 |
Correct |
363 ms |
5932 KB |
Output is correct |
76 |
Correct |
532 ms |
26352 KB |
Output is correct |
77 |
Correct |
530 ms |
24712 KB |
Output is correct |
78 |
Correct |
360 ms |
5864 KB |
Output is correct |
79 |
Correct |
387 ms |
5920 KB |
Output is correct |
80 |
Correct |
544 ms |
23272 KB |
Output is correct |
81 |
Correct |
371 ms |
5896 KB |
Output is correct |
82 |
Correct |
579 ms |
26232 KB |
Output is correct |
83 |
Correct |
549 ms |
25640 KB |
Output is correct |
84 |
Correct |
366 ms |
6004 KB |
Output is correct |
85 |
Correct |
394 ms |
5916 KB |
Output is correct |
86 |
Correct |
623 ms |
24128 KB |
Output is correct |
87 |
Correct |
626 ms |
26232 KB |
Output is correct |
88 |
Correct |
409 ms |
5952 KB |
Output is correct |
89 |
Correct |
587 ms |
25236 KB |
Output is correct |
90 |
Correct |
718 ms |
26276 KB |
Output is correct |
91 |
Correct |
395 ms |
5924 KB |
Output is correct |
92 |
Correct |
519 ms |
23876 KB |
Output is correct |
93 |
Correct |
372 ms |
5832 KB |
Output is correct |
94 |
Correct |
367 ms |
5952 KB |
Output is correct |
95 |
Correct |
365 ms |
5896 KB |
Output is correct |
96 |
Correct |
791 ms |
26272 KB |
Output is correct |
97 |
Correct |
453 ms |
26272 KB |
Output is correct |
98 |
Correct |
532 ms |
15184 KB |
Output is correct |
99 |
Correct |
925 ms |
26276 KB |
Output is correct |
100 |
Correct |
296 ms |
26348 KB |
Output is correct |