#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;
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 5
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |