# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
49892 | 2018-06-04T11:23:31 Z | daniel_02 | Construction of Highway (JOI18_construction) | C++17 | 735 ms | 16196 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; struct con { con * l; con * r; int cnt; con() { l = NULL; r = NULL; cnt = 0; } }; con * root; ll create_and_get(int x) { con * cur = root; ll ans = 0; for (int i = 25; i >= 0; i--) { if (x & (1 << i)) { if (cur -> r == NULL)cur -> r = new con(); cur = cur -> r; } else { if (cur -> l == NULL)cur -> l = new con(); if (cur -> r != NULL)ans += cur -> r -> cnt; cur = cur -> l; } cur -> cnt ++; } return ans; } 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; root = new con(); for (int i = 0; i < dq.size(); i++) { ans += create_and_get(dq[i]); } delete root; // for (int i = 0; i < dq.size(); i++) // update(1, 1, inf, dq[i], -inf); 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 2 ms | 476 KB | Output is correct |
4 | Correct | 3 ms | 1004 KB | Output is correct |
5 | Correct | 4 ms | 1236 KB | Output is correct |
6 | Correct | 4 ms | 1300 KB | Output is correct |
7 | Correct | 4 ms | 1300 KB | Output is correct |
8 | Correct | 13 ms | 1300 KB | Output is correct |
9 | Correct | 13 ms | 1300 KB | Output is correct |
10 | Correct | 13 ms | 1300 KB | Output is correct |
11 | Correct | 7 ms | 1304 KB | Output is correct |
12 | Correct | 7 ms | 1440 KB | Output is correct |
13 | Correct | 8 ms | 1440 KB | Output is correct |
14 | Correct | 8 ms | 1440 KB | Output is correct |
15 | Correct | 4 ms | 1808 KB | Output is correct |
16 | Correct | 5 ms | 2072 KB | Output is correct |
17 | Correct | 5 ms | 2084 KB | Output is correct |
18 | Correct | 6 ms | 2096 KB | Output is correct |
19 | Correct | 9 ms | 2096 KB | Output is correct |
20 | Correct | 11 ms | 2096 KB | Output is correct |
21 | Correct | 10 ms | 2096 KB | Output is correct |
22 | Correct | 4 ms | 2096 KB | Output is correct |
23 | Correct | 4 ms | 2096 KB | Output is correct |
24 | Correct | 4 ms | 2096 KB | Output is correct |
25 | Correct | 5 ms | 2096 KB | Output is correct |
26 | Correct | 15 ms | 2096 KB | Output is correct |
27 | Correct | 10 ms | 2096 KB | Output is correct |
28 | Correct | 10 ms | 2096 KB | Output is correct |
29 | Correct | 9 ms | 2096 KB | Output is correct |
30 | Correct | 5 ms | 2096 KB | Output is correct |
31 | Correct | 4 ms | 2096 KB | Output is correct |
32 | Correct | 9 ms | 2096 KB | Output is correct |
33 | Correct | 6 ms | 2096 KB | Output is correct |
34 | Correct | 8 ms | 2096 KB | Output is correct |
35 | Correct | 6 ms | 2096 KB | Output is correct |
36 | Correct | 6 ms | 2096 KB | Output is correct |
37 | Correct | 5 ms | 2096 KB | Output is correct |
38 | Correct | 5 ms | 2096 KB | Output is correct |
39 | Correct | 7 ms | 2096 KB | Output is correct |
40 | Correct | 7 ms | 2096 KB | Output is correct |
41 | Correct | 6 ms | 2096 KB | Output is correct |
42 | Correct | 7 ms | 2096 KB | Output is correct |
43 | Correct | 6 ms | 2096 KB | Output is correct |
44 | Correct | 5 ms | 2096 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 2 ms | 476 KB | Output is correct |
4 | Correct | 3 ms | 1004 KB | Output is correct |
5 | Correct | 4 ms | 1236 KB | Output is correct |
6 | Correct | 4 ms | 1300 KB | Output is correct |
7 | Correct | 4 ms | 1300 KB | Output is correct |
8 | Correct | 13 ms | 1300 KB | Output is correct |
9 | Correct | 13 ms | 1300 KB | Output is correct |
10 | Correct | 13 ms | 1300 KB | Output is correct |
11 | Correct | 7 ms | 1304 KB | Output is correct |
12 | Correct | 7 ms | 1440 KB | Output is correct |
13 | Correct | 8 ms | 1440 KB | Output is correct |
14 | Correct | 8 ms | 1440 KB | Output is correct |
15 | Correct | 4 ms | 1808 KB | Output is correct |
16 | Correct | 5 ms | 2072 KB | Output is correct |
17 | Correct | 5 ms | 2084 KB | Output is correct |
18 | Correct | 6 ms | 2096 KB | Output is correct |
19 | Correct | 9 ms | 2096 KB | Output is correct |
20 | Correct | 11 ms | 2096 KB | Output is correct |
21 | Correct | 10 ms | 2096 KB | Output is correct |
22 | Correct | 4 ms | 2096 KB | Output is correct |
23 | Correct | 4 ms | 2096 KB | Output is correct |
24 | Correct | 4 ms | 2096 KB | Output is correct |
25 | Correct | 5 ms | 2096 KB | Output is correct |
26 | Correct | 15 ms | 2096 KB | Output is correct |
27 | Correct | 10 ms | 2096 KB | Output is correct |
28 | Correct | 10 ms | 2096 KB | Output is correct |
29 | Correct | 9 ms | 2096 KB | Output is correct |
30 | Correct | 5 ms | 2096 KB | Output is correct |
31 | Correct | 4 ms | 2096 KB | Output is correct |
32 | Correct | 9 ms | 2096 KB | Output is correct |
33 | Correct | 6 ms | 2096 KB | Output is correct |
34 | Correct | 8 ms | 2096 KB | Output is correct |
35 | Correct | 6 ms | 2096 KB | Output is correct |
36 | Correct | 6 ms | 2096 KB | Output is correct |
37 | Correct | 5 ms | 2096 KB | Output is correct |
38 | Correct | 5 ms | 2096 KB | Output is correct |
39 | Correct | 7 ms | 2096 KB | Output is correct |
40 | Correct | 7 ms | 2096 KB | Output is correct |
41 | Correct | 6 ms | 2096 KB | Output is correct |
42 | Correct | 7 ms | 2096 KB | Output is correct |
43 | Correct | 6 ms | 2096 KB | Output is correct |
44 | Correct | 5 ms | 2096 KB | Output is correct |
45 | Correct | 8 ms | 2732 KB | Output is correct |
46 | Correct | 22 ms | 8640 KB | Output is correct |
47 | Correct | 25 ms | 8844 KB | Output is correct |
48 | Correct | 21 ms | 8844 KB | Output is correct |
49 | Correct | 623 ms | 8844 KB | Output is correct |
50 | Correct | 735 ms | 8844 KB | Output is correct |
51 | Correct | 609 ms | 8844 KB | Output is correct |
52 | Correct | 317 ms | 8844 KB | Output is correct |
53 | Correct | 374 ms | 8844 KB | Output is correct |
54 | Correct | 311 ms | 8844 KB | Output is correct |
55 | Correct | 317 ms | 8844 KB | Output is correct |
56 | Correct | 318 ms | 8844 KB | Output is correct |
57 | Correct | 24 ms | 12276 KB | Output is correct |
58 | Correct | 34 ms | 16172 KB | Output is correct |
59 | Correct | 31 ms | 16172 KB | Output is correct |
60 | Correct | 32 ms | 16196 KB | Output is correct |
61 | Correct | 316 ms | 16196 KB | Output is correct |
62 | Correct | 383 ms | 16196 KB | Output is correct |
63 | Correct | 364 ms | 16196 KB | Output is correct |
64 | Correct | 15 ms | 16196 KB | Output is correct |
65 | Correct | 18 ms | 16196 KB | Output is correct |
66 | Correct | 28 ms | 16196 KB | Output is correct |
67 | Correct | 23 ms | 16196 KB | Output is correct |
68 | Correct | 692 ms | 16196 KB | Output is correct |
69 | Correct | 398 ms | 16196 KB | Output is correct |
70 | Correct | 313 ms | 16196 KB | Output is correct |
71 | Correct | 400 ms | 16196 KB | Output is correct |
72 | Correct | 43 ms | 16196 KB | Output is correct |
73 | Correct | 20 ms | 16196 KB | Output is correct |
74 | Correct | 361 ms | 16196 KB | Output is correct |
75 | Correct | 221 ms | 16196 KB | Output is correct |
76 | Correct | 139 ms | 16196 KB | Output is correct |
77 | Correct | 99 ms | 16196 KB | Output is correct |
78 | Correct | 204 ms | 16196 KB | Output is correct |
79 | Correct | 161 ms | 16196 KB | Output is correct |
80 | Correct | 145 ms | 16196 KB | Output is correct |
81 | Correct | 228 ms | 16196 KB | Output is correct |
82 | Correct | 129 ms | 16196 KB | Output is correct |
83 | Correct | 106 ms | 16196 KB | Output is correct |
84 | Correct | 193 ms | 16196 KB | Output is correct |
85 | Correct | 135 ms | 16196 KB | Output is correct |
86 | Correct | 94 ms | 16196 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 2 ms | 476 KB | Output is correct |
4 | Correct | 3 ms | 1004 KB | Output is correct |
5 | Correct | 4 ms | 1236 KB | Output is correct |
6 | Correct | 4 ms | 1300 KB | Output is correct |
7 | Correct | 4 ms | 1300 KB | Output is correct |
8 | Correct | 13 ms | 1300 KB | Output is correct |
9 | Correct | 13 ms | 1300 KB | Output is correct |
10 | Correct | 13 ms | 1300 KB | Output is correct |
11 | Correct | 7 ms | 1304 KB | Output is correct |
12 | Correct | 7 ms | 1440 KB | Output is correct |
13 | Correct | 8 ms | 1440 KB | Output is correct |
14 | Correct | 8 ms | 1440 KB | Output is correct |
15 | Correct | 4 ms | 1808 KB | Output is correct |
16 | Correct | 5 ms | 2072 KB | Output is correct |
17 | Correct | 5 ms | 2084 KB | Output is correct |
18 | Correct | 6 ms | 2096 KB | Output is correct |
19 | Correct | 9 ms | 2096 KB | Output is correct |
20 | Correct | 11 ms | 2096 KB | Output is correct |
21 | Correct | 10 ms | 2096 KB | Output is correct |
22 | Correct | 4 ms | 2096 KB | Output is correct |
23 | Correct | 4 ms | 2096 KB | Output is correct |
24 | Correct | 4 ms | 2096 KB | Output is correct |
25 | Correct | 5 ms | 2096 KB | Output is correct |
26 | Correct | 15 ms | 2096 KB | Output is correct |
27 | Correct | 10 ms | 2096 KB | Output is correct |
28 | Correct | 10 ms | 2096 KB | Output is correct |
29 | Correct | 9 ms | 2096 KB | Output is correct |
30 | Correct | 5 ms | 2096 KB | Output is correct |
31 | Correct | 4 ms | 2096 KB | Output is correct |
32 | Correct | 9 ms | 2096 KB | Output is correct |
33 | Correct | 6 ms | 2096 KB | Output is correct |
34 | Correct | 8 ms | 2096 KB | Output is correct |
35 | Correct | 6 ms | 2096 KB | Output is correct |
36 | Correct | 6 ms | 2096 KB | Output is correct |
37 | Correct | 5 ms | 2096 KB | Output is correct |
38 | Correct | 5 ms | 2096 KB | Output is correct |
39 | Correct | 7 ms | 2096 KB | Output is correct |
40 | Correct | 7 ms | 2096 KB | Output is correct |
41 | Correct | 6 ms | 2096 KB | Output is correct |
42 | Correct | 7 ms | 2096 KB | Output is correct |
43 | Correct | 6 ms | 2096 KB | Output is correct |
44 | Correct | 5 ms | 2096 KB | Output is correct |
45 | Correct | 8 ms | 2732 KB | Output is correct |
46 | Correct | 22 ms | 8640 KB | Output is correct |
47 | Correct | 25 ms | 8844 KB | Output is correct |
48 | Correct | 21 ms | 8844 KB | Output is correct |
49 | Correct | 623 ms | 8844 KB | Output is correct |
50 | Correct | 735 ms | 8844 KB | Output is correct |
51 | Correct | 609 ms | 8844 KB | Output is correct |
52 | Correct | 317 ms | 8844 KB | Output is correct |
53 | Correct | 374 ms | 8844 KB | Output is correct |
54 | Correct | 311 ms | 8844 KB | Output is correct |
55 | Correct | 317 ms | 8844 KB | Output is correct |
56 | Correct | 318 ms | 8844 KB | Output is correct |
57 | Correct | 24 ms | 12276 KB | Output is correct |
58 | Correct | 34 ms | 16172 KB | Output is correct |
59 | Correct | 31 ms | 16172 KB | Output is correct |
60 | Correct | 32 ms | 16196 KB | Output is correct |
61 | Correct | 316 ms | 16196 KB | Output is correct |
62 | Correct | 383 ms | 16196 KB | Output is correct |
63 | Correct | 364 ms | 16196 KB | Output is correct |
64 | Correct | 15 ms | 16196 KB | Output is correct |
65 | Correct | 18 ms | 16196 KB | Output is correct |
66 | Correct | 28 ms | 16196 KB | Output is correct |
67 | Correct | 23 ms | 16196 KB | Output is correct |
68 | Correct | 692 ms | 16196 KB | Output is correct |
69 | Correct | 398 ms | 16196 KB | Output is correct |
70 | Correct | 313 ms | 16196 KB | Output is correct |
71 | Correct | 400 ms | 16196 KB | Output is correct |
72 | Correct | 43 ms | 16196 KB | Output is correct |
73 | Correct | 20 ms | 16196 KB | Output is correct |
74 | Correct | 361 ms | 16196 KB | Output is correct |
75 | Correct | 221 ms | 16196 KB | Output is correct |
76 | Correct | 139 ms | 16196 KB | Output is correct |
77 | Correct | 99 ms | 16196 KB | Output is correct |
78 | Correct | 204 ms | 16196 KB | Output is correct |
79 | Correct | 161 ms | 16196 KB | Output is correct |
80 | Correct | 145 ms | 16196 KB | Output is correct |
81 | Correct | 228 ms | 16196 KB | Output is correct |
82 | Correct | 129 ms | 16196 KB | Output is correct |
83 | Correct | 106 ms | 16196 KB | Output is correct |
84 | Correct | 193 ms | 16196 KB | Output is correct |
85 | Correct | 135 ms | 16196 KB | Output is correct |
86 | Correct | 94 ms | 16196 KB | Output is correct |
87 | Execution timed out | 4 ms | 16196 KB | Time limit exceeded (wall clock) |
88 | Halted | 0 ms | 0 KB | - |