# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47380 | 2018-05-02T08:10:34 Z | Just_Solve_The_Problem | Construction of Highway (JOI18_construction) | C++11 | 1000 ms | 5052 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; } }tr; int n; int c[N], b[N]; pii ar[N]; int pr[N]; vector < int > gr[N]; void dfs(int v) { for (int to : gr[v]) { pr[to] = 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(); int v = ar[i].fr; while (v != 0) { ans += tr.get(c[v] - 1); tr.upd(c[v], 1); c[v] = c[ar[i].sc]; v = pr[v]; } printf("%d\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3448 KB | Output is correct |
2 | Correct | 4 ms | 3560 KB | Output is correct |
3 | Correct | 8 ms | 3560 KB | Output is correct |
4 | Correct | 16 ms | 3560 KB | Output is correct |
5 | Correct | 24 ms | 3660 KB | Output is correct |
6 | Correct | 26 ms | 3716 KB | Output is correct |
7 | Correct | 24 ms | 3716 KB | Output is correct |
8 | Correct | 29 ms | 3772 KB | Output is correct |
9 | Correct | 30 ms | 3792 KB | Output is correct |
10 | Correct | 28 ms | 3792 KB | Output is correct |
11 | Correct | 28 ms | 3792 KB | Output is correct |
12 | Correct | 26 ms | 3792 KB | Output is correct |
13 | Correct | 27 ms | 3792 KB | Output is correct |
14 | Correct | 26 ms | 3792 KB | Output is correct |
15 | Correct | 25 ms | 3792 KB | Output is correct |
16 | Correct | 25 ms | 3792 KB | Output is correct |
17 | Correct | 25 ms | 3796 KB | Output is correct |
18 | Correct | 24 ms | 3796 KB | Output is correct |
19 | Correct | 26 ms | 3796 KB | Output is correct |
20 | Correct | 26 ms | 3796 KB | Output is correct |
21 | Correct | 26 ms | 3796 KB | Output is correct |
22 | Correct | 24 ms | 3796 KB | Output is correct |
23 | Correct | 24 ms | 3796 KB | Output is correct |
24 | Correct | 25 ms | 3796 KB | Output is correct |
25 | Correct | 25 ms | 3796 KB | Output is correct |
26 | Correct | 28 ms | 3796 KB | Output is correct |
27 | Correct | 28 ms | 3812 KB | Output is correct |
28 | Correct | 26 ms | 3812 KB | Output is correct |
29 | Correct | 28 ms | 3812 KB | Output is correct |
30 | Correct | 25 ms | 3812 KB | Output is correct |
31 | Correct | 25 ms | 3812 KB | Output is correct |
32 | Correct | 28 ms | 3812 KB | Output is correct |
33 | Correct | 26 ms | 3812 KB | Output is correct |
34 | Correct | 26 ms | 3812 KB | Output is correct |
35 | Correct | 26 ms | 3812 KB | Output is correct |
36 | Correct | 28 ms | 3812 KB | Output is correct |
37 | Correct | 28 ms | 3812 KB | Output is correct |
38 | Correct | 25 ms | 3812 KB | Output is correct |
39 | Correct | 27 ms | 3812 KB | Output is correct |
40 | Correct | 30 ms | 3812 KB | Output is correct |
41 | Correct | 24 ms | 3812 KB | Output is correct |
42 | Correct | 28 ms | 3812 KB | Output is correct |
43 | Correct | 44 ms | 3812 KB | Output is correct |
44 | Correct | 25 ms | 3812 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3448 KB | Output is correct |
2 | Correct | 4 ms | 3560 KB | Output is correct |
3 | Correct | 8 ms | 3560 KB | Output is correct |
4 | Correct | 16 ms | 3560 KB | Output is correct |
5 | Correct | 24 ms | 3660 KB | Output is correct |
6 | Correct | 26 ms | 3716 KB | Output is correct |
7 | Correct | 24 ms | 3716 KB | Output is correct |
8 | Correct | 29 ms | 3772 KB | Output is correct |
9 | Correct | 30 ms | 3792 KB | Output is correct |
10 | Correct | 28 ms | 3792 KB | Output is correct |
11 | Correct | 28 ms | 3792 KB | Output is correct |
12 | Correct | 26 ms | 3792 KB | Output is correct |
13 | Correct | 27 ms | 3792 KB | Output is correct |
14 | Correct | 26 ms | 3792 KB | Output is correct |
15 | Correct | 25 ms | 3792 KB | Output is correct |
16 | Correct | 25 ms | 3792 KB | Output is correct |
17 | Correct | 25 ms | 3796 KB | Output is correct |
18 | Correct | 24 ms | 3796 KB | Output is correct |
19 | Correct | 26 ms | 3796 KB | Output is correct |
20 | Correct | 26 ms | 3796 KB | Output is correct |
21 | Correct | 26 ms | 3796 KB | Output is correct |
22 | Correct | 24 ms | 3796 KB | Output is correct |
23 | Correct | 24 ms | 3796 KB | Output is correct |
24 | Correct | 25 ms | 3796 KB | Output is correct |
25 | Correct | 25 ms | 3796 KB | Output is correct |
26 | Correct | 28 ms | 3796 KB | Output is correct |
27 | Correct | 28 ms | 3812 KB | Output is correct |
28 | Correct | 26 ms | 3812 KB | Output is correct |
29 | Correct | 28 ms | 3812 KB | Output is correct |
30 | Correct | 25 ms | 3812 KB | Output is correct |
31 | Correct | 25 ms | 3812 KB | Output is correct |
32 | Correct | 28 ms | 3812 KB | Output is correct |
33 | Correct | 26 ms | 3812 KB | Output is correct |
34 | Correct | 26 ms | 3812 KB | Output is correct |
35 | Correct | 26 ms | 3812 KB | Output is correct |
36 | Correct | 28 ms | 3812 KB | Output is correct |
37 | Correct | 28 ms | 3812 KB | Output is correct |
38 | Correct | 25 ms | 3812 KB | Output is correct |
39 | Correct | 27 ms | 3812 KB | Output is correct |
40 | Correct | 30 ms | 3812 KB | Output is correct |
41 | Correct | 24 ms | 3812 KB | Output is correct |
42 | Correct | 28 ms | 3812 KB | Output is correct |
43 | Correct | 44 ms | 3812 KB | Output is correct |
44 | Correct | 25 ms | 3812 KB | Output is correct |
45 | Correct | 47 ms | 3836 KB | Output is correct |
46 | Correct | 176 ms | 3924 KB | Output is correct |
47 | Correct | 169 ms | 3964 KB | Output is correct |
48 | Correct | 182 ms | 3964 KB | Output is correct |
49 | Correct | 383 ms | 4256 KB | Output is correct |
50 | Correct | 370 ms | 4256 KB | Output is correct |
51 | Correct | 391 ms | 4256 KB | Output is correct |
52 | Correct | 265 ms | 4256 KB | Output is correct |
53 | Correct | 268 ms | 4256 KB | Output is correct |
54 | Correct | 266 ms | 4256 KB | Output is correct |
55 | Correct | 262 ms | 4256 KB | Output is correct |
56 | Correct | 272 ms | 4256 KB | Output is correct |
57 | Correct | 172 ms | 4256 KB | Output is correct |
58 | Correct | 168 ms | 4256 KB | Output is correct |
59 | Correct | 170 ms | 4256 KB | Output is correct |
60 | Correct | 166 ms | 4256 KB | Output is correct |
61 | Correct | 269 ms | 4256 KB | Output is correct |
62 | Correct | 286 ms | 4256 KB | Output is correct |
63 | Correct | 270 ms | 4256 KB | Output is correct |
64 | Correct | 186 ms | 4256 KB | Output is correct |
65 | Correct | 178 ms | 4256 KB | Output is correct |
66 | Correct | 170 ms | 4256 KB | Output is correct |
67 | Correct | 172 ms | 4256 KB | Output is correct |
68 | Correct | 390 ms | 4272 KB | Output is correct |
69 | Correct | 264 ms | 4272 KB | Output is correct |
70 | Correct | 285 ms | 4272 KB | Output is correct |
71 | Correct | 306 ms | 4272 KB | Output is correct |
72 | Correct | 178 ms | 4272 KB | Output is correct |
73 | Correct | 170 ms | 4272 KB | Output is correct |
74 | Correct | 295 ms | 4272 KB | Output is correct |
75 | Correct | 217 ms | 4272 KB | Output is correct |
76 | Correct | 205 ms | 4272 KB | Output is correct |
77 | Correct | 198 ms | 4272 KB | Output is correct |
78 | Correct | 535 ms | 4272 KB | Output is correct |
79 | Correct | 203 ms | 4272 KB | Output is correct |
80 | Correct | 211 ms | 4272 KB | Output is correct |
81 | Correct | 221 ms | 4272 KB | Output is correct |
82 | Correct | 227 ms | 4272 KB | Output is correct |
83 | Correct | 195 ms | 4272 KB | Output is correct |
84 | Correct | 229 ms | 4272 KB | Output is correct |
85 | Correct | 212 ms | 4272 KB | Output is correct |
86 | Correct | 196 ms | 4272 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3448 KB | Output is correct |
2 | Correct | 4 ms | 3560 KB | Output is correct |
3 | Correct | 8 ms | 3560 KB | Output is correct |
4 | Correct | 16 ms | 3560 KB | Output is correct |
5 | Correct | 24 ms | 3660 KB | Output is correct |
6 | Correct | 26 ms | 3716 KB | Output is correct |
7 | Correct | 24 ms | 3716 KB | Output is correct |
8 | Correct | 29 ms | 3772 KB | Output is correct |
9 | Correct | 30 ms | 3792 KB | Output is correct |
10 | Correct | 28 ms | 3792 KB | Output is correct |
11 | Correct | 28 ms | 3792 KB | Output is correct |
12 | Correct | 26 ms | 3792 KB | Output is correct |
13 | Correct | 27 ms | 3792 KB | Output is correct |
14 | Correct | 26 ms | 3792 KB | Output is correct |
15 | Correct | 25 ms | 3792 KB | Output is correct |
16 | Correct | 25 ms | 3792 KB | Output is correct |
17 | Correct | 25 ms | 3796 KB | Output is correct |
18 | Correct | 24 ms | 3796 KB | Output is correct |
19 | Correct | 26 ms | 3796 KB | Output is correct |
20 | Correct | 26 ms | 3796 KB | Output is correct |
21 | Correct | 26 ms | 3796 KB | Output is correct |
22 | Correct | 24 ms | 3796 KB | Output is correct |
23 | Correct | 24 ms | 3796 KB | Output is correct |
24 | Correct | 25 ms | 3796 KB | Output is correct |
25 | Correct | 25 ms | 3796 KB | Output is correct |
26 | Correct | 28 ms | 3796 KB | Output is correct |
27 | Correct | 28 ms | 3812 KB | Output is correct |
28 | Correct | 26 ms | 3812 KB | Output is correct |
29 | Correct | 28 ms | 3812 KB | Output is correct |
30 | Correct | 25 ms | 3812 KB | Output is correct |
31 | Correct | 25 ms | 3812 KB | Output is correct |
32 | Correct | 28 ms | 3812 KB | Output is correct |
33 | Correct | 26 ms | 3812 KB | Output is correct |
34 | Correct | 26 ms | 3812 KB | Output is correct |
35 | Correct | 26 ms | 3812 KB | Output is correct |
36 | Correct | 28 ms | 3812 KB | Output is correct |
37 | Correct | 28 ms | 3812 KB | Output is correct |
38 | Correct | 25 ms | 3812 KB | Output is correct |
39 | Correct | 27 ms | 3812 KB | Output is correct |
40 | Correct | 30 ms | 3812 KB | Output is correct |
41 | Correct | 24 ms | 3812 KB | Output is correct |
42 | Correct | 28 ms | 3812 KB | Output is correct |
43 | Correct | 44 ms | 3812 KB | Output is correct |
44 | Correct | 25 ms | 3812 KB | Output is correct |
45 | Correct | 47 ms | 3836 KB | Output is correct |
46 | Correct | 176 ms | 3924 KB | Output is correct |
47 | Correct | 169 ms | 3964 KB | Output is correct |
48 | Correct | 182 ms | 3964 KB | Output is correct |
49 | Correct | 383 ms | 4256 KB | Output is correct |
50 | Correct | 370 ms | 4256 KB | Output is correct |
51 | Correct | 391 ms | 4256 KB | Output is correct |
52 | Correct | 265 ms | 4256 KB | Output is correct |
53 | Correct | 268 ms | 4256 KB | Output is correct |
54 | Correct | 266 ms | 4256 KB | Output is correct |
55 | Correct | 262 ms | 4256 KB | Output is correct |
56 | Correct | 272 ms | 4256 KB | Output is correct |
57 | Correct | 172 ms | 4256 KB | Output is correct |
58 | Correct | 168 ms | 4256 KB | Output is correct |
59 | Correct | 170 ms | 4256 KB | Output is correct |
60 | Correct | 166 ms | 4256 KB | Output is correct |
61 | Correct | 269 ms | 4256 KB | Output is correct |
62 | Correct | 286 ms | 4256 KB | Output is correct |
63 | Correct | 270 ms | 4256 KB | Output is correct |
64 | Correct | 186 ms | 4256 KB | Output is correct |
65 | Correct | 178 ms | 4256 KB | Output is correct |
66 | Correct | 170 ms | 4256 KB | Output is correct |
67 | Correct | 172 ms | 4256 KB | Output is correct |
68 | Correct | 390 ms | 4272 KB | Output is correct |
69 | Correct | 264 ms | 4272 KB | Output is correct |
70 | Correct | 285 ms | 4272 KB | Output is correct |
71 | Correct | 306 ms | 4272 KB | Output is correct |
72 | Correct | 178 ms | 4272 KB | Output is correct |
73 | Correct | 170 ms | 4272 KB | Output is correct |
74 | Correct | 295 ms | 4272 KB | Output is correct |
75 | Correct | 217 ms | 4272 KB | Output is correct |
76 | Correct | 205 ms | 4272 KB | Output is correct |
77 | Correct | 198 ms | 4272 KB | Output is correct |
78 | Correct | 535 ms | 4272 KB | Output is correct |
79 | Correct | 203 ms | 4272 KB | Output is correct |
80 | Correct | 211 ms | 4272 KB | Output is correct |
81 | Correct | 221 ms | 4272 KB | Output is correct |
82 | Correct | 227 ms | 4272 KB | Output is correct |
83 | Correct | 195 ms | 4272 KB | Output is correct |
84 | Correct | 229 ms | 4272 KB | Output is correct |
85 | Correct | 212 ms | 4272 KB | Output is correct |
86 | Correct | 196 ms | 4272 KB | Output is correct |
87 | Correct | 426 ms | 4288 KB | Output is correct |
88 | Execution timed out | 1082 ms | 5052 KB | Time limit exceeded |
89 | Halted | 0 ms | 0 KB | - |