이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define ll long long
#define nl '\n'
const int N = 200200, R = 25025;
int n, r, q, timer=0, tin[N], tout[N];
vector<int> adj[N], color[R];
indexed_set<int> b[R];
void dfs(int s=0, int e=-1) {
tin[s] = timer++;
for (int node:adj[s]) {
if (node==e) continue;
dfs(node,s);
}
tout[s] = timer-1;
}
int main() {
// setIO("");
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> r >> q;
int l; cin >> l; color[l].pb(0);
for (int i=1, s, e;i<=n-1;i++) {
cin >> s >> e;
s--;
adj[s].pb(i), adj[i].pb(s);
color[e].pb(i);
}
dfs();
for (int i = 0; i < n; i++)
cout << tin[i] << " " << tout[i] << nl;
for (int i = 0; i < R; i++) {
for (int j: color[i]) {
b[i].insert(tin[j]);
}
}
while(q--) {
int i, j; cin >> i >> j;
int ans = 0;
for (int parent:color[i]) {
int hi = b[j].order_of_key(tout[parent]+1);
int lo = b[j].order_of_key(tin[parent]);
ans += (hi - lo);
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |