#include<bits/stdc++.h>
using namespace std ;
struct query
{
char type ;
int a, b ;
};
int n, k ;
vector<query> v ;
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
cin >> n >> k ;
for(int i = 1 ; i < n + k ; i++)
{
query q ;
cin >> q.type >> q.a ;
if(q.type != 'C')cin >> q.b ;
v.push_back(q) ;
}
if(n <= 4000)
{
set<int> s[n + 1] ;
int kol[n + 1] = {} ;
for(int i = 1 ; i <= n ; i++)
{
s[i].insert(i) ;
kol[i] = 1 ;
}
for(query q : v)
{
if(q.type == 'S')
{
set<int> all ;
for(int i : s[q.a])
all.insert(i) ;
for(int i : s[q.b])
all.insert(i) ;
for(int i : all)
if(!s[q.a].count(i) || !s[q.b].count(i))kol[i]++ ;
s[q.a] = all ;
s[q.b] = all ;
}
if(q.type == 'Q')
{
if(s[q.a].count(q.b))cout << "yes\n" ;
else cout << "no\n" ;
}
if(q.type == 'C')
cout << kol[q.a] << '\n' ;
}
return 0 ;
}
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3008 KB |
Output is correct |
2 |
Correct |
27 ms |
4972 KB |
Output is correct |
3 |
Correct |
197 ms |
50468 KB |
Output is correct |
4 |
Correct |
25 ms |
4604 KB |
Output is correct |
5 |
Correct |
23 ms |
4540 KB |
Output is correct |
6 |
Correct |
2191 ms |
379968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3008 KB |
Output is correct |
2 |
Correct |
27 ms |
4972 KB |
Output is correct |
3 |
Correct |
197 ms |
50468 KB |
Output is correct |
4 |
Correct |
25 ms |
4604 KB |
Output is correct |
5 |
Correct |
23 ms |
4540 KB |
Output is correct |
6 |
Correct |
2191 ms |
379968 KB |
Output is correct |
7 |
Correct |
16 ms |
3016 KB |
Output is correct |
8 |
Correct |
33 ms |
4724 KB |
Output is correct |
9 |
Correct |
227 ms |
62416 KB |
Output is correct |
10 |
Correct |
22 ms |
4372 KB |
Output is correct |
11 |
Correct |
22 ms |
4160 KB |
Output is correct |
12 |
Correct |
2115 ms |
379796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3144 KB |
Output is correct |
2 |
Incorrect |
31 ms |
6020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3144 KB |
Output is correct |
2 |
Incorrect |
31 ms |
6020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3016 KB |
Output is correct |
2 |
Incorrect |
33 ms |
6500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3016 KB |
Output is correct |
2 |
Incorrect |
33 ms |
6500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3000 KB |
Output is correct |
2 |
Incorrect |
33 ms |
6432 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3000 KB |
Output is correct |
2 |
Incorrect |
33 ms |
6432 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3108 KB |
Output is correct |
2 |
Incorrect |
33 ms |
6504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3108 KB |
Output is correct |
2 |
Incorrect |
33 ms |
6504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3092 KB |
Output is correct |
2 |
Correct |
26 ms |
4948 KB |
Output is correct |
3 |
Correct |
204 ms |
50572 KB |
Output is correct |
4 |
Correct |
28 ms |
4704 KB |
Output is correct |
5 |
Correct |
26 ms |
4548 KB |
Output is correct |
6 |
Correct |
2154 ms |
379932 KB |
Output is correct |
7 |
Correct |
16 ms |
3116 KB |
Output is correct |
8 |
Incorrect |
32 ms |
6080 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3092 KB |
Output is correct |
2 |
Correct |
26 ms |
4948 KB |
Output is correct |
3 |
Correct |
204 ms |
50572 KB |
Output is correct |
4 |
Correct |
28 ms |
4704 KB |
Output is correct |
5 |
Correct |
26 ms |
4548 KB |
Output is correct |
6 |
Correct |
2154 ms |
379932 KB |
Output is correct |
7 |
Correct |
16 ms |
3116 KB |
Output is correct |
8 |
Incorrect |
32 ms |
6080 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |