#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, k, l[nx], r[nx], a, b;
char t;
struct fenwick
{
int d[nx];
void add(int i, int x) {while (i<nx) d[i]+=x, i+=(i&-i);}
int query(int i)
{
int res=0;
while (i>0) res+=d[i], i-=(i&-i);
return res;
}
} f;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
for (int i=1; i<=n; i++) l[i]=r[i]=i;
f.add(1, 1);
for (int i=1; i<n+k; i++)
{
cin>>t;
if (t=='S')
{
cin>>a>>b;
if (a>b) swap(a, b);
f.add(l[a], 1);
f.add(r[b]+1, -1);
r[a]=r[b];
l[b]=l[a];
}
if (t=='Q') cin>>a>>b, cout<<((l[a]<=b&&b<=r[a])?"yes\n":"no\n");
if (t=='C') cin>>a, cout<<f.query(a)<<'\n';
}
}
/*
5 7
S 1 2
Q 1 2
Q 1 3
S 3 4
C 3
S 2 3
C 2
Q 5 1
S 4 5
C 5
C 4
4 6
S 2 3
Q 1 3
Q 2 3
S 1 2
Q 3 1
Q 1 3
S 3 4
Q 4 2
Q 4 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1624 KB |
Output is correct |
2 |
Correct |
37 ms |
5644 KB |
Output is correct |
3 |
Correct |
37 ms |
5464 KB |
Output is correct |
4 |
Correct |
36 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1624 KB |
Output is correct |
2 |
Correct |
37 ms |
5644 KB |
Output is correct |
3 |
Correct |
37 ms |
5464 KB |
Output is correct |
4 |
Correct |
36 ms |
5460 KB |
Output is correct |
5 |
Correct |
12 ms |
1628 KB |
Output is correct |
6 |
Correct |
38 ms |
4992 KB |
Output is correct |
7 |
Correct |
42 ms |
5204 KB |
Output is correct |
8 |
Correct |
37 ms |
4628 KB |
Output is correct |
9 |
Correct |
36 ms |
4604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
1704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
1704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1628 KB |
Output is correct |
2 |
Correct |
37 ms |
5560 KB |
Output is correct |
3 |
Correct |
42 ms |
5464 KB |
Output is correct |
4 |
Correct |
36 ms |
5452 KB |
Output is correct |
5 |
Incorrect |
12 ms |
1744 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1628 KB |
Output is correct |
2 |
Correct |
37 ms |
5560 KB |
Output is correct |
3 |
Correct |
42 ms |
5464 KB |
Output is correct |
4 |
Correct |
36 ms |
5452 KB |
Output is correct |
5 |
Incorrect |
12 ms |
1744 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |