Submission #641301

#TimeUsernameProblemLanguageResultExecution timeMemory
641301CookieRegions (IOI09_regions)C++14
13 / 100
8077 ms30424 KiB
#include<bits/stdc++.h> using namespace std; #include<fstream> #define ll long long #define vt vector #define pb push_back #define fi first #define se second #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) typedef unsigned long long ull; #define pii pair<int, int> #define pll pair<ll, ll> #include<fstream> ifstream fin("milkorder.in"); ofstream fout("milkorder.out"); const ll mod = 1e9 + 7; const int mxn = 2e5, mxr = 25e3, sq = 446; int n, r, q, t = 0; vt<int>adj[mxn + 1], ob[mxn + 1]; vt<int>reg[mxr + 3]; int in[mxn + 1], out[mxn + 1], color[mxr + 1], h[mxn + 1]; void dfs(int s, int pre){ in[s] = ++t; color[t] = h[s]; for(auto i: adj[s]){ if(i != pre){ dfs(i, s); } } out[s] = t; } void solve(int r1, int r2){ } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> r >> q; cin >> h[1]; reg[h[1]].pb(1); forr(i, 2, n + 1){ int v; cin >> v >> h[i]; reg[h[i]].pb(i); adj[v].pb(i); } dfs(1, -1); forr(i, 1, n + 1)ob[color[i]].pb(i); for(int i = 0; i < q; i++){ int r1, r2; cin >> r1 >> r2; int ans = 0; for(auto j: reg[r1]){ ans += upper_bound(ob[r2].begin(), ob[r2].end(), out[j]) - lower_bound(ob[r2].begin(), ob[r2].end(), in[j]); } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...