#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 1<<17;
const int S = 256;
int cnt[N];
unsigned char cnt_buf[S]; int buf_sum = 0;
unsigned char pool[2*N][S];
int pool_size;
int ptr_pool[N];
__attribute__((optimize("O3,unroll-loops"),target("avx2")))
void merge(int i, int j)
{
if (ptr_pool[i] == -1 && ptr_pool[j] == -1)
return;
++buf_sum;
if (ptr_pool[i] == -1)
swap(i, j);
if (ptr_pool[j] == -1) {
i = ptr_pool[i];
Loop (k,0,S)
cnt_buf[k] -= pool[i][k];
ptr_pool[j] = i;
return;
}
int z = pool_size++;
int tmp;
tmp = ptr_pool[i]; ptr_pool[i] = z; i = tmp;
tmp = ptr_pool[j]; ptr_pool[j] = z; j = tmp;
Loop (k,0,S) {
cnt_buf[k] -= pool[i][k] ^ pool[j][k];
pool[z][k] = pool[i][k] | pool[j][k];
}
}
void buf_flush()
{
buf_sum = 0;
Loop (i,0,S) {
cnt[i] += cnt_buf[i];
cnt_buf[i] = 0;
}
}
int get_count(int i)
{
return cnt[i] + cnt_buf[i];
}
bool has(int i, int j)
{
if (ptr_pool[i] == -1)
return false;
i = ptr_pool[i];
return pool[i][j];
}
void init(int off)
{
buf_sum = 0;
pool_size = S;
Loop (i,0,S) {
cnt[i] = 1;
cnt_buf[i] = 0;
}
Loop (i,0,N)
ptr_pool[i] = -1;
Loop (i,0,S) {
ptr_pool[i+off] = i;
Loop (j,0,S)
pool[i][j] = 0;
pool[i][i] = -1;
}
}
int qans[N*2];
struct {
char type;
int a, b;
} qr[N*2];
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n, q;
cin >> n >> q;
q = n+q-1;
Loop (i,0,q) {
cin >> qr[i].type;
switch (qr[i].type) {
case 'S':
case 'Q':
cin >> qr[i].a >> qr[i].b;
break;
case 'C':
cin >> qr[i].a;
break;
}
--qr[i].a; --qr[i].b;
}
for (int off = 0; off < n; off += S) {
init(off);
Loop (i,0,q) {
int a = qr[i].a;
int b = qr[i].b;
switch (qr[i].type) {
case 'S':
merge(a, b);
break;
case 'Q':
if (off <= b && b < off + S)
qans[i] = has(a, b-off);
break;
case 'C':
if (off <= a && a < off + S)
qans[i] = get_count(a-off);
break;
}
if (buf_sum == 255)
buf_flush();
}
}
Loop (i,0,q) {
switch (qr[i].type) {
case 'Q': cout << (qans[i]? "yes": "no") << '\n'; break;
case 'C': cout << qans[i] << '\n'; break;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3148 KB |
Output is correct |
2 |
Correct |
32 ms |
3144 KB |
Output is correct |
3 |
Correct |
34 ms |
3300 KB |
Output is correct |
4 |
Correct |
32 ms |
3128 KB |
Output is correct |
5 |
Correct |
35 ms |
3192 KB |
Output is correct |
6 |
Correct |
33 ms |
3276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3148 KB |
Output is correct |
2 |
Correct |
32 ms |
3144 KB |
Output is correct |
3 |
Correct |
34 ms |
3300 KB |
Output is correct |
4 |
Correct |
32 ms |
3128 KB |
Output is correct |
5 |
Correct |
35 ms |
3192 KB |
Output is correct |
6 |
Correct |
33 ms |
3276 KB |
Output is correct |
7 |
Correct |
19 ms |
3156 KB |
Output is correct |
8 |
Correct |
41 ms |
3148 KB |
Output is correct |
9 |
Correct |
41 ms |
3268 KB |
Output is correct |
10 |
Correct |
40 ms |
3128 KB |
Output is correct |
11 |
Correct |
40 ms |
3180 KB |
Output is correct |
12 |
Correct |
41 ms |
3300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3196 KB |
Output is correct |
2 |
Correct |
1341 ms |
5112 KB |
Output is correct |
3 |
Correct |
1309 ms |
7960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3196 KB |
Output is correct |
2 |
Correct |
1341 ms |
5112 KB |
Output is correct |
3 |
Correct |
1309 ms |
7960 KB |
Output is correct |
4 |
Correct |
20 ms |
4040 KB |
Output is correct |
5 |
Correct |
1404 ms |
7876 KB |
Output is correct |
6 |
Correct |
1181 ms |
7020 KB |
Output is correct |
7 |
Correct |
1414 ms |
7116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3156 KB |
Output is correct |
2 |
Correct |
432 ms |
5176 KB |
Output is correct |
3 |
Correct |
423 ms |
5100 KB |
Output is correct |
4 |
Correct |
627 ms |
5320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3156 KB |
Output is correct |
2 |
Correct |
432 ms |
5176 KB |
Output is correct |
3 |
Correct |
423 ms |
5100 KB |
Output is correct |
4 |
Correct |
627 ms |
5320 KB |
Output is correct |
5 |
Correct |
20 ms |
3156 KB |
Output is correct |
6 |
Correct |
697 ms |
4984 KB |
Output is correct |
7 |
Correct |
811 ms |
5104 KB |
Output is correct |
8 |
Correct |
464 ms |
4972 KB |
Output is correct |
9 |
Correct |
475 ms |
5068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3156 KB |
Output is correct |
2 |
Correct |
554 ms |
5100 KB |
Output is correct |
3 |
Correct |
480 ms |
4876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3156 KB |
Output is correct |
2 |
Correct |
554 ms |
5100 KB |
Output is correct |
3 |
Correct |
480 ms |
4876 KB |
Output is correct |
4 |
Correct |
20 ms |
3156 KB |
Output is correct |
5 |
Correct |
811 ms |
5104 KB |
Output is correct |
6 |
Correct |
711 ms |
4820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
3040 KB |
Output is correct |
2 |
Correct |
450 ms |
5104 KB |
Output is correct |
3 |
Correct |
424 ms |
5196 KB |
Output is correct |
4 |
Correct |
614 ms |
5068 KB |
Output is correct |
5 |
Correct |
20 ms |
3128 KB |
Output is correct |
6 |
Correct |
535 ms |
5100 KB |
Output is correct |
7 |
Correct |
427 ms |
4876 KB |
Output is correct |
8 |
Correct |
484 ms |
4912 KB |
Output is correct |
9 |
Correct |
445 ms |
5044 KB |
Output is correct |
10 |
Correct |
708 ms |
5108 KB |
Output is correct |
11 |
Correct |
720 ms |
8432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
3040 KB |
Output is correct |
2 |
Correct |
450 ms |
5104 KB |
Output is correct |
3 |
Correct |
424 ms |
5196 KB |
Output is correct |
4 |
Correct |
614 ms |
5068 KB |
Output is correct |
5 |
Correct |
20 ms |
3128 KB |
Output is correct |
6 |
Correct |
535 ms |
5100 KB |
Output is correct |
7 |
Correct |
427 ms |
4876 KB |
Output is correct |
8 |
Correct |
484 ms |
4912 KB |
Output is correct |
9 |
Correct |
445 ms |
5044 KB |
Output is correct |
10 |
Correct |
708 ms |
5108 KB |
Output is correct |
11 |
Correct |
720 ms |
8432 KB |
Output is correct |
12 |
Correct |
20 ms |
4032 KB |
Output is correct |
13 |
Correct |
713 ms |
7936 KB |
Output is correct |
14 |
Correct |
830 ms |
8144 KB |
Output is correct |
15 |
Correct |
575 ms |
7504 KB |
Output is correct |
16 |
Correct |
477 ms |
7624 KB |
Output is correct |
17 |
Correct |
20 ms |
3916 KB |
Output is correct |
18 |
Correct |
787 ms |
8040 KB |
Output is correct |
19 |
Correct |
666 ms |
7676 KB |
Output is correct |
20 |
Correct |
693 ms |
7848 KB |
Output is correct |
21 |
Correct |
673 ms |
7996 KB |
Output is correct |
22 |
Correct |
754 ms |
7664 KB |
Output is correct |
23 |
Correct |
1206 ms |
7776 KB |
Output is correct |
24 |
Correct |
943 ms |
8016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3152 KB |
Output is correct |
2 |
Correct |
33 ms |
3144 KB |
Output is correct |
3 |
Correct |
33 ms |
3272 KB |
Output is correct |
4 |
Correct |
32 ms |
3156 KB |
Output is correct |
5 |
Correct |
32 ms |
3276 KB |
Output is correct |
6 |
Correct |
34 ms |
3304 KB |
Output is correct |
7 |
Correct |
19 ms |
3156 KB |
Output is correct |
8 |
Correct |
1392 ms |
5136 KB |
Output is correct |
9 |
Correct |
1336 ms |
7952 KB |
Output is correct |
10 |
Correct |
20 ms |
4052 KB |
Output is correct |
11 |
Correct |
456 ms |
8424 KB |
Output is correct |
12 |
Correct |
424 ms |
8432 KB |
Output is correct |
13 |
Correct |
623 ms |
8372 KB |
Output is correct |
14 |
Correct |
20 ms |
4044 KB |
Output is correct |
15 |
Correct |
549 ms |
8388 KB |
Output is correct |
16 |
Correct |
463 ms |
8192 KB |
Output is correct |
17 |
Correct |
488 ms |
8272 KB |
Output is correct |
18 |
Correct |
456 ms |
8292 KB |
Output is correct |
19 |
Correct |
688 ms |
8452 KB |
Output is correct |
20 |
Correct |
715 ms |
8436 KB |
Output is correct |
21 |
Correct |
1329 ms |
8544 KB |
Output is correct |
22 |
Correct |
1327 ms |
8500 KB |
Output is correct |
23 |
Correct |
903 ms |
8448 KB |
Output is correct |
24 |
Correct |
911 ms |
8424 KB |
Output is correct |
25 |
Correct |
978 ms |
8396 KB |
Output is correct |
26 |
Correct |
448 ms |
8140 KB |
Output is correct |
27 |
Correct |
475 ms |
8080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3152 KB |
Output is correct |
2 |
Correct |
33 ms |
3144 KB |
Output is correct |
3 |
Correct |
33 ms |
3272 KB |
Output is correct |
4 |
Correct |
32 ms |
3156 KB |
Output is correct |
5 |
Correct |
32 ms |
3276 KB |
Output is correct |
6 |
Correct |
34 ms |
3304 KB |
Output is correct |
7 |
Correct |
19 ms |
3156 KB |
Output is correct |
8 |
Correct |
1392 ms |
5136 KB |
Output is correct |
9 |
Correct |
1336 ms |
7952 KB |
Output is correct |
10 |
Correct |
20 ms |
4052 KB |
Output is correct |
11 |
Correct |
456 ms |
8424 KB |
Output is correct |
12 |
Correct |
424 ms |
8432 KB |
Output is correct |
13 |
Correct |
623 ms |
8372 KB |
Output is correct |
14 |
Correct |
20 ms |
4044 KB |
Output is correct |
15 |
Correct |
549 ms |
8388 KB |
Output is correct |
16 |
Correct |
463 ms |
8192 KB |
Output is correct |
17 |
Correct |
488 ms |
8272 KB |
Output is correct |
18 |
Correct |
456 ms |
8292 KB |
Output is correct |
19 |
Correct |
688 ms |
8452 KB |
Output is correct |
20 |
Correct |
715 ms |
8436 KB |
Output is correct |
21 |
Correct |
1329 ms |
8544 KB |
Output is correct |
22 |
Correct |
1327 ms |
8500 KB |
Output is correct |
23 |
Correct |
903 ms |
8448 KB |
Output is correct |
24 |
Correct |
911 ms |
8424 KB |
Output is correct |
25 |
Correct |
978 ms |
8396 KB |
Output is correct |
26 |
Correct |
448 ms |
8140 KB |
Output is correct |
27 |
Correct |
475 ms |
8080 KB |
Output is correct |
28 |
Correct |
21 ms |
3972 KB |
Output is correct |
29 |
Correct |
44 ms |
4248 KB |
Output is correct |
30 |
Correct |
43 ms |
4372 KB |
Output is correct |
31 |
Correct |
42 ms |
4176 KB |
Output is correct |
32 |
Correct |
41 ms |
4276 KB |
Output is correct |
33 |
Correct |
40 ms |
4496 KB |
Output is correct |
34 |
Correct |
21 ms |
4180 KB |
Output is correct |
35 |
Correct |
1391 ms |
7820 KB |
Output is correct |
36 |
Correct |
1197 ms |
7020 KB |
Output is correct |
37 |
Correct |
1406 ms |
7188 KB |
Output is correct |
38 |
Correct |
20 ms |
3916 KB |
Output is correct |
39 |
Correct |
673 ms |
8028 KB |
Output is correct |
40 |
Correct |
826 ms |
8128 KB |
Output is correct |
41 |
Correct |
461 ms |
7496 KB |
Output is correct |
42 |
Correct |
513 ms |
7624 KB |
Output is correct |
43 |
Correct |
20 ms |
3928 KB |
Output is correct |
44 |
Correct |
784 ms |
8128 KB |
Output is correct |
45 |
Correct |
686 ms |
7680 KB |
Output is correct |
46 |
Correct |
689 ms |
7904 KB |
Output is correct |
47 |
Correct |
677 ms |
7876 KB |
Output is correct |
48 |
Correct |
740 ms |
7664 KB |
Output is correct |
49 |
Correct |
1229 ms |
7884 KB |
Output is correct |
50 |
Correct |
954 ms |
8144 KB |
Output is correct |
51 |
Correct |
1220 ms |
8268 KB |
Output is correct |
52 |
Correct |
1346 ms |
8064 KB |
Output is correct |
53 |
Correct |
1267 ms |
7628 KB |
Output is correct |
54 |
Correct |
1227 ms |
8280 KB |
Output is correct |
55 |
Correct |
1280 ms |
8068 KB |
Output is correct |
56 |
Correct |
1137 ms |
8104 KB |
Output is correct |
57 |
Correct |
950 ms |
7988 KB |
Output is correct |
58 |
Correct |
589 ms |
7384 KB |
Output is correct |
59 |
Correct |
540 ms |
8012 KB |
Output is correct |