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>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n, k;
cin >> n >> k;
int pos[n + 1], cur = 0;
for (int i = 1; i <= n; i++)
pos[i] = (int) 1e9;
pos[1] = 0;
for (int q = 0; q < n + k - 1; q++) {
char t;
cin >> t;
if (t == 'S') {
int a, b;
cin >> a >> b;
if (a != 1)swap(a, b);
pos[b] = cur;
cur++;
} else if (t == 'Q') {
int a, b;
cin >> a >> b;
if (a == 1) {
if (pos[b] != (int) 1e9)
cout << "yes\n";
else
cout << "no\n";
continue;
}
if (b == 1) {
if (pos[a] != (int) 1e9)
cout << "yes\n";
else
cout << "no\n";
continue;
}
if (pos[a] != (int)1e9 && pos[a] >= pos[b])
cout << "yes\n";
else
cout << "no\n";
} else {
int d;
cin >> d;
if (d == 1) {
cout << cur + 1 << "\n";
continue;
}
if (pos[d] == (int) 1e9)cout << "1\n";
else cout << 1 + cur - pos[d] << "\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... |