# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47378 | 2018-05-02T06:32:28 Z | Just_Solve_The_Problem | Construction of Highway (JOI18_construction) | C++11 | 1000 ms | 62024 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define ll long long #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() #define ok puts("ok"); #define whatis(x) cerr << #x << " = " << x << endl; #define pause system("pause"); #define random rand() ^ (rand() << 5) const int N = (int)1e5 + 7; const int inf = (int)1e9 + 7; struct fenwick { int tree[N]; fenwick() { memset(tree, 0, sizeof tree); } void upd(int pos, int val) { for (; pos < N; pos += pos & -pos) { tree[pos] += val; } } int get(int r) { int res = 0; for (; r > 0; r -= r & -r) { res += tree[r]; } return res; } int get(int l, int r) { return get(r) - get(l - 1); } }tr; int n; int c[N], b[N]; pii ar[N]; int pr[N]; vector < int > gr[N]; vector < int > vv[N]; void dfs(int v) { for (int to : gr[v]) { vv[to] = vv[v]; vv[to].pb(v); dfs(to); } } main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &c[i]); b[i] = c[i]; } sort(b + 1, b + n + 1); int m = unique(b + 1, b + n + 1) - b - 1; for (int i = 1; i <= n; i++) { c[i] = lower_bound(b + 1, b + m + 1, c[i]) - b; } for (int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); gr[u].pb(v); ar[i] = mk(u, v); } dfs(1); for (int i = 1; i < n; i++) { int ans = 0; tr = fenwick(); for (int j = sz(vv[ar[i].sc]) - 1; j >= 0; j--) { int val = vv[ar[i].sc][j]; ans += tr.get(c[val] - 1); tr.upd(c[val], 1); c[val] = c[ar[i].sc]; } printf("%d\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5880 KB | Output is correct |
2 | Correct | 7 ms | 5880 KB | Output is correct |
3 | Correct | 10 ms | 5920 KB | Output is correct |
4 | Correct | 19 ms | 6068 KB | Output is correct |
5 | Correct | 27 ms | 6108 KB | Output is correct |
6 | Correct | 28 ms | 6352 KB | Output is correct |
7 | Correct | 27 ms | 6352 KB | Output is correct |
8 | Correct | 34 ms | 7372 KB | Output is correct |
9 | Correct | 34 ms | 7400 KB | Output is correct |
10 | Correct | 31 ms | 7536 KB | Output is correct |
11 | Correct | 31 ms | 7536 KB | Output is correct |
12 | Correct | 29 ms | 7536 KB | Output is correct |
13 | Correct | 28 ms | 7536 KB | Output is correct |
14 | Correct | 30 ms | 7536 KB | Output is correct |
15 | Correct | 26 ms | 7536 KB | Output is correct |
16 | Correct | 27 ms | 7536 KB | Output is correct |
17 | Correct | 27 ms | 7536 KB | Output is correct |
18 | Correct | 27 ms | 7536 KB | Output is correct |
19 | Correct | 28 ms | 7536 KB | Output is correct |
20 | Correct | 35 ms | 7536 KB | Output is correct |
21 | Correct | 29 ms | 7536 KB | Output is correct |
22 | Correct | 27 ms | 7536 KB | Output is correct |
23 | Correct | 26 ms | 7536 KB | Output is correct |
24 | Correct | 26 ms | 7536 KB | Output is correct |
25 | Correct | 26 ms | 7536 KB | Output is correct |
26 | Correct | 34 ms | 7772 KB | Output is correct |
27 | Correct | 31 ms | 7772 KB | Output is correct |
28 | Correct | 46 ms | 7772 KB | Output is correct |
29 | Correct | 28 ms | 7772 KB | Output is correct |
30 | Correct | 27 ms | 7772 KB | Output is correct |
31 | Correct | 27 ms | 7772 KB | Output is correct |
32 | Correct | 28 ms | 7772 KB | Output is correct |
33 | Correct | 28 ms | 7772 KB | Output is correct |
34 | Correct | 28 ms | 7772 KB | Output is correct |
35 | Correct | 27 ms | 7772 KB | Output is correct |
36 | Correct | 28 ms | 7772 KB | Output is correct |
37 | Correct | 29 ms | 7772 KB | Output is correct |
38 | Correct | 27 ms | 7772 KB | Output is correct |
39 | Correct | 27 ms | 7772 KB | Output is correct |
40 | Correct | 29 ms | 7772 KB | Output is correct |
41 | Correct | 27 ms | 7772 KB | Output is correct |
42 | Correct | 27 ms | 7772 KB | Output is correct |
43 | Correct | 29 ms | 7772 KB | Output is correct |
44 | Correct | 27 ms | 7772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5880 KB | Output is correct |
2 | Correct | 7 ms | 5880 KB | Output is correct |
3 | Correct | 10 ms | 5920 KB | Output is correct |
4 | Correct | 19 ms | 6068 KB | Output is correct |
5 | Correct | 27 ms | 6108 KB | Output is correct |
6 | Correct | 28 ms | 6352 KB | Output is correct |
7 | Correct | 27 ms | 6352 KB | Output is correct |
8 | Correct | 34 ms | 7372 KB | Output is correct |
9 | Correct | 34 ms | 7400 KB | Output is correct |
10 | Correct | 31 ms | 7536 KB | Output is correct |
11 | Correct | 31 ms | 7536 KB | Output is correct |
12 | Correct | 29 ms | 7536 KB | Output is correct |
13 | Correct | 28 ms | 7536 KB | Output is correct |
14 | Correct | 30 ms | 7536 KB | Output is correct |
15 | Correct | 26 ms | 7536 KB | Output is correct |
16 | Correct | 27 ms | 7536 KB | Output is correct |
17 | Correct | 27 ms | 7536 KB | Output is correct |
18 | Correct | 27 ms | 7536 KB | Output is correct |
19 | Correct | 28 ms | 7536 KB | Output is correct |
20 | Correct | 35 ms | 7536 KB | Output is correct |
21 | Correct | 29 ms | 7536 KB | Output is correct |
22 | Correct | 27 ms | 7536 KB | Output is correct |
23 | Correct | 26 ms | 7536 KB | Output is correct |
24 | Correct | 26 ms | 7536 KB | Output is correct |
25 | Correct | 26 ms | 7536 KB | Output is correct |
26 | Correct | 34 ms | 7772 KB | Output is correct |
27 | Correct | 31 ms | 7772 KB | Output is correct |
28 | Correct | 46 ms | 7772 KB | Output is correct |
29 | Correct | 28 ms | 7772 KB | Output is correct |
30 | Correct | 27 ms | 7772 KB | Output is correct |
31 | Correct | 27 ms | 7772 KB | Output is correct |
32 | Correct | 28 ms | 7772 KB | Output is correct |
33 | Correct | 28 ms | 7772 KB | Output is correct |
34 | Correct | 28 ms | 7772 KB | Output is correct |
35 | Correct | 27 ms | 7772 KB | Output is correct |
36 | Correct | 28 ms | 7772 KB | Output is correct |
37 | Correct | 29 ms | 7772 KB | Output is correct |
38 | Correct | 27 ms | 7772 KB | Output is correct |
39 | Correct | 27 ms | 7772 KB | Output is correct |
40 | Correct | 29 ms | 7772 KB | Output is correct |
41 | Correct | 27 ms | 7772 KB | Output is correct |
42 | Correct | 27 ms | 7772 KB | Output is correct |
43 | Correct | 29 ms | 7772 KB | Output is correct |
44 | Correct | 27 ms | 7772 KB | Output is correct |
45 | Correct | 46 ms | 7772 KB | Output is correct |
46 | Correct | 170 ms | 7772 KB | Output is correct |
47 | Correct | 170 ms | 7772 KB | Output is correct |
48 | Correct | 185 ms | 7772 KB | Output is correct |
49 | Correct | 410 ms | 60688 KB | Output is correct |
50 | Correct | 405 ms | 60764 KB | Output is correct |
51 | Correct | 413 ms | 60840 KB | Output is correct |
52 | Correct | 294 ms | 60840 KB | Output is correct |
53 | Correct | 285 ms | 60840 KB | Output is correct |
54 | Correct | 323 ms | 60840 KB | Output is correct |
55 | Correct | 299 ms | 60840 KB | Output is correct |
56 | Correct | 320 ms | 60840 KB | Output is correct |
57 | Correct | 170 ms | 60840 KB | Output is correct |
58 | Correct | 185 ms | 60840 KB | Output is correct |
59 | Correct | 170 ms | 60840 KB | Output is correct |
60 | Correct | 171 ms | 60840 KB | Output is correct |
61 | Correct | 301 ms | 60840 KB | Output is correct |
62 | Correct | 287 ms | 60840 KB | Output is correct |
63 | Correct | 299 ms | 60840 KB | Output is correct |
64 | Correct | 170 ms | 60840 KB | Output is correct |
65 | Correct | 170 ms | 60840 KB | Output is correct |
66 | Correct | 173 ms | 60840 KB | Output is correct |
67 | Correct | 170 ms | 60840 KB | Output is correct |
68 | Correct | 456 ms | 62024 KB | Output is correct |
69 | Correct | 294 ms | 62024 KB | Output is correct |
70 | Correct | 302 ms | 62024 KB | Output is correct |
71 | Correct | 304 ms | 62024 KB | Output is correct |
72 | Correct | 172 ms | 62024 KB | Output is correct |
73 | Correct | 176 ms | 62024 KB | Output is correct |
74 | Correct | 301 ms | 62024 KB | Output is correct |
75 | Correct | 232 ms | 62024 KB | Output is correct |
76 | Correct | 221 ms | 62024 KB | Output is correct |
77 | Correct | 200 ms | 62024 KB | Output is correct |
78 | Correct | 237 ms | 62024 KB | Output is correct |
79 | Correct | 229 ms | 62024 KB | Output is correct |
80 | Correct | 219 ms | 62024 KB | Output is correct |
81 | Correct | 234 ms | 62024 KB | Output is correct |
82 | Correct | 218 ms | 62024 KB | Output is correct |
83 | Correct | 201 ms | 62024 KB | Output is correct |
84 | Correct | 254 ms | 62024 KB | Output is correct |
85 | Correct | 240 ms | 62024 KB | Output is correct |
86 | Correct | 205 ms | 62024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5880 KB | Output is correct |
2 | Correct | 7 ms | 5880 KB | Output is correct |
3 | Correct | 10 ms | 5920 KB | Output is correct |
4 | Correct | 19 ms | 6068 KB | Output is correct |
5 | Correct | 27 ms | 6108 KB | Output is correct |
6 | Correct | 28 ms | 6352 KB | Output is correct |
7 | Correct | 27 ms | 6352 KB | Output is correct |
8 | Correct | 34 ms | 7372 KB | Output is correct |
9 | Correct | 34 ms | 7400 KB | Output is correct |
10 | Correct | 31 ms | 7536 KB | Output is correct |
11 | Correct | 31 ms | 7536 KB | Output is correct |
12 | Correct | 29 ms | 7536 KB | Output is correct |
13 | Correct | 28 ms | 7536 KB | Output is correct |
14 | Correct | 30 ms | 7536 KB | Output is correct |
15 | Correct | 26 ms | 7536 KB | Output is correct |
16 | Correct | 27 ms | 7536 KB | Output is correct |
17 | Correct | 27 ms | 7536 KB | Output is correct |
18 | Correct | 27 ms | 7536 KB | Output is correct |
19 | Correct | 28 ms | 7536 KB | Output is correct |
20 | Correct | 35 ms | 7536 KB | Output is correct |
21 | Correct | 29 ms | 7536 KB | Output is correct |
22 | Correct | 27 ms | 7536 KB | Output is correct |
23 | Correct | 26 ms | 7536 KB | Output is correct |
24 | Correct | 26 ms | 7536 KB | Output is correct |
25 | Correct | 26 ms | 7536 KB | Output is correct |
26 | Correct | 34 ms | 7772 KB | Output is correct |
27 | Correct | 31 ms | 7772 KB | Output is correct |
28 | Correct | 46 ms | 7772 KB | Output is correct |
29 | Correct | 28 ms | 7772 KB | Output is correct |
30 | Correct | 27 ms | 7772 KB | Output is correct |
31 | Correct | 27 ms | 7772 KB | Output is correct |
32 | Correct | 28 ms | 7772 KB | Output is correct |
33 | Correct | 28 ms | 7772 KB | Output is correct |
34 | Correct | 28 ms | 7772 KB | Output is correct |
35 | Correct | 27 ms | 7772 KB | Output is correct |
36 | Correct | 28 ms | 7772 KB | Output is correct |
37 | Correct | 29 ms | 7772 KB | Output is correct |
38 | Correct | 27 ms | 7772 KB | Output is correct |
39 | Correct | 27 ms | 7772 KB | Output is correct |
40 | Correct | 29 ms | 7772 KB | Output is correct |
41 | Correct | 27 ms | 7772 KB | Output is correct |
42 | Correct | 27 ms | 7772 KB | Output is correct |
43 | Correct | 29 ms | 7772 KB | Output is correct |
44 | Correct | 27 ms | 7772 KB | Output is correct |
45 | Correct | 46 ms | 7772 KB | Output is correct |
46 | Correct | 170 ms | 7772 KB | Output is correct |
47 | Correct | 170 ms | 7772 KB | Output is correct |
48 | Correct | 185 ms | 7772 KB | Output is correct |
49 | Correct | 410 ms | 60688 KB | Output is correct |
50 | Correct | 405 ms | 60764 KB | Output is correct |
51 | Correct | 413 ms | 60840 KB | Output is correct |
52 | Correct | 294 ms | 60840 KB | Output is correct |
53 | Correct | 285 ms | 60840 KB | Output is correct |
54 | Correct | 323 ms | 60840 KB | Output is correct |
55 | Correct | 299 ms | 60840 KB | Output is correct |
56 | Correct | 320 ms | 60840 KB | Output is correct |
57 | Correct | 170 ms | 60840 KB | Output is correct |
58 | Correct | 185 ms | 60840 KB | Output is correct |
59 | Correct | 170 ms | 60840 KB | Output is correct |
60 | Correct | 171 ms | 60840 KB | Output is correct |
61 | Correct | 301 ms | 60840 KB | Output is correct |
62 | Correct | 287 ms | 60840 KB | Output is correct |
63 | Correct | 299 ms | 60840 KB | Output is correct |
64 | Correct | 170 ms | 60840 KB | Output is correct |
65 | Correct | 170 ms | 60840 KB | Output is correct |
66 | Correct | 173 ms | 60840 KB | Output is correct |
67 | Correct | 170 ms | 60840 KB | Output is correct |
68 | Correct | 456 ms | 62024 KB | Output is correct |
69 | Correct | 294 ms | 62024 KB | Output is correct |
70 | Correct | 302 ms | 62024 KB | Output is correct |
71 | Correct | 304 ms | 62024 KB | Output is correct |
72 | Correct | 172 ms | 62024 KB | Output is correct |
73 | Correct | 176 ms | 62024 KB | Output is correct |
74 | Correct | 301 ms | 62024 KB | Output is correct |
75 | Correct | 232 ms | 62024 KB | Output is correct |
76 | Correct | 221 ms | 62024 KB | Output is correct |
77 | Correct | 200 ms | 62024 KB | Output is correct |
78 | Correct | 237 ms | 62024 KB | Output is correct |
79 | Correct | 229 ms | 62024 KB | Output is correct |
80 | Correct | 219 ms | 62024 KB | Output is correct |
81 | Correct | 234 ms | 62024 KB | Output is correct |
82 | Correct | 218 ms | 62024 KB | Output is correct |
83 | Correct | 201 ms | 62024 KB | Output is correct |
84 | Correct | 254 ms | 62024 KB | Output is correct |
85 | Correct | 240 ms | 62024 KB | Output is correct |
86 | Correct | 205 ms | 62024 KB | Output is correct |
87 | Correct | 419 ms | 62024 KB | Output is correct |
88 | Execution timed out | 1077 ms | 62024 KB | Time limit exceeded |
89 | Halted | 0 ms | 0 KB | - |