#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k; cin >> n >> k;
int rec_r[n+1], rec_l[n+1];
rep (i,1,n) rec_r[i] = rec_l[i] = i;
rep (q,1,n+k-1) {
char tp; cin >> tp;
if (tp=='S') {
int a, b; cin >> a >> b;
if (b<a) swap(a,b);
rec_r[a] = rec_r[b];
rec_l[b] = rec_l[a];
}
else if (tp=='Q') {
int a, d; cin >> a >> d;
if (d<a && rec_l[a]<=d) cout << "yes\n";
else if (d>a && rec_r[a]>=d) cout << "yes\n";
else cout << "no\n";
}
else {
int d; cin >> d;
int lo = d, hi = n, lo2 = 1, hi2 = d;
while (lo<hi) {
int mid = (lo+hi+1)/2;
if (rec_l[mid]<=d) lo = mid;
else hi = mid-1;
}
while (lo2<hi2) {
int mid = (lo2+hi2)/2;
if (rec_r[mid]>=d) hi2 = mid;
else lo2 = mid+1;
}
cout << lo-lo2+1 << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
708 KB |
Output is correct |
2 |
Incorrect |
46 ms |
1552 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
708 KB |
Output is correct |
2 |
Incorrect |
46 ms |
1552 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
572 KB |
Output is correct |
2 |
Incorrect |
49 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
572 KB |
Output is correct |
2 |
Incorrect |
49 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |