# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
163882 | 2019-11-16T00:36:31 Z | arnold518 | Construction of Highway (JOI18_construction) | C++14 | 2000 ms | 10764 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N, C[MAXN+10], A[MAXN+10], B[MAXN+10]; vector<int> adj[MAXN+10]; vector<int> comp; int par[MAXN+10]; void dfs(int now, int bef) { par[now]=bef; for(int nxt : adj[now]) { if(nxt==bef) continue; dfs(nxt, now); } } struct BIT { vector<int> tree; BIT() : tree(N+10) {} void update(int i) { for(; i<=N; i+=(i&-i)) tree[i]++; } int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; } }; int main() { int i, j; scanf("%d", &N); for(i=1; i<=N; i++) scanf("%d", &C[i]), comp.push_back(C[i]); sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); for(i=1; i<=N; i++) C[i]=lower_bound(comp.begin(), comp.end(), C[i])-comp.begin()+1; for(i=1; i<N; i++) { scanf("%d%d", &A[i], &B[i]); adj[A[i]].push_back(B[i]); adj[B[i]].push_back(A[i]); } dfs(1, 1); for(j=1; j<N; j++) { vector<int> V; int now=A[j]; while(now!=1) V.push_back(now), now=par[now]; V.push_back(1); BIT bit; ll ans=0; for(i=0; i<V.size(); i++) { ans+=bit.query(C[V[i]]-1); bit.update(C[V[i]]); } printf("%lld\n", ans); for(i=0; i<V.size(); i++) C[V[i]]=C[B[j]]; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2808 KB | Output is correct |
2 | Correct | 4 ms | 2936 KB | Output is correct |
3 | Correct | 4 ms | 2680 KB | Output is correct |
4 | Correct | 4 ms | 2680 KB | Output is correct |
5 | Correct | 5 ms | 2684 KB | Output is correct |
6 | Correct | 18 ms | 2680 KB | Output is correct |
7 | Correct | 5 ms | 2680 KB | Output is correct |
8 | Correct | 8 ms | 2808 KB | Output is correct |
9 | Correct | 8 ms | 2684 KB | Output is correct |
10 | Correct | 7 ms | 2684 KB | Output is correct |
11 | Correct | 6 ms | 2680 KB | Output is correct |
12 | Correct | 6 ms | 2936 KB | Output is correct |
13 | Correct | 6 ms | 2680 KB | Output is correct |
14 | Correct | 6 ms | 2680 KB | Output is correct |
15 | Correct | 5 ms | 2680 KB | Output is correct |
16 | Correct | 5 ms | 2680 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2680 KB | Output is correct |
19 | Correct | 6 ms | 2680 KB | Output is correct |
20 | Correct | 6 ms | 2680 KB | Output is correct |
21 | Correct | 7 ms | 2680 KB | Output is correct |
22 | Correct | 5 ms | 2680 KB | Output is correct |
23 | Correct | 5 ms | 2680 KB | Output is correct |
24 | Correct | 5 ms | 2680 KB | Output is correct |
25 | Correct | 5 ms | 2680 KB | Output is correct |
26 | Correct | 8 ms | 2680 KB | Output is correct |
27 | Correct | 6 ms | 2680 KB | Output is correct |
28 | Correct | 6 ms | 2680 KB | Output is correct |
29 | Correct | 7 ms | 2680 KB | Output is correct |
30 | Correct | 5 ms | 2680 KB | Output is correct |
31 | Correct | 5 ms | 2680 KB | Output is correct |
32 | Correct | 7 ms | 2728 KB | Output is correct |
33 | Correct | 7 ms | 2792 KB | Output is correct |
34 | Correct | 5 ms | 2728 KB | Output is correct |
35 | Correct | 5 ms | 2680 KB | Output is correct |
36 | Correct | 5 ms | 2680 KB | Output is correct |
37 | Correct | 5 ms | 2680 KB | Output is correct |
38 | Correct | 5 ms | 2680 KB | Output is correct |
39 | Correct | 5 ms | 2680 KB | Output is correct |
40 | Correct | 5 ms | 2680 KB | Output is correct |
41 | Correct | 5 ms | 2680 KB | Output is correct |
42 | Correct | 6 ms | 2680 KB | Output is correct |
43 | Correct | 5 ms | 2680 KB | Output is correct |
44 | Correct | 5 ms | 2680 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2808 KB | Output is correct |
2 | Correct | 4 ms | 2936 KB | Output is correct |
3 | Correct | 4 ms | 2680 KB | Output is correct |
4 | Correct | 4 ms | 2680 KB | Output is correct |
5 | Correct | 5 ms | 2684 KB | Output is correct |
6 | Correct | 18 ms | 2680 KB | Output is correct |
7 | Correct | 5 ms | 2680 KB | Output is correct |
8 | Correct | 8 ms | 2808 KB | Output is correct |
9 | Correct | 8 ms | 2684 KB | Output is correct |
10 | Correct | 7 ms | 2684 KB | Output is correct |
11 | Correct | 6 ms | 2680 KB | Output is correct |
12 | Correct | 6 ms | 2936 KB | Output is correct |
13 | Correct | 6 ms | 2680 KB | Output is correct |
14 | Correct | 6 ms | 2680 KB | Output is correct |
15 | Correct | 5 ms | 2680 KB | Output is correct |
16 | Correct | 5 ms | 2680 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2680 KB | Output is correct |
19 | Correct | 6 ms | 2680 KB | Output is correct |
20 | Correct | 6 ms | 2680 KB | Output is correct |
21 | Correct | 7 ms | 2680 KB | Output is correct |
22 | Correct | 5 ms | 2680 KB | Output is correct |
23 | Correct | 5 ms | 2680 KB | Output is correct |
24 | Correct | 5 ms | 2680 KB | Output is correct |
25 | Correct | 5 ms | 2680 KB | Output is correct |
26 | Correct | 8 ms | 2680 KB | Output is correct |
27 | Correct | 6 ms | 2680 KB | Output is correct |
28 | Correct | 6 ms | 2680 KB | Output is correct |
29 | Correct | 7 ms | 2680 KB | Output is correct |
30 | Correct | 5 ms | 2680 KB | Output is correct |
31 | Correct | 5 ms | 2680 KB | Output is correct |
32 | Correct | 7 ms | 2728 KB | Output is correct |
33 | Correct | 7 ms | 2792 KB | Output is correct |
34 | Correct | 5 ms | 2728 KB | Output is correct |
35 | Correct | 5 ms | 2680 KB | Output is correct |
36 | Correct | 5 ms | 2680 KB | Output is correct |
37 | Correct | 5 ms | 2680 KB | Output is correct |
38 | Correct | 5 ms | 2680 KB | Output is correct |
39 | Correct | 5 ms | 2680 KB | Output is correct |
40 | Correct | 5 ms | 2680 KB | Output is correct |
41 | Correct | 5 ms | 2680 KB | Output is correct |
42 | Correct | 6 ms | 2680 KB | Output is correct |
43 | Correct | 5 ms | 2680 KB | Output is correct |
44 | Correct | 5 ms | 2680 KB | Output is correct |
45 | Correct | 6 ms | 2808 KB | Output is correct |
46 | Correct | 18 ms | 3064 KB | Output is correct |
47 | Correct | 19 ms | 2976 KB | Output is correct |
48 | Correct | 17 ms | 3064 KB | Output is correct |
49 | Correct | 225 ms | 3192 KB | Output is correct |
50 | Correct | 221 ms | 3192 KB | Output is correct |
51 | Correct | 223 ms | 3320 KB | Output is correct |
52 | Correct | 121 ms | 3064 KB | Output is correct |
53 | Correct | 132 ms | 3164 KB | Output is correct |
54 | Correct | 122 ms | 3192 KB | Output is correct |
55 | Correct | 123 ms | 3128 KB | Output is correct |
56 | Correct | 122 ms | 3064 KB | Output is correct |
57 | Correct | 17 ms | 2936 KB | Output is correct |
58 | Correct | 18 ms | 3064 KB | Output is correct |
59 | Correct | 18 ms | 2936 KB | Output is correct |
60 | Correct | 18 ms | 3020 KB | Output is correct |
61 | Correct | 123 ms | 3192 KB | Output is correct |
62 | Correct | 123 ms | 3128 KB | Output is correct |
63 | Correct | 123 ms | 3168 KB | Output is correct |
64 | Correct | 17 ms | 2936 KB | Output is correct |
65 | Correct | 17 ms | 3064 KB | Output is correct |
66 | Correct | 18 ms | 2808 KB | Output is correct |
67 | Correct | 18 ms | 2936 KB | Output is correct |
68 | Correct | 262 ms | 3196 KB | Output is correct |
69 | Correct | 122 ms | 3064 KB | Output is correct |
70 | Correct | 138 ms | 3064 KB | Output is correct |
71 | Correct | 143 ms | 3192 KB | Output is correct |
72 | Correct | 19 ms | 3040 KB | Output is correct |
73 | Correct | 17 ms | 2936 KB | Output is correct |
74 | Correct | 137 ms | 3192 KB | Output is correct |
75 | Correct | 72 ms | 3064 KB | Output is correct |
76 | Correct | 56 ms | 3064 KB | Output is correct |
77 | Correct | 46 ms | 3044 KB | Output is correct |
78 | Correct | 80 ms | 3192 KB | Output is correct |
79 | Correct | 59 ms | 3064 KB | Output is correct |
80 | Correct | 49 ms | 3064 KB | Output is correct |
81 | Correct | 73 ms | 3068 KB | Output is correct |
82 | Correct | 56 ms | 2984 KB | Output is correct |
83 | Correct | 47 ms | 3064 KB | Output is correct |
84 | Correct | 79 ms | 3064 KB | Output is correct |
85 | Correct | 60 ms | 3068 KB | Output is correct |
86 | Correct | 49 ms | 2936 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2808 KB | Output is correct |
2 | Correct | 4 ms | 2936 KB | Output is correct |
3 | Correct | 4 ms | 2680 KB | Output is correct |
4 | Correct | 4 ms | 2680 KB | Output is correct |
5 | Correct | 5 ms | 2684 KB | Output is correct |
6 | Correct | 18 ms | 2680 KB | Output is correct |
7 | Correct | 5 ms | 2680 KB | Output is correct |
8 | Correct | 8 ms | 2808 KB | Output is correct |
9 | Correct | 8 ms | 2684 KB | Output is correct |
10 | Correct | 7 ms | 2684 KB | Output is correct |
11 | Correct | 6 ms | 2680 KB | Output is correct |
12 | Correct | 6 ms | 2936 KB | Output is correct |
13 | Correct | 6 ms | 2680 KB | Output is correct |
14 | Correct | 6 ms | 2680 KB | Output is correct |
15 | Correct | 5 ms | 2680 KB | Output is correct |
16 | Correct | 5 ms | 2680 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2680 KB | Output is correct |
19 | Correct | 6 ms | 2680 KB | Output is correct |
20 | Correct | 6 ms | 2680 KB | Output is correct |
21 | Correct | 7 ms | 2680 KB | Output is correct |
22 | Correct | 5 ms | 2680 KB | Output is correct |
23 | Correct | 5 ms | 2680 KB | Output is correct |
24 | Correct | 5 ms | 2680 KB | Output is correct |
25 | Correct | 5 ms | 2680 KB | Output is correct |
26 | Correct | 8 ms | 2680 KB | Output is correct |
27 | Correct | 6 ms | 2680 KB | Output is correct |
28 | Correct | 6 ms | 2680 KB | Output is correct |
29 | Correct | 7 ms | 2680 KB | Output is correct |
30 | Correct | 5 ms | 2680 KB | Output is correct |
31 | Correct | 5 ms | 2680 KB | Output is correct |
32 | Correct | 7 ms | 2728 KB | Output is correct |
33 | Correct | 7 ms | 2792 KB | Output is correct |
34 | Correct | 5 ms | 2728 KB | Output is correct |
35 | Correct | 5 ms | 2680 KB | Output is correct |
36 | Correct | 5 ms | 2680 KB | Output is correct |
37 | Correct | 5 ms | 2680 KB | Output is correct |
38 | Correct | 5 ms | 2680 KB | Output is correct |
39 | Correct | 5 ms | 2680 KB | Output is correct |
40 | Correct | 5 ms | 2680 KB | Output is correct |
41 | Correct | 5 ms | 2680 KB | Output is correct |
42 | Correct | 6 ms | 2680 KB | Output is correct |
43 | Correct | 5 ms | 2680 KB | Output is correct |
44 | Correct | 5 ms | 2680 KB | Output is correct |
45 | Correct | 6 ms | 2808 KB | Output is correct |
46 | Correct | 18 ms | 3064 KB | Output is correct |
47 | Correct | 19 ms | 2976 KB | Output is correct |
48 | Correct | 17 ms | 3064 KB | Output is correct |
49 | Correct | 225 ms | 3192 KB | Output is correct |
50 | Correct | 221 ms | 3192 KB | Output is correct |
51 | Correct | 223 ms | 3320 KB | Output is correct |
52 | Correct | 121 ms | 3064 KB | Output is correct |
53 | Correct | 132 ms | 3164 KB | Output is correct |
54 | Correct | 122 ms | 3192 KB | Output is correct |
55 | Correct | 123 ms | 3128 KB | Output is correct |
56 | Correct | 122 ms | 3064 KB | Output is correct |
57 | Correct | 17 ms | 2936 KB | Output is correct |
58 | Correct | 18 ms | 3064 KB | Output is correct |
59 | Correct | 18 ms | 2936 KB | Output is correct |
60 | Correct | 18 ms | 3020 KB | Output is correct |
61 | Correct | 123 ms | 3192 KB | Output is correct |
62 | Correct | 123 ms | 3128 KB | Output is correct |
63 | Correct | 123 ms | 3168 KB | Output is correct |
64 | Correct | 17 ms | 2936 KB | Output is correct |
65 | Correct | 17 ms | 3064 KB | Output is correct |
66 | Correct | 18 ms | 2808 KB | Output is correct |
67 | Correct | 18 ms | 2936 KB | Output is correct |
68 | Correct | 262 ms | 3196 KB | Output is correct |
69 | Correct | 122 ms | 3064 KB | Output is correct |
70 | Correct | 138 ms | 3064 KB | Output is correct |
71 | Correct | 143 ms | 3192 KB | Output is correct |
72 | Correct | 19 ms | 3040 KB | Output is correct |
73 | Correct | 17 ms | 2936 KB | Output is correct |
74 | Correct | 137 ms | 3192 KB | Output is correct |
75 | Correct | 72 ms | 3064 KB | Output is correct |
76 | Correct | 56 ms | 3064 KB | Output is correct |
77 | Correct | 46 ms | 3044 KB | Output is correct |
78 | Correct | 80 ms | 3192 KB | Output is correct |
79 | Correct | 59 ms | 3064 KB | Output is correct |
80 | Correct | 49 ms | 3064 KB | Output is correct |
81 | Correct | 73 ms | 3068 KB | Output is correct |
82 | Correct | 56 ms | 2984 KB | Output is correct |
83 | Correct | 47 ms | 3064 KB | Output is correct |
84 | Correct | 79 ms | 3064 KB | Output is correct |
85 | Correct | 60 ms | 3068 KB | Output is correct |
86 | Correct | 49 ms | 2936 KB | Output is correct |
87 | Correct | 70 ms | 3544 KB | Output is correct |
88 | Correct | 490 ms | 5364 KB | Output is correct |
89 | Execution timed out | 2061 ms | 10764 KB | Time limit exceeded |
90 | Halted | 0 ms | 0 KB | - |