# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47409 | 2018-05-02T12:01:32 Z | daniel_02 | Construction of Highway (JOI18_construction) | C++17 | 240 ms | 956 KB |
#include <bits/stdc++.h> #define ll long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front using namespace std; const int N = 4000 + 7; const int inf = 4000+7; int a[N], pr[N]; int t[N]; int cnt; deque<int>dq; void update (int r) { for (; r > 0; r -= (r & -r)) t[r] ++; } int get (int r) { int res = 0; for (; r < N; r += (r & -r)) res += t[r]; return res; } void dfs(int v) { while (v != 0) { dq.pf(a[v]); v = pr[v]; } } void conquer(int v) { ll ans = 0; dfs(v); cnt = 1; for (int i = 0; i < dq.size(); i++) { ans += get(dq[i] + 1); update(dq[i]); } // for (int i = 0; i < dq.size(); i++) // update(1, 1, inf, dq[i], -inf); memset(t, 0, sizeof(t)); dq.clear(); printf("%lld\n", ans); } void upd(int v, int x) { while (v != 0) { a[v] = x; v = pr[v]; } } vector <int> vec; main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); vec.pb(a[i]); } sort(vec.begin(),vec.end()); vec.erase(unique(vec.begin(),vec.end()),vec.end()); for (int i = 1; i <= n; i ++) { a[i] = lower_bound(vec.begin(),vec.end(),a[i]) - vec.begin() + 1; } for (int i = 1; i < n; i++) { int q, w; scanf("%d%d", &q, &w); if (i == 1) { puts("0"); pr[w] = q; a[q] = a[w]; continue; } conquer(q); upd(q, a[w]); pr[w] = q; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 468 KB | Output is correct |
3 | Correct | 2 ms | 468 KB | Output is correct |
4 | Correct | 2 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 468 KB | Output is correct |
6 | Correct | 3 ms | 468 KB | Output is correct |
7 | Correct | 3 ms | 468 KB | Output is correct |
8 | Correct | 7 ms | 512 KB | Output is correct |
9 | Correct | 5 ms | 564 KB | Output is correct |
10 | Correct | 6 ms | 564 KB | Output is correct |
11 | Correct | 4 ms | 564 KB | Output is correct |
12 | Correct | 4 ms | 564 KB | Output is correct |
13 | Correct | 5 ms | 700 KB | Output is correct |
14 | Correct | 4 ms | 700 KB | Output is correct |
15 | Correct | 3 ms | 700 KB | Output is correct |
16 | Correct | 2 ms | 748 KB | Output is correct |
17 | Correct | 2 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 4 ms | 748 KB | Output is correct |
20 | Correct | 4 ms | 748 KB | Output is correct |
21 | Correct | 6 ms | 748 KB | Output is correct |
22 | Correct | 2 ms | 748 KB | Output is correct |
23 | Correct | 3 ms | 748 KB | Output is correct |
24 | Correct | 3 ms | 748 KB | Output is correct |
25 | Correct | 3 ms | 748 KB | Output is correct |
26 | Correct | 7 ms | 748 KB | Output is correct |
27 | Correct | 4 ms | 748 KB | Output is correct |
28 | Correct | 4 ms | 748 KB | Output is correct |
29 | Correct | 5 ms | 748 KB | Output is correct |
30 | Correct | 3 ms | 748 KB | Output is correct |
31 | Correct | 2 ms | 748 KB | Output is correct |
32 | Correct | 4 ms | 748 KB | Output is correct |
33 | Correct | 4 ms | 748 KB | Output is correct |
34 | Correct | 4 ms | 748 KB | Output is correct |
35 | Correct | 3 ms | 748 KB | Output is correct |
36 | Correct | 3 ms | 748 KB | Output is correct |
37 | Correct | 3 ms | 748 KB | Output is correct |
38 | Correct | 4 ms | 748 KB | Output is correct |
39 | Correct | 3 ms | 748 KB | Output is correct |
40 | Correct | 3 ms | 748 KB | Output is correct |
41 | Correct | 3 ms | 748 KB | Output is correct |
42 | Correct | 3 ms | 748 KB | Output is correct |
43 | Correct | 3 ms | 748 KB | Output is correct |
44 | Correct | 3 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 468 KB | Output is correct |
3 | Correct | 2 ms | 468 KB | Output is correct |
4 | Correct | 2 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 468 KB | Output is correct |
6 | Correct | 3 ms | 468 KB | Output is correct |
7 | Correct | 3 ms | 468 KB | Output is correct |
8 | Correct | 7 ms | 512 KB | Output is correct |
9 | Correct | 5 ms | 564 KB | Output is correct |
10 | Correct | 6 ms | 564 KB | Output is correct |
11 | Correct | 4 ms | 564 KB | Output is correct |
12 | Correct | 4 ms | 564 KB | Output is correct |
13 | Correct | 5 ms | 700 KB | Output is correct |
14 | Correct | 4 ms | 700 KB | Output is correct |
15 | Correct | 3 ms | 700 KB | Output is correct |
16 | Correct | 2 ms | 748 KB | Output is correct |
17 | Correct | 2 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 4 ms | 748 KB | Output is correct |
20 | Correct | 4 ms | 748 KB | Output is correct |
21 | Correct | 6 ms | 748 KB | Output is correct |
22 | Correct | 2 ms | 748 KB | Output is correct |
23 | Correct | 3 ms | 748 KB | Output is correct |
24 | Correct | 3 ms | 748 KB | Output is correct |
25 | Correct | 3 ms | 748 KB | Output is correct |
26 | Correct | 7 ms | 748 KB | Output is correct |
27 | Correct | 4 ms | 748 KB | Output is correct |
28 | Correct | 4 ms | 748 KB | Output is correct |
29 | Correct | 5 ms | 748 KB | Output is correct |
30 | Correct | 3 ms | 748 KB | Output is correct |
31 | Correct | 2 ms | 748 KB | Output is correct |
32 | Correct | 4 ms | 748 KB | Output is correct |
33 | Correct | 4 ms | 748 KB | Output is correct |
34 | Correct | 4 ms | 748 KB | Output is correct |
35 | Correct | 3 ms | 748 KB | Output is correct |
36 | Correct | 3 ms | 748 KB | Output is correct |
37 | Correct | 3 ms | 748 KB | Output is correct |
38 | Correct | 4 ms | 748 KB | Output is correct |
39 | Correct | 3 ms | 748 KB | Output is correct |
40 | Correct | 3 ms | 748 KB | Output is correct |
41 | Correct | 3 ms | 748 KB | Output is correct |
42 | Correct | 3 ms | 748 KB | Output is correct |
43 | Correct | 3 ms | 748 KB | Output is correct |
44 | Correct | 3 ms | 748 KB | Output is correct |
45 | Correct | 3 ms | 748 KB | Output is correct |
46 | Correct | 7 ms | 748 KB | Output is correct |
47 | Correct | 9 ms | 748 KB | Output is correct |
48 | Correct | 7 ms | 748 KB | Output is correct |
49 | Correct | 207 ms | 748 KB | Output is correct |
50 | Correct | 240 ms | 856 KB | Output is correct |
51 | Correct | 225 ms | 856 KB | Output is correct |
52 | Correct | 109 ms | 856 KB | Output is correct |
53 | Correct | 106 ms | 856 KB | Output is correct |
54 | Correct | 109 ms | 856 KB | Output is correct |
55 | Correct | 117 ms | 856 KB | Output is correct |
56 | Correct | 143 ms | 856 KB | Output is correct |
57 | Correct | 7 ms | 856 KB | Output is correct |
58 | Correct | 7 ms | 856 KB | Output is correct |
59 | Correct | 8 ms | 856 KB | Output is correct |
60 | Correct | 7 ms | 856 KB | Output is correct |
61 | Correct | 108 ms | 856 KB | Output is correct |
62 | Correct | 110 ms | 856 KB | Output is correct |
63 | Correct | 111 ms | 856 KB | Output is correct |
64 | Correct | 6 ms | 856 KB | Output is correct |
65 | Correct | 8 ms | 856 KB | Output is correct |
66 | Correct | 7 ms | 856 KB | Output is correct |
67 | Correct | 7 ms | 856 KB | Output is correct |
68 | Correct | 228 ms | 856 KB | Output is correct |
69 | Correct | 117 ms | 888 KB | Output is correct |
70 | Correct | 111 ms | 888 KB | Output is correct |
71 | Correct | 121 ms | 888 KB | Output is correct |
72 | Correct | 7 ms | 888 KB | Output is correct |
73 | Correct | 10 ms | 888 KB | Output is correct |
74 | Correct | 111 ms | 888 KB | Output is correct |
75 | Correct | 60 ms | 888 KB | Output is correct |
76 | Correct | 44 ms | 888 KB | Output is correct |
77 | Correct | 36 ms | 888 KB | Output is correct |
78 | Correct | 60 ms | 888 KB | Output is correct |
79 | Correct | 45 ms | 956 KB | Output is correct |
80 | Correct | 34 ms | 956 KB | Output is correct |
81 | Correct | 59 ms | 956 KB | Output is correct |
82 | Correct | 41 ms | 956 KB | Output is correct |
83 | Correct | 33 ms | 956 KB | Output is correct |
84 | Correct | 61 ms | 956 KB | Output is correct |
85 | Correct | 41 ms | 956 KB | Output is correct |
86 | Correct | 33 ms | 956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 468 KB | Output is correct |
3 | Correct | 2 ms | 468 KB | Output is correct |
4 | Correct | 2 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 468 KB | Output is correct |
6 | Correct | 3 ms | 468 KB | Output is correct |
7 | Correct | 3 ms | 468 KB | Output is correct |
8 | Correct | 7 ms | 512 KB | Output is correct |
9 | Correct | 5 ms | 564 KB | Output is correct |
10 | Correct | 6 ms | 564 KB | Output is correct |
11 | Correct | 4 ms | 564 KB | Output is correct |
12 | Correct | 4 ms | 564 KB | Output is correct |
13 | Correct | 5 ms | 700 KB | Output is correct |
14 | Correct | 4 ms | 700 KB | Output is correct |
15 | Correct | 3 ms | 700 KB | Output is correct |
16 | Correct | 2 ms | 748 KB | Output is correct |
17 | Correct | 2 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 4 ms | 748 KB | Output is correct |
20 | Correct | 4 ms | 748 KB | Output is correct |
21 | Correct | 6 ms | 748 KB | Output is correct |
22 | Correct | 2 ms | 748 KB | Output is correct |
23 | Correct | 3 ms | 748 KB | Output is correct |
24 | Correct | 3 ms | 748 KB | Output is correct |
25 | Correct | 3 ms | 748 KB | Output is correct |
26 | Correct | 7 ms | 748 KB | Output is correct |
27 | Correct | 4 ms | 748 KB | Output is correct |
28 | Correct | 4 ms | 748 KB | Output is correct |
29 | Correct | 5 ms | 748 KB | Output is correct |
30 | Correct | 3 ms | 748 KB | Output is correct |
31 | Correct | 2 ms | 748 KB | Output is correct |
32 | Correct | 4 ms | 748 KB | Output is correct |
33 | Correct | 4 ms | 748 KB | Output is correct |
34 | Correct | 4 ms | 748 KB | Output is correct |
35 | Correct | 3 ms | 748 KB | Output is correct |
36 | Correct | 3 ms | 748 KB | Output is correct |
37 | Correct | 3 ms | 748 KB | Output is correct |
38 | Correct | 4 ms | 748 KB | Output is correct |
39 | Correct | 3 ms | 748 KB | Output is correct |
40 | Correct | 3 ms | 748 KB | Output is correct |
41 | Correct | 3 ms | 748 KB | Output is correct |
42 | Correct | 3 ms | 748 KB | Output is correct |
43 | Correct | 3 ms | 748 KB | Output is correct |
44 | Correct | 3 ms | 748 KB | Output is correct |
45 | Correct | 3 ms | 748 KB | Output is correct |
46 | Correct | 7 ms | 748 KB | Output is correct |
47 | Correct | 9 ms | 748 KB | Output is correct |
48 | Correct | 7 ms | 748 KB | Output is correct |
49 | Correct | 207 ms | 748 KB | Output is correct |
50 | Correct | 240 ms | 856 KB | Output is correct |
51 | Correct | 225 ms | 856 KB | Output is correct |
52 | Correct | 109 ms | 856 KB | Output is correct |
53 | Correct | 106 ms | 856 KB | Output is correct |
54 | Correct | 109 ms | 856 KB | Output is correct |
55 | Correct | 117 ms | 856 KB | Output is correct |
56 | Correct | 143 ms | 856 KB | Output is correct |
57 | Correct | 7 ms | 856 KB | Output is correct |
58 | Correct | 7 ms | 856 KB | Output is correct |
59 | Correct | 8 ms | 856 KB | Output is correct |
60 | Correct | 7 ms | 856 KB | Output is correct |
61 | Correct | 108 ms | 856 KB | Output is correct |
62 | Correct | 110 ms | 856 KB | Output is correct |
63 | Correct | 111 ms | 856 KB | Output is correct |
64 | Correct | 6 ms | 856 KB | Output is correct |
65 | Correct | 8 ms | 856 KB | Output is correct |
66 | Correct | 7 ms | 856 KB | Output is correct |
67 | Correct | 7 ms | 856 KB | Output is correct |
68 | Correct | 228 ms | 856 KB | Output is correct |
69 | Correct | 117 ms | 888 KB | Output is correct |
70 | Correct | 111 ms | 888 KB | Output is correct |
71 | Correct | 121 ms | 888 KB | Output is correct |
72 | Correct | 7 ms | 888 KB | Output is correct |
73 | Correct | 10 ms | 888 KB | Output is correct |
74 | Correct | 111 ms | 888 KB | Output is correct |
75 | Correct | 60 ms | 888 KB | Output is correct |
76 | Correct | 44 ms | 888 KB | Output is correct |
77 | Correct | 36 ms | 888 KB | Output is correct |
78 | Correct | 60 ms | 888 KB | Output is correct |
79 | Correct | 45 ms | 956 KB | Output is correct |
80 | Correct | 34 ms | 956 KB | Output is correct |
81 | Correct | 59 ms | 956 KB | Output is correct |
82 | Correct | 41 ms | 956 KB | Output is correct |
83 | Correct | 33 ms | 956 KB | Output is correct |
84 | Correct | 61 ms | 956 KB | Output is correct |
85 | Correct | 41 ms | 956 KB | Output is correct |
86 | Correct | 33 ms | 956 KB | Output is correct |
87 | Execution timed out | 3 ms | 956 KB | Time limit exceeded (wall clock) |
88 | Halted | 0 ms | 0 KB | - |