//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 200015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
const int mod1=233LL;
const int mod2=998244353LL;
const int inv1=844009174LL;
const int inv_mod1_1=684141604LL;
int n,p[N],inv[N];
string s1,s2,s3;
char get(char a,char b){
if (a==b) return a;
else if (a!='O'&&b!='O') return 'O';
else if (a!='J'&&b!='J') return 'J';
return 'I';
}
string cross(string a,string b){
string ans="";
for (int i=0;i<n;i++)
ans.push_back(get(a[i],b[i]));
return ans;
}
string ori;
set<int>can;
int fast_pow(int a,int b,int mod){
int ans=1;
while (b){
if (b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
struct segtree{
int seg[4*N],tag[4*N];
void build(int l,int r,int i){
if (l==r){
seg[i]=(ori[l-1]-'A')*p[l-1]%mod2;
return;
}
int mid=(l+r)>>1;
build(l,mid,2*i);
build(mid+1,r,2*i+1);
seg[i]=(seg[2*i]+seg[2*i+1])%mod2;
}
int count(int l,int r,char c){
return p[l-1]*((p[r-l+1]-1+mod2)%mod2)%mod2*inv_mod1_1%mod2*(c-'A')%mod2;
}
void push(int l,int r,int i){
if (tag[i]){
int mid=(l+r)>>1;
tag[2*i]=tag[i];
seg[2*i]=count(l,mid,(char)(tag[i]+'A'));
tag[2*i+1]=tag[i];
seg[2*i+1]=count(mid+1,r,(char)(tag[i]+'A'));
tag[i]=0;
}
}
void modify(int l,int r,int i,int ll,int rr,char c){
if (ll<=l&&rr>=r){
tag[i]=c-'A';
seg[i]=count(l,r,c);
return;
}
int mid=(l+r)>>1;
push(l,r,i);
if (rr<=mid) modify(l,mid,2*i,ll,rr,c);
else if (ll>mid) modify(mid+1,r,2*i+1,ll,rr,c);
else {
modify(l,mid,2*i,ll,mid,c);
modify(mid+1,r,2*i+1,mid+1,rr,c);
}
seg[i]=(seg[2*i]+seg[2*i+1])%mod2;
}
}seg;
int get_hash(string str){
int val=0;
for (int i=0;i<n;i++)
val=(val+p[i]*(str[i]-'A'))%mod2;
return val;
}
void build(){
p[0]=1; inv[0]=1;
for (int i=1;i<=n;i++){
p[i]=p[i-1]*mod1%mod2;
inv[i]=inv[i-1]*inv1%mod2;
}
vector<string>all;
all.push_back(s1); all.push_back(s2); all.push_back(s3);
set<string>st;
for (auto i:all)
st.insert(i);
for (int h=0;h<2;h++){
all.clear();
for (auto i:st)
all.push_back(i);
for (int i=0;i<all.size();i++){
for (int j=i+1;j<all.size();j++){
string str=cross(all[i],all[j]);
st.insert(str);
}
}
}
for (auto i:st){
can.insert(get_hash(i));
}
}
signed main(){
fast
cin>>n>>s1>>s2>>s3;
build();
int q; cin>>q;
cin>>ori;
seg.build(1,n,1);
if (can.find(seg.seg[1])!=can.end())
cout<<"Yes\n";
else cout<<"No\n";
while (q--){
int l,r;
char c;
cin>>l>>r>>c;
seg.modify(1,n,1,l,r,c);
if (can.find(seg.seg[1])!=can.end())
cout<<"Yes\n";
else cout<<"No\n";
}
}
Compilation message
Main.cpp: In function 'void build()':
Main.cpp:109:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int i=0;i<all.size();i++){
| ~^~~~~~~~~~~
Main.cpp:110:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for (int j=i+1;j<all.size();j++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
800 KB |
Output is correct |
2 |
Correct |
69 ms |
952 KB |
Output is correct |
3 |
Correct |
76 ms |
920 KB |
Output is correct |
4 |
Correct |
54 ms |
844 KB |
Output is correct |
5 |
Correct |
53 ms |
820 KB |
Output is correct |
6 |
Correct |
60 ms |
920 KB |
Output is correct |
7 |
Correct |
56 ms |
840 KB |
Output is correct |
8 |
Correct |
70 ms |
932 KB |
Output is correct |
9 |
Correct |
58 ms |
936 KB |
Output is correct |
10 |
Correct |
57 ms |
936 KB |
Output is correct |
11 |
Correct |
70 ms |
1004 KB |
Output is correct |
12 |
Correct |
57 ms |
912 KB |
Output is correct |
13 |
Correct |
63 ms |
844 KB |
Output is correct |
14 |
Correct |
57 ms |
844 KB |
Output is correct |
15 |
Correct |
57 ms |
904 KB |
Output is correct |
16 |
Correct |
58 ms |
940 KB |
Output is correct |
17 |
Correct |
56 ms |
912 KB |
Output is correct |
18 |
Correct |
70 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
800 KB |
Output is correct |
2 |
Correct |
69 ms |
952 KB |
Output is correct |
3 |
Correct |
76 ms |
920 KB |
Output is correct |
4 |
Correct |
54 ms |
844 KB |
Output is correct |
5 |
Correct |
53 ms |
820 KB |
Output is correct |
6 |
Correct |
60 ms |
920 KB |
Output is correct |
7 |
Correct |
56 ms |
840 KB |
Output is correct |
8 |
Correct |
70 ms |
932 KB |
Output is correct |
9 |
Correct |
58 ms |
936 KB |
Output is correct |
10 |
Correct |
57 ms |
936 KB |
Output is correct |
11 |
Correct |
70 ms |
1004 KB |
Output is correct |
12 |
Correct |
57 ms |
912 KB |
Output is correct |
13 |
Correct |
63 ms |
844 KB |
Output is correct |
14 |
Correct |
57 ms |
844 KB |
Output is correct |
15 |
Correct |
57 ms |
904 KB |
Output is correct |
16 |
Correct |
58 ms |
940 KB |
Output is correct |
17 |
Correct |
56 ms |
912 KB |
Output is correct |
18 |
Correct |
70 ms |
960 KB |
Output is correct |
19 |
Correct |
326 ms |
13272 KB |
Output is correct |
20 |
Correct |
216 ms |
10012 KB |
Output is correct |
21 |
Correct |
132 ms |
12848 KB |
Output is correct |
22 |
Correct |
134 ms |
12516 KB |
Output is correct |
23 |
Correct |
91 ms |
1772 KB |
Output is correct |
24 |
Correct |
89 ms |
1708 KB |
Output is correct |
25 |
Correct |
144 ms |
13240 KB |
Output is correct |
26 |
Correct |
150 ms |
13260 KB |
Output is correct |
27 |
Correct |
190 ms |
13272 KB |
Output is correct |
28 |
Correct |
185 ms |
13200 KB |
Output is correct |
29 |
Correct |
155 ms |
13152 KB |
Output is correct |
30 |
Correct |
100 ms |
1700 KB |
Output is correct |
31 |
Correct |
151 ms |
13188 KB |
Output is correct |
32 |
Correct |
168 ms |
12828 KB |
Output is correct |
33 |
Correct |
91 ms |
1712 KB |
Output is correct |
34 |
Correct |
171 ms |
13344 KB |
Output is correct |
35 |
Correct |
127 ms |
12148 KB |
Output is correct |
36 |
Correct |
88 ms |
1708 KB |
Output is correct |
37 |
Correct |
87 ms |
1608 KB |
Output is correct |
38 |
Correct |
205 ms |
10044 KB |
Output is correct |
39 |
Correct |
96 ms |
9192 KB |
Output is correct |
40 |
Correct |
137 ms |
7980 KB |
Output is correct |
41 |
Correct |
376 ms |
13424 KB |
Output is correct |
42 |
Correct |
47 ms |
9292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
800 KB |
Output is correct |
2 |
Correct |
69 ms |
952 KB |
Output is correct |
3 |
Correct |
76 ms |
920 KB |
Output is correct |
4 |
Correct |
54 ms |
844 KB |
Output is correct |
5 |
Correct |
53 ms |
820 KB |
Output is correct |
6 |
Correct |
60 ms |
920 KB |
Output is correct |
7 |
Correct |
56 ms |
840 KB |
Output is correct |
8 |
Correct |
70 ms |
932 KB |
Output is correct |
9 |
Correct |
58 ms |
936 KB |
Output is correct |
10 |
Correct |
57 ms |
936 KB |
Output is correct |
11 |
Correct |
70 ms |
1004 KB |
Output is correct |
12 |
Correct |
57 ms |
912 KB |
Output is correct |
13 |
Correct |
63 ms |
844 KB |
Output is correct |
14 |
Correct |
57 ms |
844 KB |
Output is correct |
15 |
Correct |
57 ms |
904 KB |
Output is correct |
16 |
Correct |
58 ms |
940 KB |
Output is correct |
17 |
Correct |
56 ms |
912 KB |
Output is correct |
18 |
Correct |
70 ms |
960 KB |
Output is correct |
19 |
Correct |
71 ms |
824 KB |
Output is correct |
20 |
Correct |
81 ms |
912 KB |
Output is correct |
21 |
Correct |
68 ms |
840 KB |
Output is correct |
22 |
Correct |
57 ms |
888 KB |
Output is correct |
23 |
Correct |
59 ms |
880 KB |
Output is correct |
24 |
Correct |
59 ms |
972 KB |
Output is correct |
25 |
Correct |
60 ms |
944 KB |
Output is correct |
26 |
Correct |
55 ms |
876 KB |
Output is correct |
27 |
Correct |
59 ms |
944 KB |
Output is correct |
28 |
Correct |
57 ms |
860 KB |
Output is correct |
29 |
Correct |
59 ms |
936 KB |
Output is correct |
30 |
Correct |
53 ms |
896 KB |
Output is correct |
31 |
Correct |
63 ms |
1028 KB |
Output is correct |
32 |
Correct |
60 ms |
928 KB |
Output is correct |
33 |
Correct |
68 ms |
876 KB |
Output is correct |
34 |
Correct |
59 ms |
796 KB |
Output is correct |
35 |
Correct |
62 ms |
952 KB |
Output is correct |
36 |
Correct |
63 ms |
888 KB |
Output is correct |
37 |
Correct |
66 ms |
852 KB |
Output is correct |
38 |
Correct |
76 ms |
840 KB |
Output is correct |
39 |
Correct |
64 ms |
932 KB |
Output is correct |
40 |
Correct |
62 ms |
840 KB |
Output is correct |
41 |
Correct |
64 ms |
860 KB |
Output is correct |
42 |
Correct |
61 ms |
844 KB |
Output is correct |
43 |
Correct |
71 ms |
916 KB |
Output is correct |
44 |
Correct |
63 ms |
916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
800 KB |
Output is correct |
2 |
Correct |
69 ms |
952 KB |
Output is correct |
3 |
Correct |
76 ms |
920 KB |
Output is correct |
4 |
Correct |
54 ms |
844 KB |
Output is correct |
5 |
Correct |
53 ms |
820 KB |
Output is correct |
6 |
Correct |
60 ms |
920 KB |
Output is correct |
7 |
Correct |
56 ms |
840 KB |
Output is correct |
8 |
Correct |
70 ms |
932 KB |
Output is correct |
9 |
Correct |
58 ms |
936 KB |
Output is correct |
10 |
Correct |
57 ms |
936 KB |
Output is correct |
11 |
Correct |
70 ms |
1004 KB |
Output is correct |
12 |
Correct |
57 ms |
912 KB |
Output is correct |
13 |
Correct |
63 ms |
844 KB |
Output is correct |
14 |
Correct |
57 ms |
844 KB |
Output is correct |
15 |
Correct |
57 ms |
904 KB |
Output is correct |
16 |
Correct |
58 ms |
940 KB |
Output is correct |
17 |
Correct |
56 ms |
912 KB |
Output is correct |
18 |
Correct |
70 ms |
960 KB |
Output is correct |
19 |
Correct |
326 ms |
13272 KB |
Output is correct |
20 |
Correct |
216 ms |
10012 KB |
Output is correct |
21 |
Correct |
132 ms |
12848 KB |
Output is correct |
22 |
Correct |
134 ms |
12516 KB |
Output is correct |
23 |
Correct |
91 ms |
1772 KB |
Output is correct |
24 |
Correct |
89 ms |
1708 KB |
Output is correct |
25 |
Correct |
144 ms |
13240 KB |
Output is correct |
26 |
Correct |
150 ms |
13260 KB |
Output is correct |
27 |
Correct |
190 ms |
13272 KB |
Output is correct |
28 |
Correct |
185 ms |
13200 KB |
Output is correct |
29 |
Correct |
155 ms |
13152 KB |
Output is correct |
30 |
Correct |
100 ms |
1700 KB |
Output is correct |
31 |
Correct |
151 ms |
13188 KB |
Output is correct |
32 |
Correct |
168 ms |
12828 KB |
Output is correct |
33 |
Correct |
91 ms |
1712 KB |
Output is correct |
34 |
Correct |
171 ms |
13344 KB |
Output is correct |
35 |
Correct |
127 ms |
12148 KB |
Output is correct |
36 |
Correct |
88 ms |
1708 KB |
Output is correct |
37 |
Correct |
87 ms |
1608 KB |
Output is correct |
38 |
Correct |
205 ms |
10044 KB |
Output is correct |
39 |
Correct |
96 ms |
9192 KB |
Output is correct |
40 |
Correct |
137 ms |
7980 KB |
Output is correct |
41 |
Correct |
376 ms |
13424 KB |
Output is correct |
42 |
Correct |
47 ms |
9292 KB |
Output is correct |
43 |
Correct |
71 ms |
824 KB |
Output is correct |
44 |
Correct |
81 ms |
912 KB |
Output is correct |
45 |
Correct |
68 ms |
840 KB |
Output is correct |
46 |
Correct |
57 ms |
888 KB |
Output is correct |
47 |
Correct |
59 ms |
880 KB |
Output is correct |
48 |
Correct |
59 ms |
972 KB |
Output is correct |
49 |
Correct |
60 ms |
944 KB |
Output is correct |
50 |
Correct |
55 ms |
876 KB |
Output is correct |
51 |
Correct |
59 ms |
944 KB |
Output is correct |
52 |
Correct |
57 ms |
860 KB |
Output is correct |
53 |
Correct |
59 ms |
936 KB |
Output is correct |
54 |
Correct |
53 ms |
896 KB |
Output is correct |
55 |
Correct |
63 ms |
1028 KB |
Output is correct |
56 |
Correct |
60 ms |
928 KB |
Output is correct |
57 |
Correct |
68 ms |
876 KB |
Output is correct |
58 |
Correct |
59 ms |
796 KB |
Output is correct |
59 |
Correct |
62 ms |
952 KB |
Output is correct |
60 |
Correct |
63 ms |
888 KB |
Output is correct |
61 |
Correct |
66 ms |
852 KB |
Output is correct |
62 |
Correct |
76 ms |
840 KB |
Output is correct |
63 |
Correct |
64 ms |
932 KB |
Output is correct |
64 |
Correct |
62 ms |
840 KB |
Output is correct |
65 |
Correct |
64 ms |
860 KB |
Output is correct |
66 |
Correct |
61 ms |
844 KB |
Output is correct |
67 |
Correct |
71 ms |
916 KB |
Output is correct |
68 |
Correct |
63 ms |
916 KB |
Output is correct |
69 |
Correct |
315 ms |
14948 KB |
Output is correct |
70 |
Correct |
303 ms |
12848 KB |
Output is correct |
71 |
Correct |
95 ms |
1676 KB |
Output is correct |
72 |
Correct |
95 ms |
1836 KB |
Output is correct |
73 |
Correct |
98 ms |
1720 KB |
Output is correct |
74 |
Correct |
166 ms |
13564 KB |
Output is correct |
75 |
Correct |
89 ms |
1728 KB |
Output is correct |
76 |
Correct |
161 ms |
14424 KB |
Output is correct |
77 |
Correct |
152 ms |
13492 KB |
Output is correct |
78 |
Correct |
95 ms |
1736 KB |
Output is correct |
79 |
Correct |
94 ms |
1740 KB |
Output is correct |
80 |
Correct |
183 ms |
14052 KB |
Output is correct |
81 |
Correct |
97 ms |
1728 KB |
Output is correct |
82 |
Correct |
191 ms |
16104 KB |
Output is correct |
83 |
Correct |
243 ms |
15764 KB |
Output is correct |
84 |
Correct |
98 ms |
1704 KB |
Output is correct |
85 |
Correct |
111 ms |
1852 KB |
Output is correct |
86 |
Correct |
206 ms |
14448 KB |
Output is correct |
87 |
Correct |
194 ms |
16076 KB |
Output is correct |
88 |
Correct |
115 ms |
1756 KB |
Output is correct |
89 |
Correct |
254 ms |
15260 KB |
Output is correct |
90 |
Correct |
214 ms |
16040 KB |
Output is correct |
91 |
Correct |
118 ms |
1812 KB |
Output is correct |
92 |
Correct |
230 ms |
14288 KB |
Output is correct |
93 |
Correct |
117 ms |
1728 KB |
Output is correct |
94 |
Correct |
104 ms |
1700 KB |
Output is correct |
95 |
Correct |
107 ms |
1788 KB |
Output is correct |
96 |
Correct |
216 ms |
9944 KB |
Output is correct |
97 |
Correct |
144 ms |
12040 KB |
Output is correct |
98 |
Correct |
192 ms |
9680 KB |
Output is correct |
99 |
Correct |
400 ms |
16276 KB |
Output is correct |
100 |
Correct |
103 ms |
12136 KB |
Output is correct |