//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------Kargpefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
void KarginSet(string name = "") {
ios_base::sync_with_stdio(false); cin.tie(NULL);
if (name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
//-------------------KarginConstants------------------\\
const ll mod = 998244353;
const ll inf = 1e9;
//-------------------KarginCode-----------------------\\
const int N = 500005, M = 1000005;
int n, q;
vector<pair<int, int>> g[N];
bool dfs_q(int u, int p, int cur, int t) {
if (u == t) return true;
for (auto it : g[u]) {
int v = it.first, ind = it.second;
if (v == p) continue;
if (cur > ind) continue;
if (dfs_q(v, u, ind, t)) return true;
}
return false;
}
int dfs_c(int u, int p,int cur) {
int res = 1;
for (auto it : g[u]) {
int v = it.first, ind = it.second;
if (v == p) continue;
if (cur > ind) continue;
res += dfs_c(v, u, ind);
}
return res;
}
int tree[4 * N];
struct segtree {
int size = 1;
void init() {
while (size < n) size <<= 1;
}
void push(int x, int lx, int rx) {
if (rx - lx == 1) return;
tree[2 * x + 1] += tree[x], tree[2 * x + 2] += tree[x];
tree[x] = 0;
}
void set(int l, int r, int x, int lx, int rx) {
push(x, lx, rx);
if (lx >= r || rx <= l) return;
if (lx >= l && rx <= r) {
tree[x]++;
return;
}
int m = (lx + rx) / 2;
set(l, r, 2 * x + 1, lx, m);
set(l, r, 2 * x + 2, m, rx);
}
void set(int l, int r) {
set(l, r, 0, 0, size);
}
int get(int i, int x, int lx, int rx) {
push(x, lx, rx);
if (rx - lx == 1) return tree[x];
int m = (lx + rx) / 2;
if (i < m) return get(i, 2 * x + 1, lx, m);
return get(i, 2 * x + 2, m, rx);
}
int get(int i) {
return get(i, 0, 0, size);
}
};
void KarginSolve() {
cin >> n >> q;
vector<int> ind(n + 1, inf);
ind[1] = 0;
int l = 1;
segtree st;
st.init();
st.set(0, 1);
for (int i = 1;i <= n - 1 + q;i++) {
char type; cin >> type;
if (type == 'S') {
int u, v;
cin >> u >> v;
if (u == 1) swap(u, v);
ind[u] = l++;
st.set(0, ind[u] + 1);
st.set(ind[u], ind[u] + 1);
}
else if (type == 'Q') {
int u, v;
cin >> u >> v;
if (u == 1 || v == 1) cout << "yes\n";
else {
if (ind[u] == inf || ind[v] == inf) cout << "no\n";
else if (ind[u] >= ind[v]) cout << "yes\n";
else cout << "no\n";
}
}
else {
int u; cin >> u;
cout << st.get(ind[u]) << '\n';
}
}
}
int main() {
KarginSet();
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message
servers.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
servers.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------Kargpefines--------------------\\
| ^
servers.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginConstants------------------\\
| ^
servers.cpp:32:1: warning: multi-line comment [-Wcomment]
32 | //-------------------KarginCode-----------------------\\
| ^
servers.cpp: In function 'void KarginSet(std::string)':
servers.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
servers.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
13400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
13400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
13400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
13400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
13404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |