#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
int n, k;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
int q = n + k - 1;
vector<int> tm(n + 1);
vector<pair<int, pii>> qry;
for(int i = 0; i < q; i++){
string s;
cin >> s;
if(s == "S"){
int u, v;
cin >> u >> v;
if(u > v) swap(u, v);
assert(u == 1);
tm[v] = i;
}
else if(s == "Q"){
int a, d;
cin >> a >> d;
qry.eb(mp(i, mp(a, d)));
}
else{
int d;
cin >> d;
qry.eb(mp(i, mp(-1, d)));
}
}
vector<int> tmp = tm;
tmp.erase(tmp.begin());
tmp.erase(tmp.begin());
lsort(tmp);
for(auto i : qry){
int t = i.F;
int a = i.S.F, d = i.S.S;
if(a != -1){
if(a == d){
cout << "yes\n";
continue;
}
if(tm[d] > t || tm[a] > t){
cout << "no\n";
continue;
}
if(a == 1 || d == 1 || tm[d] < tm[a]) cout << "yes\n";
else cout << "no\n";
continue;
}
if(d == 1){
int ans = upper_bound(iter(tmp), t) - tmp.begin() + 1;
cout << ans << "\n";
continue;
}
if(tm[d] > t){
cout << "1\n";
continue;
}
int st = lower_bound(iter(tmp), tm[d]) - tmp.begin();
int ed = upper_bound(iter(tmp), t) - tmp.begin();
cout << ed - st + 1 << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2248 KB |
Output is correct |
2 |
Correct |
100 ms |
3064 KB |
Output is correct |
3 |
Correct |
95 ms |
3052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2248 KB |
Output is correct |
2 |
Correct |
100 ms |
3064 KB |
Output is correct |
3 |
Correct |
95 ms |
3052 KB |
Output is correct |
4 |
Correct |
37 ms |
2880 KB |
Output is correct |
5 |
Correct |
93 ms |
5776 KB |
Output is correct |
6 |
Correct |
86 ms |
5048 KB |
Output is correct |
7 |
Correct |
87 ms |
5088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |