# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
355535 | 2021-01-22T16:47:11 Z | parsabahrami | Regions (IOI09_regions) | C++17 | 291 ms | 131076 KB |
// Call my Name and Save me from The Dark #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 2e5 + 10, SQ = 450; unordered_map<int, int> Cup[N], Cdown[N], C1[N], C2[N]; vector<pii> vec[N]; int A[N], S[N], St[N], Ft[N], n, R, q, tim; vector<int> adj[N]; void preDFS(int v) { St[v] = tim++; for (int u : adj[v]) { preDFS(u); } Ft[v] = tim; } void DFS(int v, int p = -1) { if (~p) { Cup[v] = Cup[p]; if (S[A[p]] > SQ) Cup[v][A[p]]++; } for (int u : adj[v]) { DFS(u, v); unordered_map<int, int> tmp = Cdown[u]; if (SZ(tmp) > SZ(Cdown[v])) Cdown[v].swap(tmp); for (pii x : tmp) Cdown[v][x.F] += x.S; if (S[A[u]] > SQ) Cdown[v][A[u]]++; } } int main() { scanf("%d%d%d%d", &n, &R, &q, &A[1]); for (int i = 2; i <= n; i++) { int p; scanf("%d%d", &p, &A[i]); adj[p].push_back(i); } preDFS(1); for (int i = 1; i <= n; i++) vec[A[i]].push_back({St[i], i}); for (int i = 1; i <= R; i++) sort(vec[i].begin(), vec[i].end()), S[i] = SZ(vec[i]); DFS(1); for (int i = 1; i <= n; i++) { for (pii x : Cup[i]) C1[A[i]][x.F] += x.S; for (pii x : Cdown[i]) C2[A[i]][x.F] += x.S; } for (; q; q--) { int r1, r2; scanf("%d%d", &r1, &r2); if (S[r1] > SQ) printf("%d\n", C1[r2][r1]); else if (S[r2] > SQ) printf("%d\n", C2[r1][r2]); else { int l = 0, r = 0, ret = 0; for (pii x : vec[r1]) { int v = x.S; while (r < S[r2] && vec[r2][r].F < Ft[v]) r++; while (l < r && vec[r2][l].F < St[v]) l++; if (l == S[r2]) continue; int u = vec[r2][l].S; if (St[v] <= St[u] && Ft[u] <= Ft[v]) ret += r - l; } printf("%d\n", ret); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 29 ms | 53612 KB | Time limit exceeded (wall clock) |
2 | Execution timed out | 30 ms | 53612 KB | Time limit exceeded (wall clock) |
3 | Execution timed out | 31 ms | 53612 KB | Time limit exceeded (wall clock) |
4 | Execution timed out | 29 ms | 53612 KB | Time limit exceeded (wall clock) |
5 | Execution timed out | 29 ms | 53612 KB | Time limit exceeded (wall clock) |
6 | Execution timed out | 29 ms | 53740 KB | Time limit exceeded (wall clock) |
7 | Execution timed out | 30 ms | 53612 KB | Time limit exceeded (wall clock) |
8 | Execution timed out | 31 ms | 53740 KB | Time limit exceeded (wall clock) |
9 | Execution timed out | 31 ms | 54764 KB | Time limit exceeded (wall clock) |
10 | Execution timed out | 34 ms | 54124 KB | Time limit exceeded (wall clock) |
11 | Execution timed out | 36 ms | 54508 KB | Time limit exceeded (wall clock) |
12 | Execution timed out | 39 ms | 55504 KB | Time limit exceeded (wall clock) |
13 | Execution timed out | 41 ms | 54636 KB | Time limit exceeded (wall clock) |
14 | Execution timed out | 48 ms | 55276 KB | Time limit exceeded (wall clock) |
15 | Execution timed out | 48 ms | 63340 KB | Time limit exceeded (wall clock) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 173 ms | 131076 KB | Execution killed with signal 9 |
2 | Execution timed out | 200 ms | 116332 KB | Time limit exceeded (wall clock) |
3 | Runtime error | 175 ms | 131076 KB | Execution killed with signal 9 |
4 | Execution timed out | 47 ms | 55532 KB | Time limit exceeded (wall clock) |
5 | Execution timed out | 48 ms | 60396 KB | Time limit exceeded (wall clock) |
6 | Runtime error | 167 ms | 131076 KB | Execution killed with signal 9 |
7 | Execution timed out | 224 ms | 124596 KB | Time limit exceeded (wall clock) |
8 | Runtime error | 160 ms | 131076 KB | Execution killed with signal 9 |
9 | Execution timed out | 136 ms | 65472 KB | Time limit exceeded (wall clock) |
10 | Runtime error | 181 ms | 131076 KB | Execution killed with signal 9 |
11 | Execution timed out | 155 ms | 62700 KB | Time limit exceeded (wall clock) |
12 | Execution timed out | 291 ms | 100332 KB | Time limit exceeded (wall clock) |
13 | Execution timed out | 250 ms | 100844 KB | Time limit exceeded (wall clock) |
14 | Runtime error | 241 ms | 131076 KB | Execution killed with signal 9 |
15 | Execution timed out | 244 ms | 119584 KB | Time limit exceeded (wall clock) |
16 | Runtime error | 202 ms | 131076 KB | Execution killed with signal 9 |
17 | Runtime error | 208 ms | 131076 KB | Execution killed with signal 9 |