#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define ms memset
#define fi first
#define se second
ll MOD = 1000000007;
ll A = 998244353;
ll power(ll base, ll n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n%2 == 0) return (halfn*halfn)%MOD;
return (((halfn*halfn)%MOD)*base) % MOD;
}
ll inverse(ll n){
return power(n, MOD-2);
}
ll add(ll a, ll b){
return (a+b) % MOD;
}
ll mul(ll a, ll b){
return (a*b) % MOD;
}
ll gcd(ll a, ll b){
if (a == 0) return b;
if (a == 1) return 1;
return gcd(b%a, a);
}
ll p[200001], pre[200001];
struct segtree{
int sz; vector<ll> hash, as;
void init(int n){
sz = n;
hash.assign(4*n, 0);
as.assign(4*n, -1);
}
void prop(int v, int tl, int tr){
if (as[v] == -1) return;
if (tl == tr){
return;
}
int tm = (tl + tr)/2;
as[2*v] = as[v];
as[2*v+1] = as[v];
hash[2*v] = mul(as[v], pre[tm-tl]);
hash[2*v+1] = mul(as[v], pre[tr-tm-1]);
as[v] = -1;
}
void update(int v, int tl, int tr, int l, int r, ll val){
prop(v, tl, tr);
if (tl == l && tr == r){
as[v] = val;
hash[v] = mul(as[v], pre[tr-tl]);
return;
}
if (l > r) return;
int tm = (tl + tr)/2;
update(2*v, tl, tm, l, min(r, tm), val);
update(2*v+1, tm+1, tr, max(l, tm+1), r, val);
hash[v] = add(mul(hash[2*v], p[tr-tm]), hash[2*v+1]);
}
void update(int l, int r, ll val){
update(1, 0, sz-1, l, r, val);
}
};
map<char, int> joi;
string JOI = "JOI";
ll Hash(string s){
ll ans = 0;
int sz = s.size();
FOR(i, 0, sz){
ans = mul(ans, A);
ans += joi[s[i]];
}
return ans;
}
string comb(string a, string b){
string ans = "";
int sz = a.size();
FOR(i, 0, sz){
ans += JOI[(6-joi[a[i]]-joi[b[i]]) % 3];
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
pre[0] = 1; p[0] = 1;
FOR(i, 1, 200001){
p[i] = mul(p[i-1], A);
pre[i] = add(pre[i-1], p[i]);
}
joi['J'] = 0;
joi['O'] = 1;
joi['I'] = 2;
int n; cin >> n;
string s1, s2, s3; cin >> s1 >> s2 >> s3;
map<ll, int> mp;
mp[Hash(s1)] = 1;
mp[Hash(s2)] = 1;
mp[Hash(s3)] = 1;
string a1 = comb(s1, s2);
string a2 = comb(s2, s3);
string a3 = comb(s3, s1);
mp[Hash(a1)] = 1;
mp[Hash(a2)] = 1;
mp[Hash(a3)] = 1;
string b1 = comb(a1, s3);
string b2 = comb(a2, s1);
string b3 = comb(a3, s2);
mp[Hash(b1)] = 1;
mp[Hash(b2)] = 1;
mp[Hash(b3)] = 1;
segtree st;
st.init(n);
int q; cin >> q;
string t; cin >> t;
FOR(i, 0, n){
st.update(i, i, joi[t[i]]);
}
if (mp[st.hash[1]]) cout << "Yes\n";
else cout << "No\n";
while (q--){
int l, r; cin >> l >> r;
char c; cin >> c;
st.update(l-1, r-1, joi[c]);
if (mp[st.hash[1]]) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
591 ms |
13284 KB |
Output is correct |
2 |
Correct |
650 ms |
14108 KB |
Output is correct |
3 |
Correct |
568 ms |
7592 KB |
Output is correct |
4 |
Correct |
566 ms |
14160 KB |
Output is correct |
5 |
Correct |
582 ms |
14276 KB |
Output is correct |
6 |
Correct |
643 ms |
13408 KB |
Output is correct |
7 |
Correct |
554 ms |
13756 KB |
Output is correct |
8 |
Correct |
618 ms |
14484 KB |
Output is correct |
9 |
Correct |
616 ms |
14052 KB |
Output is correct |
10 |
Correct |
575 ms |
15564 KB |
Output is correct |
11 |
Correct |
638 ms |
14828 KB |
Output is correct |
12 |
Correct |
600 ms |
15584 KB |
Output is correct |
13 |
Correct |
636 ms |
14828 KB |
Output is correct |
14 |
Correct |
660 ms |
15568 KB |
Output is correct |
15 |
Correct |
628 ms |
14748 KB |
Output is correct |
16 |
Correct |
663 ms |
15604 KB |
Output is correct |
17 |
Correct |
591 ms |
14796 KB |
Output is correct |
18 |
Correct |
531 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
591 ms |
13284 KB |
Output is correct |
2 |
Correct |
650 ms |
14108 KB |
Output is correct |
3 |
Correct |
568 ms |
7592 KB |
Output is correct |
4 |
Correct |
566 ms |
14160 KB |
Output is correct |
5 |
Correct |
582 ms |
14276 KB |
Output is correct |
6 |
Correct |
643 ms |
13408 KB |
Output is correct |
7 |
Correct |
554 ms |
13756 KB |
Output is correct |
8 |
Correct |
618 ms |
14484 KB |
Output is correct |
9 |
Correct |
616 ms |
14052 KB |
Output is correct |
10 |
Correct |
575 ms |
15564 KB |
Output is correct |
11 |
Correct |
638 ms |
14828 KB |
Output is correct |
12 |
Correct |
600 ms |
15584 KB |
Output is correct |
13 |
Correct |
636 ms |
14828 KB |
Output is correct |
14 |
Correct |
660 ms |
15568 KB |
Output is correct |
15 |
Correct |
628 ms |
14748 KB |
Output is correct |
16 |
Correct |
663 ms |
15604 KB |
Output is correct |
17 |
Correct |
591 ms |
14796 KB |
Output is correct |
18 |
Correct |
531 ms |
5980 KB |
Output is correct |
19 |
Correct |
1175 ms |
28216 KB |
Output is correct |
20 |
Correct |
1126 ms |
29036 KB |
Output is correct |
21 |
Correct |
1038 ms |
29012 KB |
Output is correct |
22 |
Correct |
848 ms |
25564 KB |
Output is correct |
23 |
Correct |
850 ms |
17284 KB |
Output is correct |
24 |
Correct |
780 ms |
15968 KB |
Output is correct |
25 |
Correct |
1097 ms |
30588 KB |
Output is correct |
26 |
Correct |
1020 ms |
28792 KB |
Output is correct |
27 |
Correct |
1064 ms |
31040 KB |
Output is correct |
28 |
Correct |
1067 ms |
28568 KB |
Output is correct |
29 |
Correct |
1036 ms |
30260 KB |
Output is correct |
30 |
Correct |
802 ms |
17248 KB |
Output is correct |
31 |
Correct |
1154 ms |
30960 KB |
Output is correct |
32 |
Correct |
1020 ms |
27112 KB |
Output is correct |
33 |
Correct |
777 ms |
15888 KB |
Output is correct |
34 |
Correct |
1170 ms |
28632 KB |
Output is correct |
35 |
Correct |
895 ms |
25124 KB |
Output is correct |
36 |
Correct |
764 ms |
16096 KB |
Output is correct |
37 |
Correct |
775 ms |
16036 KB |
Output is correct |
38 |
Correct |
1038 ms |
26336 KB |
Output is correct |
39 |
Correct |
818 ms |
24928 KB |
Output is correct |
40 |
Correct |
936 ms |
23988 KB |
Output is correct |
41 |
Correct |
929 ms |
19116 KB |
Output is correct |
42 |
Correct |
521 ms |
19120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
591 ms |
13284 KB |
Output is correct |
2 |
Correct |
650 ms |
14108 KB |
Output is correct |
3 |
Correct |
568 ms |
7592 KB |
Output is correct |
4 |
Correct |
566 ms |
14160 KB |
Output is correct |
5 |
Correct |
582 ms |
14276 KB |
Output is correct |
6 |
Correct |
643 ms |
13408 KB |
Output is correct |
7 |
Correct |
554 ms |
13756 KB |
Output is correct |
8 |
Correct |
618 ms |
14484 KB |
Output is correct |
9 |
Correct |
616 ms |
14052 KB |
Output is correct |
10 |
Correct |
575 ms |
15564 KB |
Output is correct |
11 |
Correct |
638 ms |
14828 KB |
Output is correct |
12 |
Correct |
600 ms |
15584 KB |
Output is correct |
13 |
Correct |
636 ms |
14828 KB |
Output is correct |
14 |
Correct |
660 ms |
15568 KB |
Output is correct |
15 |
Correct |
628 ms |
14748 KB |
Output is correct |
16 |
Correct |
663 ms |
15604 KB |
Output is correct |
17 |
Correct |
591 ms |
14796 KB |
Output is correct |
18 |
Correct |
531 ms |
5980 KB |
Output is correct |
19 |
Correct |
643 ms |
13632 KB |
Output is correct |
20 |
Correct |
526 ms |
7644 KB |
Output is correct |
21 |
Correct |
670 ms |
14960 KB |
Output is correct |
22 |
Correct |
591 ms |
12996 KB |
Output is correct |
23 |
Correct |
591 ms |
15056 KB |
Output is correct |
24 |
Correct |
571 ms |
13884 KB |
Output is correct |
25 |
Correct |
573 ms |
14904 KB |
Output is correct |
26 |
Correct |
581 ms |
13576 KB |
Output is correct |
27 |
Correct |
669 ms |
15044 KB |
Output is correct |
28 |
Correct |
596 ms |
13940 KB |
Output is correct |
29 |
Correct |
567 ms |
14336 KB |
Output is correct |
30 |
Correct |
568 ms |
13320 KB |
Output is correct |
31 |
Correct |
583 ms |
15264 KB |
Output is correct |
32 |
Correct |
589 ms |
15116 KB |
Output is correct |
33 |
Correct |
631 ms |
14532 KB |
Output is correct |
34 |
Correct |
551 ms |
13596 KB |
Output is correct |
35 |
Correct |
606 ms |
15596 KB |
Output is correct |
36 |
Correct |
593 ms |
14836 KB |
Output is correct |
37 |
Correct |
587 ms |
15580 KB |
Output is correct |
38 |
Correct |
593 ms |
14772 KB |
Output is correct |
39 |
Correct |
691 ms |
15560 KB |
Output is correct |
40 |
Correct |
580 ms |
14820 KB |
Output is correct |
41 |
Correct |
645 ms |
15676 KB |
Output is correct |
42 |
Correct |
573 ms |
14788 KB |
Output is correct |
43 |
Correct |
532 ms |
14108 KB |
Output is correct |
44 |
Correct |
563 ms |
14436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
591 ms |
13284 KB |
Output is correct |
2 |
Correct |
650 ms |
14108 KB |
Output is correct |
3 |
Correct |
568 ms |
7592 KB |
Output is correct |
4 |
Correct |
566 ms |
14160 KB |
Output is correct |
5 |
Correct |
582 ms |
14276 KB |
Output is correct |
6 |
Correct |
643 ms |
13408 KB |
Output is correct |
7 |
Correct |
554 ms |
13756 KB |
Output is correct |
8 |
Correct |
618 ms |
14484 KB |
Output is correct |
9 |
Correct |
616 ms |
14052 KB |
Output is correct |
10 |
Correct |
575 ms |
15564 KB |
Output is correct |
11 |
Correct |
638 ms |
14828 KB |
Output is correct |
12 |
Correct |
600 ms |
15584 KB |
Output is correct |
13 |
Correct |
636 ms |
14828 KB |
Output is correct |
14 |
Correct |
660 ms |
15568 KB |
Output is correct |
15 |
Correct |
628 ms |
14748 KB |
Output is correct |
16 |
Correct |
663 ms |
15604 KB |
Output is correct |
17 |
Correct |
591 ms |
14796 KB |
Output is correct |
18 |
Correct |
531 ms |
5980 KB |
Output is correct |
19 |
Correct |
1175 ms |
28216 KB |
Output is correct |
20 |
Correct |
1126 ms |
29036 KB |
Output is correct |
21 |
Correct |
1038 ms |
29012 KB |
Output is correct |
22 |
Correct |
848 ms |
25564 KB |
Output is correct |
23 |
Correct |
850 ms |
17284 KB |
Output is correct |
24 |
Correct |
780 ms |
15968 KB |
Output is correct |
25 |
Correct |
1097 ms |
30588 KB |
Output is correct |
26 |
Correct |
1020 ms |
28792 KB |
Output is correct |
27 |
Correct |
1064 ms |
31040 KB |
Output is correct |
28 |
Correct |
1067 ms |
28568 KB |
Output is correct |
29 |
Correct |
1036 ms |
30260 KB |
Output is correct |
30 |
Correct |
802 ms |
17248 KB |
Output is correct |
31 |
Correct |
1154 ms |
30960 KB |
Output is correct |
32 |
Correct |
1020 ms |
27112 KB |
Output is correct |
33 |
Correct |
777 ms |
15888 KB |
Output is correct |
34 |
Correct |
1170 ms |
28632 KB |
Output is correct |
35 |
Correct |
895 ms |
25124 KB |
Output is correct |
36 |
Correct |
764 ms |
16096 KB |
Output is correct |
37 |
Correct |
775 ms |
16036 KB |
Output is correct |
38 |
Correct |
1038 ms |
26336 KB |
Output is correct |
39 |
Correct |
818 ms |
24928 KB |
Output is correct |
40 |
Correct |
936 ms |
23988 KB |
Output is correct |
41 |
Correct |
929 ms |
19116 KB |
Output is correct |
42 |
Correct |
521 ms |
19120 KB |
Output is correct |
43 |
Correct |
643 ms |
13632 KB |
Output is correct |
44 |
Correct |
526 ms |
7644 KB |
Output is correct |
45 |
Correct |
670 ms |
14960 KB |
Output is correct |
46 |
Correct |
591 ms |
12996 KB |
Output is correct |
47 |
Correct |
591 ms |
15056 KB |
Output is correct |
48 |
Correct |
571 ms |
13884 KB |
Output is correct |
49 |
Correct |
573 ms |
14904 KB |
Output is correct |
50 |
Correct |
581 ms |
13576 KB |
Output is correct |
51 |
Correct |
669 ms |
15044 KB |
Output is correct |
52 |
Correct |
596 ms |
13940 KB |
Output is correct |
53 |
Correct |
567 ms |
14336 KB |
Output is correct |
54 |
Correct |
568 ms |
13320 KB |
Output is correct |
55 |
Correct |
583 ms |
15264 KB |
Output is correct |
56 |
Correct |
589 ms |
15116 KB |
Output is correct |
57 |
Correct |
631 ms |
14532 KB |
Output is correct |
58 |
Correct |
551 ms |
13596 KB |
Output is correct |
59 |
Correct |
606 ms |
15596 KB |
Output is correct |
60 |
Correct |
593 ms |
14836 KB |
Output is correct |
61 |
Correct |
587 ms |
15580 KB |
Output is correct |
62 |
Correct |
593 ms |
14772 KB |
Output is correct |
63 |
Correct |
691 ms |
15560 KB |
Output is correct |
64 |
Correct |
580 ms |
14820 KB |
Output is correct |
65 |
Correct |
645 ms |
15676 KB |
Output is correct |
66 |
Correct |
573 ms |
14788 KB |
Output is correct |
67 |
Correct |
532 ms |
14108 KB |
Output is correct |
68 |
Correct |
563 ms |
14436 KB |
Output is correct |
69 |
Correct |
927 ms |
24980 KB |
Output is correct |
70 |
Correct |
1120 ms |
29100 KB |
Output is correct |
71 |
Correct |
730 ms |
16008 KB |
Output is correct |
72 |
Correct |
823 ms |
16128 KB |
Output is correct |
73 |
Correct |
743 ms |
16080 KB |
Output is correct |
74 |
Correct |
935 ms |
26932 KB |
Output is correct |
75 |
Correct |
775 ms |
17216 KB |
Output is correct |
76 |
Correct |
1184 ms |
30600 KB |
Output is correct |
77 |
Correct |
946 ms |
25644 KB |
Output is correct |
78 |
Correct |
766 ms |
16028 KB |
Output is correct |
79 |
Correct |
737 ms |
16016 KB |
Output is correct |
80 |
Correct |
968 ms |
24752 KB |
Output is correct |
81 |
Correct |
754 ms |
17284 KB |
Output is correct |
82 |
Correct |
1098 ms |
30624 KB |
Output is correct |
83 |
Correct |
967 ms |
27376 KB |
Output is correct |
84 |
Correct |
705 ms |
15968 KB |
Output is correct |
85 |
Correct |
773 ms |
16004 KB |
Output is correct |
86 |
Correct |
1012 ms |
24460 KB |
Output is correct |
87 |
Correct |
1038 ms |
28664 KB |
Output is correct |
88 |
Correct |
777 ms |
15344 KB |
Output is correct |
89 |
Correct |
938 ms |
26400 KB |
Output is correct |
90 |
Correct |
1076 ms |
28796 KB |
Output is correct |
91 |
Correct |
757 ms |
15452 KB |
Output is correct |
92 |
Correct |
909 ms |
25328 KB |
Output is correct |
93 |
Correct |
676 ms |
15972 KB |
Output is correct |
94 |
Correct |
751 ms |
16016 KB |
Output is correct |
95 |
Correct |
727 ms |
15980 KB |
Output is correct |
96 |
Correct |
915 ms |
26264 KB |
Output is correct |
97 |
Correct |
843 ms |
26184 KB |
Output is correct |
98 |
Correct |
855 ms |
24064 KB |
Output is correct |
99 |
Correct |
1016 ms |
19244 KB |
Output is correct |
100 |
Correct |
551 ms |
19364 KB |
Output is correct |