#include <bits/stdc++.h>
#define hmod 1223334444555553LL
using namespace std;
int sz,n,nowl,nowr,l[200005],r[200005],q,blk;
long long val,sum[505],ttl,b[200005],sumb[505],indx[200005],all[505],nowindx;
char c[10]={'a','J','O','I'},ch;
string s,str;
vector <string> v;
map <string,bool> a;
map <long long,bool> hashing;
void makestring(){
for (int i=0;i<v.size();i++){
for (int j=i+1;j<v.size();j++){
str.clear();
for (int k=0;k<n;k++){
if (v[i][k] != v[j][k]){
for (int l=1;l<=3;l++){
if (c[l] != v[i][k] && c[l] != v[j][k])
str+=c[l];
}
}
else
str+=v[i][k];
}
if (!a[str]){
v.push_back(str);
a[str]=true;
}
}
}
for (int i=0;i<v.size();i++){
val=0;
for (int j=0;j<n;j++){
for (long long k=1;k<=3;k++){
if (v[i][j] == c[k])
val+=k*b[j];
}
val%=hmod;
}
hashing[val]=true;
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cout.tie(0);
cin >> n;
for (int i=1;i<=3;i++){
cin >> s;
a[s]=true; v.push_back(s);
}
b[0]=1;
for (int i=1;i<n;i++){
b[i]=b[i-1]*4;
b[i]%=hmod;
}
makestring();
sz=int(sqrt(n));
if (sz*sz != n) sz++;
nowl=0; nowr=sz-1;
for (int i=1;i<=sz;i++){
l[i]=nowl; r[i]=nowr;
nowl=nowr+1; nowr=min(n-1,nowl+sz-1);
if (nowl >= n){
sz=i;
break;
}
}
cin >> q >> str;
for (int i=0;i<n;i++){
for (int j=1;j<=3;j++){
if (str[i] == c[j])
indx[i]=j;
}
}
for (int i=1;i<=sz;i++){
for (int j=l[i];j<=r[i];j++){
sum[i]+=indx[j]*b[j]; sum[i]%=hmod;
sumb[i]+=b[j]; sumb[i]%=hmod;
}
ttl+=sum[i]; ttl%=hmod;
all[i]=-1;
}
if (hashing[ttl]) cout << "Yes\n";
else cout << "No\n";
for (int i=1;i<=q;i++){
cin >> nowl >> nowr >> ch;
nowl--; nowr--;
ttl=0;
for (int j=1;j<=3;j++){
if (ch == c[j]) nowindx=j;
}
for (int j=1;j<=sz;j++){
if (nowl > r[j] || nowr < l[j])
continue;
if (nowl <= l[j] && r[j] <= nowr){
all[j]=nowindx;
sum[j]=nowindx*sumb[j];
}
else
if (l[j] <= nowl && nowl <= r[j]){
if (all[j] == -1){
for (int k=nowl;k<=min(nowr,r[j]);k++){
sum[j]-=b[k]*indx[k]; sum[j]+=b[k]*nowindx;
indx[k]=nowindx;
}
}
else
{
for (int k=l[j];k<nowl;k++){
indx[k]=all[j];
}
for (int k=nowl;k<=min(nowr,r[j]);k++){
sum[j]-=b[k]*all[j]; sum[j]+=b[k]*nowindx;
indx[k]=nowindx;
}
for (int k=min(nowr,r[j])+1;k<=r[j];k++){
indx[k]=all[j];
}
}
all[j]=-1;
}
else
if (l[j] <= nowr && nowr <= r[j]){
if (all[j] == -1){
for (int k=max(nowl,l[j]);k<=nowr;k++){
sum[j]-=b[k]*indx[k]; sum[j]+=b[k]*nowindx;
indx[k]=nowindx;
}
}
else
{
for (int k=l[j];k<max(nowl,l[j]);k++){
indx[k]=all[j];
}
for (int k=max(nowl,l[j]);k<=nowr;k++){
sum[j]-=b[k]*all[j]; sum[j]+=b[k]*nowindx;
indx[k]=nowindx;
}
for (int k=nowr+1;k<=r[j];k++){
indx[k]=all[j];
}
}
all[j]=-1;
}
while (sum[j] < 0) sum[j]+=hmod;
}
for (int j=1;j<=sz;j++){
ttl+=sum[j]; ttl%=hmod;
}
if (hashing[ttl]) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'void makestring()':
Main.cpp:13:16: 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]
13 | for (int i=0;i<v.size();i++){
| ~^~~~~~~~~
Main.cpp:14:19: 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]
14 | for (int j=i+1;j<v.size();j++){
| ~^~~~~~~~~
Main.cpp:32:16: 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]
32 | for (int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
10228 KB |
Output is correct |
2 |
Correct |
170 ms |
10996 KB |
Output is correct |
3 |
Correct |
115 ms |
4652 KB |
Output is correct |
4 |
Correct |
149 ms |
11040 KB |
Output is correct |
5 |
Correct |
158 ms |
12588 KB |
Output is correct |
6 |
Correct |
146 ms |
11692 KB |
Output is correct |
7 |
Correct |
142 ms |
12100 KB |
Output is correct |
8 |
Correct |
196 ms |
12956 KB |
Output is correct |
9 |
Correct |
164 ms |
12444 KB |
Output is correct |
10 |
Correct |
198 ms |
14004 KB |
Output is correct |
11 |
Correct |
178 ms |
13212 KB |
Output is correct |
12 |
Correct |
175 ms |
13932 KB |
Output is correct |
13 |
Correct |
174 ms |
13264 KB |
Output is correct |
14 |
Correct |
184 ms |
14032 KB |
Output is correct |
15 |
Correct |
165 ms |
13280 KB |
Output is correct |
16 |
Correct |
177 ms |
14108 KB |
Output is correct |
17 |
Correct |
191 ms |
13252 KB |
Output is correct |
18 |
Correct |
100 ms |
4280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
10228 KB |
Output is correct |
2 |
Correct |
170 ms |
10996 KB |
Output is correct |
3 |
Correct |
115 ms |
4652 KB |
Output is correct |
4 |
Correct |
149 ms |
11040 KB |
Output is correct |
5 |
Correct |
158 ms |
12588 KB |
Output is correct |
6 |
Correct |
146 ms |
11692 KB |
Output is correct |
7 |
Correct |
142 ms |
12100 KB |
Output is correct |
8 |
Correct |
196 ms |
12956 KB |
Output is correct |
9 |
Correct |
164 ms |
12444 KB |
Output is correct |
10 |
Correct |
198 ms |
14004 KB |
Output is correct |
11 |
Correct |
178 ms |
13212 KB |
Output is correct |
12 |
Correct |
175 ms |
13932 KB |
Output is correct |
13 |
Correct |
174 ms |
13264 KB |
Output is correct |
14 |
Correct |
184 ms |
14032 KB |
Output is correct |
15 |
Correct |
165 ms |
13280 KB |
Output is correct |
16 |
Correct |
177 ms |
14108 KB |
Output is correct |
17 |
Correct |
191 ms |
13252 KB |
Output is correct |
18 |
Correct |
100 ms |
4280 KB |
Output is correct |
19 |
Correct |
921 ms |
18720 KB |
Output is correct |
20 |
Correct |
1104 ms |
19364 KB |
Output is correct |
21 |
Correct |
708 ms |
19996 KB |
Output is correct |
22 |
Correct |
649 ms |
17144 KB |
Output is correct |
23 |
Correct |
347 ms |
15940 KB |
Output is correct |
24 |
Correct |
332 ms |
14640 KB |
Output is correct |
25 |
Correct |
801 ms |
20968 KB |
Output is correct |
26 |
Correct |
785 ms |
19104 KB |
Output is correct |
27 |
Correct |
853 ms |
21364 KB |
Output is correct |
28 |
Correct |
868 ms |
19120 KB |
Output is correct |
29 |
Correct |
857 ms |
20968 KB |
Output is correct |
30 |
Correct |
322 ms |
16056 KB |
Output is correct |
31 |
Correct |
898 ms |
21356 KB |
Output is correct |
32 |
Correct |
850 ms |
18428 KB |
Output is correct |
33 |
Correct |
331 ms |
14616 KB |
Output is correct |
34 |
Correct |
808 ms |
19068 KB |
Output is correct |
35 |
Correct |
620 ms |
17708 KB |
Output is correct |
36 |
Correct |
324 ms |
14704 KB |
Output is correct |
37 |
Correct |
318 ms |
14696 KB |
Output is correct |
38 |
Correct |
1084 ms |
16532 KB |
Output is correct |
39 |
Correct |
689 ms |
15308 KB |
Output is correct |
40 |
Correct |
695 ms |
17708 KB |
Output is correct |
41 |
Correct |
858 ms |
9248 KB |
Output is correct |
42 |
Correct |
709 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
10228 KB |
Output is correct |
2 |
Correct |
170 ms |
10996 KB |
Output is correct |
3 |
Correct |
115 ms |
4652 KB |
Output is correct |
4 |
Correct |
149 ms |
11040 KB |
Output is correct |
5 |
Correct |
158 ms |
12588 KB |
Output is correct |
6 |
Correct |
146 ms |
11692 KB |
Output is correct |
7 |
Correct |
142 ms |
12100 KB |
Output is correct |
8 |
Correct |
196 ms |
12956 KB |
Output is correct |
9 |
Correct |
164 ms |
12444 KB |
Output is correct |
10 |
Correct |
198 ms |
14004 KB |
Output is correct |
11 |
Correct |
178 ms |
13212 KB |
Output is correct |
12 |
Correct |
175 ms |
13932 KB |
Output is correct |
13 |
Correct |
174 ms |
13264 KB |
Output is correct |
14 |
Correct |
184 ms |
14032 KB |
Output is correct |
15 |
Correct |
165 ms |
13280 KB |
Output is correct |
16 |
Correct |
177 ms |
14108 KB |
Output is correct |
17 |
Correct |
191 ms |
13252 KB |
Output is correct |
18 |
Correct |
100 ms |
4280 KB |
Output is correct |
19 |
Correct |
166 ms |
11988 KB |
Output is correct |
20 |
Correct |
116 ms |
5980 KB |
Output is correct |
21 |
Correct |
182 ms |
13356 KB |
Output is correct |
22 |
Correct |
141 ms |
11332 KB |
Output is correct |
23 |
Correct |
189 ms |
13544 KB |
Output is correct |
24 |
Correct |
178 ms |
12300 KB |
Output is correct |
25 |
Correct |
164 ms |
13332 KB |
Output is correct |
26 |
Correct |
152 ms |
11892 KB |
Output is correct |
27 |
Correct |
187 ms |
13504 KB |
Output is correct |
28 |
Correct |
155 ms |
12188 KB |
Output is correct |
29 |
Correct |
158 ms |
12752 KB |
Output is correct |
30 |
Correct |
136 ms |
11640 KB |
Output is correct |
31 |
Correct |
230 ms |
13576 KB |
Output is correct |
32 |
Correct |
165 ms |
13516 KB |
Output is correct |
33 |
Correct |
160 ms |
13008 KB |
Output is correct |
34 |
Correct |
136 ms |
11972 KB |
Output is correct |
35 |
Correct |
167 ms |
14020 KB |
Output is correct |
36 |
Correct |
178 ms |
13252 KB |
Output is correct |
37 |
Correct |
177 ms |
13988 KB |
Output is correct |
38 |
Correct |
205 ms |
13168 KB |
Output is correct |
39 |
Correct |
173 ms |
13996 KB |
Output is correct |
40 |
Correct |
181 ms |
13292 KB |
Output is correct |
41 |
Correct |
213 ms |
13944 KB |
Output is correct |
42 |
Correct |
187 ms |
13252 KB |
Output is correct |
43 |
Correct |
153 ms |
12568 KB |
Output is correct |
44 |
Correct |
175 ms |
12944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
10228 KB |
Output is correct |
2 |
Correct |
170 ms |
10996 KB |
Output is correct |
3 |
Correct |
115 ms |
4652 KB |
Output is correct |
4 |
Correct |
149 ms |
11040 KB |
Output is correct |
5 |
Correct |
158 ms |
12588 KB |
Output is correct |
6 |
Correct |
146 ms |
11692 KB |
Output is correct |
7 |
Correct |
142 ms |
12100 KB |
Output is correct |
8 |
Correct |
196 ms |
12956 KB |
Output is correct |
9 |
Correct |
164 ms |
12444 KB |
Output is correct |
10 |
Correct |
198 ms |
14004 KB |
Output is correct |
11 |
Correct |
178 ms |
13212 KB |
Output is correct |
12 |
Correct |
175 ms |
13932 KB |
Output is correct |
13 |
Correct |
174 ms |
13264 KB |
Output is correct |
14 |
Correct |
184 ms |
14032 KB |
Output is correct |
15 |
Correct |
165 ms |
13280 KB |
Output is correct |
16 |
Correct |
177 ms |
14108 KB |
Output is correct |
17 |
Correct |
191 ms |
13252 KB |
Output is correct |
18 |
Correct |
100 ms |
4280 KB |
Output is correct |
19 |
Correct |
921 ms |
18720 KB |
Output is correct |
20 |
Correct |
1104 ms |
19364 KB |
Output is correct |
21 |
Correct |
708 ms |
19996 KB |
Output is correct |
22 |
Correct |
649 ms |
17144 KB |
Output is correct |
23 |
Correct |
347 ms |
15940 KB |
Output is correct |
24 |
Correct |
332 ms |
14640 KB |
Output is correct |
25 |
Correct |
801 ms |
20968 KB |
Output is correct |
26 |
Correct |
785 ms |
19104 KB |
Output is correct |
27 |
Correct |
853 ms |
21364 KB |
Output is correct |
28 |
Correct |
868 ms |
19120 KB |
Output is correct |
29 |
Correct |
857 ms |
20968 KB |
Output is correct |
30 |
Correct |
322 ms |
16056 KB |
Output is correct |
31 |
Correct |
898 ms |
21356 KB |
Output is correct |
32 |
Correct |
850 ms |
18428 KB |
Output is correct |
33 |
Correct |
331 ms |
14616 KB |
Output is correct |
34 |
Correct |
808 ms |
19068 KB |
Output is correct |
35 |
Correct |
620 ms |
17708 KB |
Output is correct |
36 |
Correct |
324 ms |
14704 KB |
Output is correct |
37 |
Correct |
318 ms |
14696 KB |
Output is correct |
38 |
Correct |
1084 ms |
16532 KB |
Output is correct |
39 |
Correct |
689 ms |
15308 KB |
Output is correct |
40 |
Correct |
695 ms |
17708 KB |
Output is correct |
41 |
Correct |
858 ms |
9248 KB |
Output is correct |
42 |
Correct |
709 ms |
8540 KB |
Output is correct |
43 |
Correct |
166 ms |
11988 KB |
Output is correct |
44 |
Correct |
116 ms |
5980 KB |
Output is correct |
45 |
Correct |
182 ms |
13356 KB |
Output is correct |
46 |
Correct |
141 ms |
11332 KB |
Output is correct |
47 |
Correct |
189 ms |
13544 KB |
Output is correct |
48 |
Correct |
178 ms |
12300 KB |
Output is correct |
49 |
Correct |
164 ms |
13332 KB |
Output is correct |
50 |
Correct |
152 ms |
11892 KB |
Output is correct |
51 |
Correct |
187 ms |
13504 KB |
Output is correct |
52 |
Correct |
155 ms |
12188 KB |
Output is correct |
53 |
Correct |
158 ms |
12752 KB |
Output is correct |
54 |
Correct |
136 ms |
11640 KB |
Output is correct |
55 |
Correct |
230 ms |
13576 KB |
Output is correct |
56 |
Correct |
165 ms |
13516 KB |
Output is correct |
57 |
Correct |
160 ms |
13008 KB |
Output is correct |
58 |
Correct |
136 ms |
11972 KB |
Output is correct |
59 |
Correct |
167 ms |
14020 KB |
Output is correct |
60 |
Correct |
178 ms |
13252 KB |
Output is correct |
61 |
Correct |
177 ms |
13988 KB |
Output is correct |
62 |
Correct |
205 ms |
13168 KB |
Output is correct |
63 |
Correct |
173 ms |
13996 KB |
Output is correct |
64 |
Correct |
181 ms |
13292 KB |
Output is correct |
65 |
Correct |
213 ms |
13944 KB |
Output is correct |
66 |
Correct |
187 ms |
13252 KB |
Output is correct |
67 |
Correct |
153 ms |
12568 KB |
Output is correct |
68 |
Correct |
175 ms |
12944 KB |
Output is correct |
69 |
Correct |
966 ms |
18836 KB |
Output is correct |
70 |
Correct |
1229 ms |
22080 KB |
Output is correct |
71 |
Correct |
333 ms |
14788 KB |
Output is correct |
72 |
Correct |
355 ms |
14852 KB |
Output is correct |
73 |
Correct |
337 ms |
15000 KB |
Output is correct |
74 |
Correct |
667 ms |
18936 KB |
Output is correct |
75 |
Correct |
341 ms |
16024 KB |
Output is correct |
76 |
Correct |
779 ms |
21344 KB |
Output is correct |
77 |
Correct |
721 ms |
17772 KB |
Output is correct |
78 |
Correct |
314 ms |
14760 KB |
Output is correct |
79 |
Correct |
318 ms |
14816 KB |
Output is correct |
80 |
Correct |
737 ms |
19676 KB |
Output is correct |
81 |
Correct |
350 ms |
16088 KB |
Output is correct |
82 |
Correct |
954 ms |
23876 KB |
Output is correct |
83 |
Correct |
864 ms |
20844 KB |
Output is correct |
84 |
Correct |
338 ms |
14844 KB |
Output is correct |
85 |
Correct |
337 ms |
14900 KB |
Output is correct |
86 |
Correct |
769 ms |
18948 KB |
Output is correct |
87 |
Correct |
877 ms |
21940 KB |
Output is correct |
88 |
Correct |
351 ms |
14308 KB |
Output is correct |
89 |
Correct |
743 ms |
20272 KB |
Output is correct |
90 |
Correct |
868 ms |
22220 KB |
Output is correct |
91 |
Correct |
312 ms |
14240 KB |
Output is correct |
92 |
Correct |
733 ms |
19916 KB |
Output is correct |
93 |
Correct |
309 ms |
14916 KB |
Output is correct |
94 |
Correct |
337 ms |
14812 KB |
Output is correct |
95 |
Correct |
323 ms |
14908 KB |
Output is correct |
96 |
Correct |
1086 ms |
16628 KB |
Output is correct |
97 |
Correct |
728 ms |
19400 KB |
Output is correct |
98 |
Correct |
726 ms |
19480 KB |
Output is correct |
99 |
Correct |
989 ms |
11996 KB |
Output is correct |
100 |
Correct |
853 ms |
11176 KB |
Output is correct |