This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |