#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string JOI="JOI";
vector<ll> keys;
string merge(string a, string b) {
string c="";
for(int i=0;i<a.size();i++) {
if(a[i]==b[i]) c+=a[i];
else {
if(a[i]!='J' && b[i]!='J') c+='J';
if(a[i]!='O' && b[i]!='O') c+='O';
if(a[i]!='I' && b[i]!='I') c+='I';
}
}
return c;
}
const int MX=2e5+5, B=500, mod=998244353, P=1e9+7;
ll pw[MX], pf[MX];
ll getHash(string S) {
ll res=0;
for(int i=0;i<S.size();i++) {
for(int j=0;j<3;j++) {
if(JOI[j]==S[i]) {
res+=pw[i+1]*keys[j]%mod;
res%=mod;
break;
}
}
}
return res;
}
struct DS {
ll lazy[MX],sum[MX],val[MX]; // activate or deactivate
ll key;
void push(int x) {
if(lazy[x]==1) {
ll curs=0;
for(int i=x*B;i<(x+1)*B;i++) {
val[i]=0;
curs+=val[i];
curs%=mod;
}
assert(curs==sum[x]);
}
if(lazy[x]==2) {
ll curs=0;
for(int i=x*B;i<(x+1)*B;i++) {
val[i]=pw[i+1]*key%mod;
curs+=val[i];
curs%=mod;
}
assert(curs==sum[x]);
}
lazy[x]=0;
}
void add(int l, int r) {
int lb=l/B;
push(lb);
while(l%B!=0 && l<=r) {
sum[lb]-=val[l];
val[l]=pw[l+1]*key%mod;
sum[lb]+=val[l];
sum[lb]+=mod;
sum[lb]%=mod;
l++;
}
if(l%B!=0) return;
while(l%B==0 && l+B-1<=r) {
lazy[l/B]=2;
sum[l/B]=(pf[l+B]-pf[l]+mod)%mod*key%mod;
l+=B;
}
int rb=l/B;
push(rb);
while(l<=r) {
sum[rb]-=val[l];
val[l]=pw[l+1]*key%mod;
sum[rb]+=val[l];
sum[rb]+=mod;
sum[rb]%=mod;
l++;
}
}
void del(int l, int r) {
int lb=l/B;
push(lb);
while(l%B!=0 && l<=r) {
sum[lb]-=val[l];
val[l]=0;
sum[lb]+=val[l];
sum[lb]+=mod;
sum[lb]%=mod;
l++;
}
if(l%B!=0) return;
while(l%B==0 && l+B-1<=r) {
lazy[l/B]=1;
sum[l/B]=0;
l+=B;
}
int rb=l/B;
push(rb);
while(l<=r) {
sum[rb]-=val[l];
val[l]=0;
sum[rb]+=val[l];
sum[rb]+=mod;
sum[rb]%=mod;
l++;
}
}
ll f() {
ll res=0;
for(int i=0;i<MX;i+=B) {
res+=sum[i/B];
res%=mod;
}
return res;
}
} ds[3];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
pw[0]=1;
pf[0]=1;
for(int i=1;i<MX;i++) {
pw[i]=pw[i-1]*P%mod;
pf[i]=(pf[i-1]+pw[i])%mod;
}
for(int i=0;i<3;i++) {
keys.push_back(rng()%mod);
}
int N;
cin>>N;
string sa, sb, sc;
cin>>sa>>sb>>sc;
vector<string> v;
set<string> st;
if(!st.count(sa)) {
v.push_back(sa);
st.insert(sa);
}
if(!st.count(sb)) {
v.push_back(sb);
st.insert(sb);
}
if(!st.count(sc)) {
v.push_back(sc);
st.insert(sc);
}
while(true) {
bool fnd=0;
for(int i=0;i<v.size();i++) {
for(int j=i+1;j<v.size();j++) {
string c=merge(v[i],v[j]);
if(!st.count(c)) {
fnd=true;
v.push_back(c);
st.insert(c);
}
}
}
if(!fnd) break;
}
set<ll> tt;
for(auto S:st) {
tt.insert(getHash(S));
}
int Q;
cin>>Q;
string S;
cin>>S;
ds[0].key=keys[0];
ds[1].key=keys[1];
ds[2].key=keys[2];
for(int i=0;i<N;i++) {
int t;
if(S[i]=='J') t=0;
if(S[i]=='O') t=1;
if(S[i]=='I') t=2;
ds[t].add(i,i);
}
cout<<(tt.count((ds[0].f()+ds[1].f()+ds[2].f())%mod)? "Yes":"No")<<'\n';
for(int i=0;i<Q;i++) {
int l,r;
char c;
cin>>l>>r>>c;
int t=0;
for(int j=0;j<3;j++)
if(JOI[j]==c) t=j;
l--,r--;
ds[t].add(l,r);
for(int j=0;j<3;j++)
if(j!=t) ds[j].del(l,r);
cout<<(tt.count((ds[0].f()+ds[1].f()+ds[2].f())%mod)?"Yes":"No")<<'\n';
}
}
Compilation message
Main.cpp: In function 'std::string merge(std::string, std::string)':
Main.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=0;i<a.size();i++) {
| ~^~~~~~~~~
Main.cpp: In function 'll getHash(std::string)':
Main.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<S.size();i++) {
| ~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:182:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
182 | for(int i=0;i<v.size();i++) {
| ~^~~~~~~~~
Main.cpp:183:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
183 | for(int j=i+1;j<v.size();j++) {
| ~^~~~~~~~~
Main.cpp:211:21: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
211 | int t;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
730 ms |
9812 KB |
Output is correct |
2 |
Correct |
783 ms |
9808 KB |
Output is correct |
3 |
Correct |
924 ms |
10068 KB |
Output is correct |
4 |
Correct |
738 ms |
9772 KB |
Output is correct |
5 |
Correct |
740 ms |
9772 KB |
Output is correct |
6 |
Correct |
722 ms |
9824 KB |
Output is correct |
7 |
Correct |
749 ms |
9704 KB |
Output is correct |
8 |
Correct |
772 ms |
9792 KB |
Output is correct |
9 |
Correct |
782 ms |
9868 KB |
Output is correct |
10 |
Correct |
786 ms |
9852 KB |
Output is correct |
11 |
Correct |
776 ms |
9808 KB |
Output is correct |
12 |
Correct |
802 ms |
9864 KB |
Output is correct |
13 |
Correct |
763 ms |
9808 KB |
Output is correct |
14 |
Correct |
762 ms |
9888 KB |
Output is correct |
15 |
Correct |
766 ms |
9812 KB |
Output is correct |
16 |
Correct |
774 ms |
9808 KB |
Output is correct |
17 |
Correct |
763 ms |
9860 KB |
Output is correct |
18 |
Correct |
920 ms |
10064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
730 ms |
9812 KB |
Output is correct |
2 |
Correct |
783 ms |
9808 KB |
Output is correct |
3 |
Correct |
924 ms |
10068 KB |
Output is correct |
4 |
Correct |
738 ms |
9772 KB |
Output is correct |
5 |
Correct |
740 ms |
9772 KB |
Output is correct |
6 |
Correct |
722 ms |
9824 KB |
Output is correct |
7 |
Correct |
749 ms |
9704 KB |
Output is correct |
8 |
Correct |
772 ms |
9792 KB |
Output is correct |
9 |
Correct |
782 ms |
9868 KB |
Output is correct |
10 |
Correct |
786 ms |
9852 KB |
Output is correct |
11 |
Correct |
776 ms |
9808 KB |
Output is correct |
12 |
Correct |
802 ms |
9864 KB |
Output is correct |
13 |
Correct |
763 ms |
9808 KB |
Output is correct |
14 |
Correct |
762 ms |
9888 KB |
Output is correct |
15 |
Correct |
766 ms |
9812 KB |
Output is correct |
16 |
Correct |
774 ms |
9808 KB |
Output is correct |
17 |
Correct |
763 ms |
9860 KB |
Output is correct |
18 |
Correct |
920 ms |
10064 KB |
Output is correct |
19 |
Correct |
2120 ms |
12920 KB |
Output is correct |
20 |
Correct |
2879 ms |
14828 KB |
Output is correct |
21 |
Correct |
850 ms |
16092 KB |
Output is correct |
22 |
Correct |
864 ms |
16040 KB |
Output is correct |
23 |
Correct |
866 ms |
12488 KB |
Output is correct |
24 |
Correct |
862 ms |
12340 KB |
Output is correct |
25 |
Correct |
901 ms |
18288 KB |
Output is correct |
26 |
Correct |
955 ms |
16664 KB |
Output is correct |
27 |
Correct |
1343 ms |
16516 KB |
Output is correct |
28 |
Correct |
1339 ms |
18028 KB |
Output is correct |
29 |
Correct |
1356 ms |
16548 KB |
Output is correct |
30 |
Correct |
984 ms |
12412 KB |
Output is correct |
31 |
Correct |
1361 ms |
16576 KB |
Output is correct |
32 |
Correct |
1165 ms |
16080 KB |
Output is correct |
33 |
Correct |
890 ms |
12368 KB |
Output is correct |
34 |
Correct |
1246 ms |
16632 KB |
Output is correct |
35 |
Correct |
820 ms |
15804 KB |
Output is correct |
36 |
Correct |
867 ms |
12468 KB |
Output is correct |
37 |
Correct |
857 ms |
12436 KB |
Output is correct |
38 |
Correct |
2612 ms |
16504 KB |
Output is correct |
39 |
Correct |
758 ms |
16756 KB |
Output is correct |
40 |
Correct |
891 ms |
15624 KB |
Output is correct |
41 |
Correct |
2612 ms |
16752 KB |
Output is correct |
42 |
Correct |
1627 ms |
15916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
730 ms |
9812 KB |
Output is correct |
2 |
Correct |
783 ms |
9808 KB |
Output is correct |
3 |
Correct |
924 ms |
10068 KB |
Output is correct |
4 |
Correct |
738 ms |
9772 KB |
Output is correct |
5 |
Correct |
740 ms |
9772 KB |
Output is correct |
6 |
Correct |
722 ms |
9824 KB |
Output is correct |
7 |
Correct |
749 ms |
9704 KB |
Output is correct |
8 |
Correct |
772 ms |
9792 KB |
Output is correct |
9 |
Correct |
782 ms |
9868 KB |
Output is correct |
10 |
Correct |
786 ms |
9852 KB |
Output is correct |
11 |
Correct |
776 ms |
9808 KB |
Output is correct |
12 |
Correct |
802 ms |
9864 KB |
Output is correct |
13 |
Correct |
763 ms |
9808 KB |
Output is correct |
14 |
Correct |
762 ms |
9888 KB |
Output is correct |
15 |
Correct |
766 ms |
9812 KB |
Output is correct |
16 |
Correct |
774 ms |
9808 KB |
Output is correct |
17 |
Correct |
763 ms |
9860 KB |
Output is correct |
18 |
Correct |
920 ms |
10064 KB |
Output is correct |
19 |
Correct |
745 ms |
9812 KB |
Output is correct |
20 |
Correct |
922 ms |
9812 KB |
Output is correct |
21 |
Correct |
779 ms |
9812 KB |
Output is correct |
22 |
Correct |
703 ms |
9652 KB |
Output is correct |
23 |
Correct |
767 ms |
9808 KB |
Output is correct |
24 |
Correct |
760 ms |
9808 KB |
Output is correct |
25 |
Correct |
769 ms |
9868 KB |
Output is correct |
26 |
Correct |
733 ms |
9808 KB |
Output is correct |
27 |
Correct |
772 ms |
9884 KB |
Output is correct |
28 |
Correct |
742 ms |
9812 KB |
Output is correct |
29 |
Correct |
764 ms |
9876 KB |
Output is correct |
30 |
Correct |
702 ms |
9760 KB |
Output is correct |
31 |
Correct |
775 ms |
9804 KB |
Output is correct |
32 |
Correct |
765 ms |
9736 KB |
Output is correct |
33 |
Correct |
766 ms |
9820 KB |
Output is correct |
34 |
Correct |
714 ms |
10076 KB |
Output is correct |
35 |
Correct |
766 ms |
9812 KB |
Output is correct |
36 |
Correct |
768 ms |
9816 KB |
Output is correct |
37 |
Correct |
774 ms |
9812 KB |
Output is correct |
38 |
Correct |
776 ms |
9808 KB |
Output is correct |
39 |
Correct |
818 ms |
9808 KB |
Output is correct |
40 |
Correct |
771 ms |
9808 KB |
Output is correct |
41 |
Correct |
768 ms |
9808 KB |
Output is correct |
42 |
Correct |
767 ms |
9880 KB |
Output is correct |
43 |
Correct |
753 ms |
9808 KB |
Output is correct |
44 |
Correct |
763 ms |
9872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
730 ms |
9812 KB |
Output is correct |
2 |
Correct |
783 ms |
9808 KB |
Output is correct |
3 |
Correct |
924 ms |
10068 KB |
Output is correct |
4 |
Correct |
738 ms |
9772 KB |
Output is correct |
5 |
Correct |
740 ms |
9772 KB |
Output is correct |
6 |
Correct |
722 ms |
9824 KB |
Output is correct |
7 |
Correct |
749 ms |
9704 KB |
Output is correct |
8 |
Correct |
772 ms |
9792 KB |
Output is correct |
9 |
Correct |
782 ms |
9868 KB |
Output is correct |
10 |
Correct |
786 ms |
9852 KB |
Output is correct |
11 |
Correct |
776 ms |
9808 KB |
Output is correct |
12 |
Correct |
802 ms |
9864 KB |
Output is correct |
13 |
Correct |
763 ms |
9808 KB |
Output is correct |
14 |
Correct |
762 ms |
9888 KB |
Output is correct |
15 |
Correct |
766 ms |
9812 KB |
Output is correct |
16 |
Correct |
774 ms |
9808 KB |
Output is correct |
17 |
Correct |
763 ms |
9860 KB |
Output is correct |
18 |
Correct |
920 ms |
10064 KB |
Output is correct |
19 |
Correct |
2120 ms |
12920 KB |
Output is correct |
20 |
Correct |
2879 ms |
14828 KB |
Output is correct |
21 |
Correct |
850 ms |
16092 KB |
Output is correct |
22 |
Correct |
864 ms |
16040 KB |
Output is correct |
23 |
Correct |
866 ms |
12488 KB |
Output is correct |
24 |
Correct |
862 ms |
12340 KB |
Output is correct |
25 |
Correct |
901 ms |
18288 KB |
Output is correct |
26 |
Correct |
955 ms |
16664 KB |
Output is correct |
27 |
Correct |
1343 ms |
16516 KB |
Output is correct |
28 |
Correct |
1339 ms |
18028 KB |
Output is correct |
29 |
Correct |
1356 ms |
16548 KB |
Output is correct |
30 |
Correct |
984 ms |
12412 KB |
Output is correct |
31 |
Correct |
1361 ms |
16576 KB |
Output is correct |
32 |
Correct |
1165 ms |
16080 KB |
Output is correct |
33 |
Correct |
890 ms |
12368 KB |
Output is correct |
34 |
Correct |
1246 ms |
16632 KB |
Output is correct |
35 |
Correct |
820 ms |
15804 KB |
Output is correct |
36 |
Correct |
867 ms |
12468 KB |
Output is correct |
37 |
Correct |
857 ms |
12436 KB |
Output is correct |
38 |
Correct |
2612 ms |
16504 KB |
Output is correct |
39 |
Correct |
758 ms |
16756 KB |
Output is correct |
40 |
Correct |
891 ms |
15624 KB |
Output is correct |
41 |
Correct |
2612 ms |
16752 KB |
Output is correct |
42 |
Correct |
1627 ms |
15916 KB |
Output is correct |
43 |
Correct |
745 ms |
9812 KB |
Output is correct |
44 |
Correct |
922 ms |
9812 KB |
Output is correct |
45 |
Correct |
779 ms |
9812 KB |
Output is correct |
46 |
Correct |
703 ms |
9652 KB |
Output is correct |
47 |
Correct |
767 ms |
9808 KB |
Output is correct |
48 |
Correct |
760 ms |
9808 KB |
Output is correct |
49 |
Correct |
769 ms |
9868 KB |
Output is correct |
50 |
Correct |
733 ms |
9808 KB |
Output is correct |
51 |
Correct |
772 ms |
9884 KB |
Output is correct |
52 |
Correct |
742 ms |
9812 KB |
Output is correct |
53 |
Correct |
764 ms |
9876 KB |
Output is correct |
54 |
Correct |
702 ms |
9760 KB |
Output is correct |
55 |
Correct |
775 ms |
9804 KB |
Output is correct |
56 |
Correct |
765 ms |
9736 KB |
Output is correct |
57 |
Correct |
766 ms |
9820 KB |
Output is correct |
58 |
Correct |
714 ms |
10076 KB |
Output is correct |
59 |
Correct |
766 ms |
9812 KB |
Output is correct |
60 |
Correct |
768 ms |
9816 KB |
Output is correct |
61 |
Correct |
774 ms |
9812 KB |
Output is correct |
62 |
Correct |
776 ms |
9808 KB |
Output is correct |
63 |
Correct |
818 ms |
9808 KB |
Output is correct |
64 |
Correct |
771 ms |
9808 KB |
Output is correct |
65 |
Correct |
768 ms |
9808 KB |
Output is correct |
66 |
Correct |
767 ms |
9880 KB |
Output is correct |
67 |
Correct |
753 ms |
9808 KB |
Output is correct |
68 |
Correct |
763 ms |
9872 KB |
Output is correct |
69 |
Correct |
2037 ms |
18600 KB |
Output is correct |
70 |
Correct |
3057 ms |
19820 KB |
Output is correct |
71 |
Correct |
853 ms |
12468 KB |
Output is correct |
72 |
Correct |
854 ms |
12372 KB |
Output is correct |
73 |
Correct |
855 ms |
12620 KB |
Output is correct |
74 |
Correct |
845 ms |
16788 KB |
Output is correct |
75 |
Correct |
859 ms |
12540 KB |
Output is correct |
76 |
Correct |
923 ms |
17608 KB |
Output is correct |
77 |
Correct |
911 ms |
16956 KB |
Output is correct |
78 |
Correct |
863 ms |
12368 KB |
Output is correct |
79 |
Correct |
873 ms |
12564 KB |
Output is correct |
80 |
Correct |
988 ms |
17908 KB |
Output is correct |
81 |
Correct |
871 ms |
12664 KB |
Output is correct |
82 |
Correct |
1049 ms |
19892 KB |
Output is correct |
83 |
Correct |
1061 ms |
19472 KB |
Output is correct |
84 |
Correct |
857 ms |
12628 KB |
Output is correct |
85 |
Correct |
870 ms |
12468 KB |
Output is correct |
86 |
Correct |
1444 ms |
18264 KB |
Output is correct |
87 |
Correct |
1397 ms |
19932 KB |
Output is correct |
88 |
Correct |
996 ms |
12672 KB |
Output is correct |
89 |
Correct |
1182 ms |
19120 KB |
Output is correct |
90 |
Correct |
1234 ms |
19988 KB |
Output is correct |
91 |
Correct |
966 ms |
12576 KB |
Output is correct |
92 |
Correct |
965 ms |
18296 KB |
Output is correct |
93 |
Correct |
886 ms |
12628 KB |
Output is correct |
94 |
Correct |
863 ms |
12628 KB |
Output is correct |
95 |
Correct |
889 ms |
12584 KB |
Output is correct |
96 |
Correct |
2639 ms |
17976 KB |
Output is correct |
97 |
Correct |
821 ms |
19924 KB |
Output is correct |
98 |
Correct |
993 ms |
17880 KB |
Output is correct |
99 |
Correct |
2754 ms |
20116 KB |
Output is correct |
100 |
Correct |
1744 ms |
19384 KB |
Output is correct |