#include <stdio.h>
#include <string.h>
#define N 200000
#define N_ (1 << 18) /* N_ = pow2(ceil(log2(N))) */
#define MD 0x7fffffff
char *joi = "JOI";
int X = 469762049, Y = 595591169;
int ppx[N + 1], ppy[N + 1];
void init() {
int i;
ppx[0] = ppy[0] = 1;
for (i = 1; i <= N; i++) {
ppx[i] = (long long) ppx[i - 1] * X % MD;
ppy[i] = (long long) ppy[i - 1] * Y % MD;
}
}
int xx_[N_ * 2], yy_[N_ * 2], xx1[N_ * 2][3], yy1[N_ * 2][3], lz[N_], h_, n_;
void put(int i, int d) {
xx_[i] = xx1[i][d], yy_[i] = yy1[i][d];
if (i < n_)
lz[i] = d;
}
void pus(int i) {
if (lz[i] != -1)
put(i << 1 | 0, lz[i]), put(i << 1 | 1, lz[i]), lz[i] = -1;
}
void pul(int i) {
if (lz[i] == -1) {
int l = i << 1, r = l | 1;
xx_[i] = ((long long) xx_[l] + xx_[r]) % MD;
yy_[i] = ((long long) yy_[l] + yy_[r]) % MD;
}
}
void push(int i) {
int h;
for (h = h_; h > 0; h--)
pus(i >> h);
}
void pull(int i) {
while (i > 1)
pul(i >>= 1);
}
void build(char *cc, int n) {
int i, l, r, d;
h_ = 0;
while (1 << h_ < n)
h_++;
n_ = 1 << h_;
for (i = 0; i < n; i++) {
for (d = 0; d < 3; d++) {
xx1[n_ + i][d] = (long long) d * ppx[i] % MD;
yy1[n_ + i][d] = (long long) d * ppy[i] % MD;
}
xx_[n_ + i] = (long long) cc[i] * ppx[i] % MD;
yy_[n_ + i] = (long long) cc[i] * ppy[i] % MD;
}
memset(lz, -1, n_ * sizeof *lz);
for (i = n_ - 1; i > 0; i--) {
l = i << 1, r = l | 1;
for (d = 0; d < 3; d++) {
xx1[i][d] = ((long long) xx1[l][d] + xx1[r][d]) % MD;
yy1[i][d] = ((long long) yy1[l][d] + yy1[r][d]) % MD;
}
pul(i);
}
}
void update(int l, int r, int d) {
int l_ = l += n_, r_ = r += n_;
push(l_), push(r_);
for ( ; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1)
put(l++, d);
if ((r & 1) == 0)
put(r--, d);
}
pull(l_), pull(r_);
}
int main() {
static char ss[3][N + 1], cc[N + 1];
static int xx[3][3], yy[3][3];
int n, q, h, i, a, b, c, d, x, y, yes;
scanf("%d", &n), init();
for (h = 0; h < 3; h++) {
scanf("%s", ss[h]);
for (i = 0; i < n; i++)
ss[h][i] = strchr(joi, ss[h][i]) - joi;
}
for (a = 0; a < 3; a++)
for (b = 0; b < 3; b++) {
c = (4 - a - b) % 3;
x = y = 0;
for (i = 0; i < n; i++) {
d = (ss[0][i] * a + ss[1][i] * b + ss[2][i] * c) % 3;
x = (x + (long long) d * ppx[i]) % MD;
y = (y + (long long) d * ppy[i]) % MD;
}
xx[a][b] = x, yy[a][b] = y;
}
scanf("%d%s", &q, cc);
for (i = 0; i < n; i++)
cc[i] = strchr(joi, cc[i]) - joi;
build(cc, n);
yes = 0;
for (a = 0; a < 3; a++)
for (b = 0; b < 3; b++)
if (xx_[1] == xx[a][b] && yy_[1] == yy[a][b]) {
yes = 1;
goto out;
}
out:
printf(yes ? "Yes\n" : "No\n");
while (q--) {
static char s[2];
int l, r;
scanf("%d%d%s", &l, &r, s), l--, r--;
d = strchr(joi, s[0]) - joi;
update(l, r, d);
yes = 0;
for (a = 0; a < 3; a++)
for (b = 0; b < 3; b++)
if (xx_[1] == xx[a][b] && yy_[1] == yy[a][b]) {
yes = 1;
goto out_;
}
out_:
printf(yes ? "Yes\n" : "No\n");
}
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:102:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | scanf("%d", &n), init();
| ^~~~~~~~~~~~~~~
Main.c:104:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | scanf("%s", ss[h]);
| ^~~~~~~~~~~~~~~~~~
Main.c:119:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
119 | scanf("%d%s", &q, cc);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:136:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
136 | scanf("%d%d%s", &l, &r, s), l--, r--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
3756 KB |
Output is correct |
2 |
Correct |
89 ms |
4008 KB |
Output is correct |
3 |
Correct |
86 ms |
3792 KB |
Output is correct |
4 |
Correct |
85 ms |
3864 KB |
Output is correct |
5 |
Correct |
78 ms |
3868 KB |
Output is correct |
6 |
Correct |
86 ms |
3768 KB |
Output is correct |
7 |
Correct |
84 ms |
3848 KB |
Output is correct |
8 |
Correct |
91 ms |
3916 KB |
Output is correct |
9 |
Correct |
86 ms |
3960 KB |
Output is correct |
10 |
Correct |
83 ms |
4008 KB |
Output is correct |
11 |
Correct |
88 ms |
4008 KB |
Output is correct |
12 |
Correct |
88 ms |
3916 KB |
Output is correct |
13 |
Correct |
87 ms |
3916 KB |
Output is correct |
14 |
Correct |
92 ms |
4064 KB |
Output is correct |
15 |
Correct |
95 ms |
3940 KB |
Output is correct |
16 |
Correct |
97 ms |
4028 KB |
Output is correct |
17 |
Correct |
109 ms |
3944 KB |
Output is correct |
18 |
Correct |
91 ms |
3936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
3756 KB |
Output is correct |
2 |
Correct |
89 ms |
4008 KB |
Output is correct |
3 |
Correct |
86 ms |
3792 KB |
Output is correct |
4 |
Correct |
85 ms |
3864 KB |
Output is correct |
5 |
Correct |
78 ms |
3868 KB |
Output is correct |
6 |
Correct |
86 ms |
3768 KB |
Output is correct |
7 |
Correct |
84 ms |
3848 KB |
Output is correct |
8 |
Correct |
91 ms |
3916 KB |
Output is correct |
9 |
Correct |
86 ms |
3960 KB |
Output is correct |
10 |
Correct |
83 ms |
4008 KB |
Output is correct |
11 |
Correct |
88 ms |
4008 KB |
Output is correct |
12 |
Correct |
88 ms |
3916 KB |
Output is correct |
13 |
Correct |
87 ms |
3916 KB |
Output is correct |
14 |
Correct |
92 ms |
4064 KB |
Output is correct |
15 |
Correct |
95 ms |
3940 KB |
Output is correct |
16 |
Correct |
97 ms |
4028 KB |
Output is correct |
17 |
Correct |
109 ms |
3944 KB |
Output is correct |
18 |
Correct |
91 ms |
3936 KB |
Output is correct |
19 |
Correct |
291 ms |
22532 KB |
Output is correct |
20 |
Correct |
257 ms |
22256 KB |
Output is correct |
21 |
Correct |
238 ms |
21708 KB |
Output is correct |
22 |
Correct |
221 ms |
20888 KB |
Output is correct |
23 |
Correct |
162 ms |
5676 KB |
Output is correct |
24 |
Correct |
133 ms |
5660 KB |
Output is correct |
25 |
Correct |
237 ms |
22312 KB |
Output is correct |
26 |
Correct |
278 ms |
22492 KB |
Output is correct |
27 |
Correct |
239 ms |
22416 KB |
Output is correct |
28 |
Correct |
249 ms |
22348 KB |
Output is correct |
29 |
Correct |
254 ms |
22048 KB |
Output is correct |
30 |
Correct |
142 ms |
5708 KB |
Output is correct |
31 |
Correct |
286 ms |
22368 KB |
Output is correct |
32 |
Correct |
238 ms |
21588 KB |
Output is correct |
33 |
Correct |
126 ms |
5724 KB |
Output is correct |
34 |
Correct |
264 ms |
22492 KB |
Output is correct |
35 |
Correct |
238 ms |
20104 KB |
Output is correct |
36 |
Correct |
135 ms |
5708 KB |
Output is correct |
37 |
Correct |
125 ms |
5636 KB |
Output is correct |
38 |
Correct |
252 ms |
22140 KB |
Output is correct |
39 |
Correct |
181 ms |
22420 KB |
Output is correct |
40 |
Correct |
215 ms |
14976 KB |
Output is correct |
41 |
Correct |
282 ms |
22532 KB |
Output is correct |
42 |
Correct |
279 ms |
21816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
3756 KB |
Output is correct |
2 |
Correct |
89 ms |
4008 KB |
Output is correct |
3 |
Correct |
86 ms |
3792 KB |
Output is correct |
4 |
Correct |
85 ms |
3864 KB |
Output is correct |
5 |
Correct |
78 ms |
3868 KB |
Output is correct |
6 |
Correct |
86 ms |
3768 KB |
Output is correct |
7 |
Correct |
84 ms |
3848 KB |
Output is correct |
8 |
Correct |
91 ms |
3916 KB |
Output is correct |
9 |
Correct |
86 ms |
3960 KB |
Output is correct |
10 |
Correct |
83 ms |
4008 KB |
Output is correct |
11 |
Correct |
88 ms |
4008 KB |
Output is correct |
12 |
Correct |
88 ms |
3916 KB |
Output is correct |
13 |
Correct |
87 ms |
3916 KB |
Output is correct |
14 |
Correct |
92 ms |
4064 KB |
Output is correct |
15 |
Correct |
95 ms |
3940 KB |
Output is correct |
16 |
Correct |
97 ms |
4028 KB |
Output is correct |
17 |
Correct |
109 ms |
3944 KB |
Output is correct |
18 |
Correct |
91 ms |
3936 KB |
Output is correct |
19 |
Correct |
91 ms |
3872 KB |
Output is correct |
20 |
Correct |
85 ms |
3832 KB |
Output is correct |
21 |
Correct |
90 ms |
3976 KB |
Output is correct |
22 |
Correct |
84 ms |
3760 KB |
Output is correct |
23 |
Correct |
85 ms |
3912 KB |
Output is correct |
24 |
Correct |
81 ms |
3884 KB |
Output is correct |
25 |
Correct |
84 ms |
3900 KB |
Output is correct |
26 |
Correct |
102 ms |
3800 KB |
Output is correct |
27 |
Correct |
88 ms |
3916 KB |
Output is correct |
28 |
Correct |
75 ms |
3700 KB |
Output is correct |
29 |
Correct |
84 ms |
3904 KB |
Output is correct |
30 |
Correct |
90 ms |
3836 KB |
Output is correct |
31 |
Correct |
89 ms |
3896 KB |
Output is correct |
32 |
Correct |
82 ms |
3912 KB |
Output is correct |
33 |
Correct |
86 ms |
4076 KB |
Output is correct |
34 |
Correct |
89 ms |
3852 KB |
Output is correct |
35 |
Correct |
86 ms |
3896 KB |
Output is correct |
36 |
Correct |
84 ms |
4000 KB |
Output is correct |
37 |
Correct |
83 ms |
4000 KB |
Output is correct |
38 |
Correct |
111 ms |
3992 KB |
Output is correct |
39 |
Correct |
85 ms |
3960 KB |
Output is correct |
40 |
Correct |
84 ms |
4008 KB |
Output is correct |
41 |
Correct |
84 ms |
3912 KB |
Output is correct |
42 |
Correct |
104 ms |
4144 KB |
Output is correct |
43 |
Correct |
88 ms |
4044 KB |
Output is correct |
44 |
Correct |
89 ms |
4032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
3756 KB |
Output is correct |
2 |
Correct |
89 ms |
4008 KB |
Output is correct |
3 |
Correct |
86 ms |
3792 KB |
Output is correct |
4 |
Correct |
85 ms |
3864 KB |
Output is correct |
5 |
Correct |
78 ms |
3868 KB |
Output is correct |
6 |
Correct |
86 ms |
3768 KB |
Output is correct |
7 |
Correct |
84 ms |
3848 KB |
Output is correct |
8 |
Correct |
91 ms |
3916 KB |
Output is correct |
9 |
Correct |
86 ms |
3960 KB |
Output is correct |
10 |
Correct |
83 ms |
4008 KB |
Output is correct |
11 |
Correct |
88 ms |
4008 KB |
Output is correct |
12 |
Correct |
88 ms |
3916 KB |
Output is correct |
13 |
Correct |
87 ms |
3916 KB |
Output is correct |
14 |
Correct |
92 ms |
4064 KB |
Output is correct |
15 |
Correct |
95 ms |
3940 KB |
Output is correct |
16 |
Correct |
97 ms |
4028 KB |
Output is correct |
17 |
Correct |
109 ms |
3944 KB |
Output is correct |
18 |
Correct |
91 ms |
3936 KB |
Output is correct |
19 |
Correct |
291 ms |
22532 KB |
Output is correct |
20 |
Correct |
257 ms |
22256 KB |
Output is correct |
21 |
Correct |
238 ms |
21708 KB |
Output is correct |
22 |
Correct |
221 ms |
20888 KB |
Output is correct |
23 |
Correct |
162 ms |
5676 KB |
Output is correct |
24 |
Correct |
133 ms |
5660 KB |
Output is correct |
25 |
Correct |
237 ms |
22312 KB |
Output is correct |
26 |
Correct |
278 ms |
22492 KB |
Output is correct |
27 |
Correct |
239 ms |
22416 KB |
Output is correct |
28 |
Correct |
249 ms |
22348 KB |
Output is correct |
29 |
Correct |
254 ms |
22048 KB |
Output is correct |
30 |
Correct |
142 ms |
5708 KB |
Output is correct |
31 |
Correct |
286 ms |
22368 KB |
Output is correct |
32 |
Correct |
238 ms |
21588 KB |
Output is correct |
33 |
Correct |
126 ms |
5724 KB |
Output is correct |
34 |
Correct |
264 ms |
22492 KB |
Output is correct |
35 |
Correct |
238 ms |
20104 KB |
Output is correct |
36 |
Correct |
135 ms |
5708 KB |
Output is correct |
37 |
Correct |
125 ms |
5636 KB |
Output is correct |
38 |
Correct |
252 ms |
22140 KB |
Output is correct |
39 |
Correct |
181 ms |
22420 KB |
Output is correct |
40 |
Correct |
215 ms |
14976 KB |
Output is correct |
41 |
Correct |
282 ms |
22532 KB |
Output is correct |
42 |
Correct |
279 ms |
21816 KB |
Output is correct |
43 |
Correct |
91 ms |
3872 KB |
Output is correct |
44 |
Correct |
85 ms |
3832 KB |
Output is correct |
45 |
Correct |
90 ms |
3976 KB |
Output is correct |
46 |
Correct |
84 ms |
3760 KB |
Output is correct |
47 |
Correct |
85 ms |
3912 KB |
Output is correct |
48 |
Correct |
81 ms |
3884 KB |
Output is correct |
49 |
Correct |
84 ms |
3900 KB |
Output is correct |
50 |
Correct |
102 ms |
3800 KB |
Output is correct |
51 |
Correct |
88 ms |
3916 KB |
Output is correct |
52 |
Correct |
75 ms |
3700 KB |
Output is correct |
53 |
Correct |
84 ms |
3904 KB |
Output is correct |
54 |
Correct |
90 ms |
3836 KB |
Output is correct |
55 |
Correct |
89 ms |
3896 KB |
Output is correct |
56 |
Correct |
82 ms |
3912 KB |
Output is correct |
57 |
Correct |
86 ms |
4076 KB |
Output is correct |
58 |
Correct |
89 ms |
3852 KB |
Output is correct |
59 |
Correct |
86 ms |
3896 KB |
Output is correct |
60 |
Correct |
84 ms |
4000 KB |
Output is correct |
61 |
Correct |
83 ms |
4000 KB |
Output is correct |
62 |
Correct |
111 ms |
3992 KB |
Output is correct |
63 |
Correct |
85 ms |
3960 KB |
Output is correct |
64 |
Correct |
84 ms |
4008 KB |
Output is correct |
65 |
Correct |
84 ms |
3912 KB |
Output is correct |
66 |
Correct |
104 ms |
4144 KB |
Output is correct |
67 |
Correct |
88 ms |
4044 KB |
Output is correct |
68 |
Correct |
89 ms |
4032 KB |
Output is correct |
69 |
Correct |
313 ms |
20692 KB |
Output is correct |
70 |
Correct |
235 ms |
22316 KB |
Output is correct |
71 |
Correct |
137 ms |
5672 KB |
Output is correct |
72 |
Correct |
156 ms |
5748 KB |
Output is correct |
73 |
Correct |
133 ms |
5816 KB |
Output is correct |
74 |
Correct |
227 ms |
20708 KB |
Output is correct |
75 |
Correct |
130 ms |
5744 KB |
Output is correct |
76 |
Correct |
241 ms |
22352 KB |
Output is correct |
77 |
Correct |
221 ms |
21000 KB |
Output is correct |
78 |
Correct |
126 ms |
5684 KB |
Output is correct |
79 |
Correct |
135 ms |
5820 KB |
Output is correct |
80 |
Correct |
199 ms |
19744 KB |
Output is correct |
81 |
Correct |
128 ms |
5648 KB |
Output is correct |
82 |
Correct |
282 ms |
22348 KB |
Output is correct |
83 |
Correct |
219 ms |
21716 KB |
Output is correct |
84 |
Correct |
133 ms |
5692 KB |
Output is correct |
85 |
Correct |
123 ms |
5632 KB |
Output is correct |
86 |
Correct |
217 ms |
20220 KB |
Output is correct |
87 |
Correct |
258 ms |
22368 KB |
Output is correct |
88 |
Correct |
137 ms |
5780 KB |
Output is correct |
89 |
Correct |
231 ms |
21172 KB |
Output is correct |
90 |
Correct |
261 ms |
22368 KB |
Output is correct |
91 |
Correct |
131 ms |
5708 KB |
Output is correct |
92 |
Correct |
209 ms |
20220 KB |
Output is correct |
93 |
Correct |
139 ms |
5652 KB |
Output is correct |
94 |
Correct |
143 ms |
5820 KB |
Output is correct |
95 |
Correct |
139 ms |
5784 KB |
Output is correct |
96 |
Correct |
253 ms |
22124 KB |
Output is correct |
97 |
Correct |
213 ms |
22444 KB |
Output is correct |
98 |
Correct |
189 ms |
14900 KB |
Output is correct |
99 |
Correct |
311 ms |
22604 KB |
Output is correct |
100 |
Correct |
260 ms |
21740 KB |
Output is correct |