# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47388 | 2018-05-02T10:14:32 Z | mirbek01 | Construction of Highway (JOI18_construction) | C++17 | 1000 ms | 2720 KB |
# include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; int n, c[N], p[N], fen[N]; vector <int> vec; void update(int pos, int val){ for(; pos <= n; pos |= pos + 1) fen[pos] += val; } int get(int pos){ int res = 0; for(; pos > 0; pos = (pos & (pos + 1)) - 1) res += fen[pos]; return res; } int main(){ scanf("%d", &n); for(int i = 1; i <= n; i ++){ scanf("%d", &c[i]); vec.emplace_back(c[i]); } sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end()) - vec.begin()); for(int i = 1; i <= n; i ++){ c[i] = lower_bound(vec.begin(), vec.end(), c[i]) - vec.begin() + 1; } int cc = 0; for(int i = 1; i < n; i ++){ int a, b; scanf("%d %d", &a, &b); int v = a, ans = 0; set <int> st; while(v){ update(c[v], 1); ans += get(c[v] - 1); st.insert(c[v]); v = p[v]; } cc += st.size(); v = a; while(v){ update(c[v], -1); c[v] = c[b]; v = p[v]; } printf("%d\n", ans); p[b] = a; } int lg = ceil(log2(n)); if(cc > n * lg) assert(0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 484 KB | Output is correct |
5 | Correct | 2 ms | 484 KB | Output is correct |
6 | Correct | 2 ms | 520 KB | Output is correct |
7 | Correct | 2 ms | 520 KB | Output is correct |
8 | Correct | 4 ms | 520 KB | Output is correct |
9 | Correct | 4 ms | 520 KB | Output is correct |
10 | Correct | 4 ms | 608 KB | Output is correct |
11 | Correct | 3 ms | 608 KB | Output is correct |
12 | Correct | 3 ms | 608 KB | Output is correct |
13 | Correct | 3 ms | 608 KB | Output is correct |
14 | Correct | 3 ms | 616 KB | Output is correct |
15 | Correct | 2 ms | 616 KB | Output is correct |
16 | Correct | 3 ms | 616 KB | Output is correct |
17 | Correct | 3 ms | 616 KB | Output is correct |
18 | Correct | 3 ms | 616 KB | Output is correct |
19 | Correct | 3 ms | 616 KB | Output is correct |
20 | Correct | 5 ms | 616 KB | Output is correct |
21 | Correct | 3 ms | 616 KB | Output is correct |
22 | Correct | 2 ms | 616 KB | Output is correct |
23 | Correct | 3 ms | 616 KB | Output is correct |
24 | Correct | 3 ms | 616 KB | Output is correct |
25 | Correct | 2 ms | 616 KB | Output is correct |
26 | Correct | 5 ms | 616 KB | Output is correct |
27 | Correct | 3 ms | 620 KB | Output is correct |
28 | Correct | 5 ms | 620 KB | Output is correct |
29 | Correct | 4 ms | 620 KB | Output is correct |
30 | Correct | 3 ms | 636 KB | Output is correct |
31 | Correct | 2 ms | 636 KB | Output is correct |
32 | Correct | 3 ms | 636 KB | Output is correct |
33 | Correct | 3 ms | 748 KB | Output is correct |
34 | Correct | 3 ms | 748 KB | Output is correct |
35 | Correct | 2 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 | 4 ms | 748 KB | Output is correct |
41 | Correct | 2 ms | 748 KB | Output is correct |
42 | Correct | 3 ms | 748 KB | Output is correct |
43 | Correct | 3 ms | 752 KB | Output is correct |
44 | Correct | 3 ms | 752 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 484 KB | Output is correct |
5 | Correct | 2 ms | 484 KB | Output is correct |
6 | Correct | 2 ms | 520 KB | Output is correct |
7 | Correct | 2 ms | 520 KB | Output is correct |
8 | Correct | 4 ms | 520 KB | Output is correct |
9 | Correct | 4 ms | 520 KB | Output is correct |
10 | Correct | 4 ms | 608 KB | Output is correct |
11 | Correct | 3 ms | 608 KB | Output is correct |
12 | Correct | 3 ms | 608 KB | Output is correct |
13 | Correct | 3 ms | 608 KB | Output is correct |
14 | Correct | 3 ms | 616 KB | Output is correct |
15 | Correct | 2 ms | 616 KB | Output is correct |
16 | Correct | 3 ms | 616 KB | Output is correct |
17 | Correct | 3 ms | 616 KB | Output is correct |
18 | Correct | 3 ms | 616 KB | Output is correct |
19 | Correct | 3 ms | 616 KB | Output is correct |
20 | Correct | 5 ms | 616 KB | Output is correct |
21 | Correct | 3 ms | 616 KB | Output is correct |
22 | Correct | 2 ms | 616 KB | Output is correct |
23 | Correct | 3 ms | 616 KB | Output is correct |
24 | Correct | 3 ms | 616 KB | Output is correct |
25 | Correct | 2 ms | 616 KB | Output is correct |
26 | Correct | 5 ms | 616 KB | Output is correct |
27 | Correct | 3 ms | 620 KB | Output is correct |
28 | Correct | 5 ms | 620 KB | Output is correct |
29 | Correct | 4 ms | 620 KB | Output is correct |
30 | Correct | 3 ms | 636 KB | Output is correct |
31 | Correct | 2 ms | 636 KB | Output is correct |
32 | Correct | 3 ms | 636 KB | Output is correct |
33 | Correct | 3 ms | 748 KB | Output is correct |
34 | Correct | 3 ms | 748 KB | Output is correct |
35 | Correct | 2 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 | 4 ms | 748 KB | Output is correct |
41 | Correct | 2 ms | 748 KB | Output is correct |
42 | Correct | 3 ms | 748 KB | Output is correct |
43 | Correct | 3 ms | 752 KB | Output is correct |
44 | Correct | 3 ms | 752 KB | Output is correct |
45 | Correct | 3 ms | 752 KB | Output is correct |
46 | Correct | 9 ms | 752 KB | Output is correct |
47 | Correct | 9 ms | 752 KB | Output is correct |
48 | Correct | 7 ms | 752 KB | Output is correct |
49 | Correct | 197 ms | 876 KB | Output is correct |
50 | Correct | 192 ms | 876 KB | Output is correct |
51 | Correct | 195 ms | 876 KB | Output is correct |
52 | Correct | 104 ms | 876 KB | Output is correct |
53 | Correct | 121 ms | 876 KB | Output is correct |
54 | Correct | 100 ms | 876 KB | Output is correct |
55 | Correct | 124 ms | 896 KB | Output is correct |
56 | Correct | 100 ms | 896 KB | Output is correct |
57 | Correct | 9 ms | 896 KB | Output is correct |
58 | Correct | 11 ms | 896 KB | Output is correct |
59 | Correct | 10 ms | 896 KB | Output is correct |
60 | Correct | 11 ms | 896 KB | Output is correct |
61 | Correct | 101 ms | 896 KB | Output is correct |
62 | Correct | 101 ms | 896 KB | Output is correct |
63 | Correct | 99 ms | 896 KB | Output is correct |
64 | Correct | 6 ms | 896 KB | Output is correct |
65 | Correct | 10 ms | 896 KB | Output is correct |
66 | Correct | 9 ms | 896 KB | Output is correct |
67 | Correct | 8 ms | 896 KB | Output is correct |
68 | Correct | 256 ms | 896 KB | Output is correct |
69 | Correct | 99 ms | 896 KB | Output is correct |
70 | Correct | 123 ms | 896 KB | Output is correct |
71 | Correct | 133 ms | 896 KB | Output is correct |
72 | Correct | 8 ms | 896 KB | Output is correct |
73 | Correct | 10 ms | 896 KB | Output is correct |
74 | Correct | 122 ms | 896 KB | Output is correct |
75 | Correct | 90 ms | 896 KB | Output is correct |
76 | Correct | 37 ms | 896 KB | Output is correct |
77 | Correct | 29 ms | 896 KB | Output is correct |
78 | Correct | 95 ms | 896 KB | Output is correct |
79 | Correct | 45 ms | 896 KB | Output is correct |
80 | Correct | 35 ms | 896 KB | Output is correct |
81 | Correct | 55 ms | 896 KB | Output is correct |
82 | Correct | 38 ms | 896 KB | Output is correct |
83 | Correct | 30 ms | 896 KB | Output is correct |
84 | Correct | 63 ms | 896 KB | Output is correct |
85 | Correct | 44 ms | 896 KB | Output is correct |
86 | Correct | 35 ms | 896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 484 KB | Output is correct |
5 | Correct | 2 ms | 484 KB | Output is correct |
6 | Correct | 2 ms | 520 KB | Output is correct |
7 | Correct | 2 ms | 520 KB | Output is correct |
8 | Correct | 4 ms | 520 KB | Output is correct |
9 | Correct | 4 ms | 520 KB | Output is correct |
10 | Correct | 4 ms | 608 KB | Output is correct |
11 | Correct | 3 ms | 608 KB | Output is correct |
12 | Correct | 3 ms | 608 KB | Output is correct |
13 | Correct | 3 ms | 608 KB | Output is correct |
14 | Correct | 3 ms | 616 KB | Output is correct |
15 | Correct | 2 ms | 616 KB | Output is correct |
16 | Correct | 3 ms | 616 KB | Output is correct |
17 | Correct | 3 ms | 616 KB | Output is correct |
18 | Correct | 3 ms | 616 KB | Output is correct |
19 | Correct | 3 ms | 616 KB | Output is correct |
20 | Correct | 5 ms | 616 KB | Output is correct |
21 | Correct | 3 ms | 616 KB | Output is correct |
22 | Correct | 2 ms | 616 KB | Output is correct |
23 | Correct | 3 ms | 616 KB | Output is correct |
24 | Correct | 3 ms | 616 KB | Output is correct |
25 | Correct | 2 ms | 616 KB | Output is correct |
26 | Correct | 5 ms | 616 KB | Output is correct |
27 | Correct | 3 ms | 620 KB | Output is correct |
28 | Correct | 5 ms | 620 KB | Output is correct |
29 | Correct | 4 ms | 620 KB | Output is correct |
30 | Correct | 3 ms | 636 KB | Output is correct |
31 | Correct | 2 ms | 636 KB | Output is correct |
32 | Correct | 3 ms | 636 KB | Output is correct |
33 | Correct | 3 ms | 748 KB | Output is correct |
34 | Correct | 3 ms | 748 KB | Output is correct |
35 | Correct | 2 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 | 4 ms | 748 KB | Output is correct |
41 | Correct | 2 ms | 748 KB | Output is correct |
42 | Correct | 3 ms | 748 KB | Output is correct |
43 | Correct | 3 ms | 752 KB | Output is correct |
44 | Correct | 3 ms | 752 KB | Output is correct |
45 | Correct | 3 ms | 752 KB | Output is correct |
46 | Correct | 9 ms | 752 KB | Output is correct |
47 | Correct | 9 ms | 752 KB | Output is correct |
48 | Correct | 7 ms | 752 KB | Output is correct |
49 | Correct | 197 ms | 876 KB | Output is correct |
50 | Correct | 192 ms | 876 KB | Output is correct |
51 | Correct | 195 ms | 876 KB | Output is correct |
52 | Correct | 104 ms | 876 KB | Output is correct |
53 | Correct | 121 ms | 876 KB | Output is correct |
54 | Correct | 100 ms | 876 KB | Output is correct |
55 | Correct | 124 ms | 896 KB | Output is correct |
56 | Correct | 100 ms | 896 KB | Output is correct |
57 | Correct | 9 ms | 896 KB | Output is correct |
58 | Correct | 11 ms | 896 KB | Output is correct |
59 | Correct | 10 ms | 896 KB | Output is correct |
60 | Correct | 11 ms | 896 KB | Output is correct |
61 | Correct | 101 ms | 896 KB | Output is correct |
62 | Correct | 101 ms | 896 KB | Output is correct |
63 | Correct | 99 ms | 896 KB | Output is correct |
64 | Correct | 6 ms | 896 KB | Output is correct |
65 | Correct | 10 ms | 896 KB | Output is correct |
66 | Correct | 9 ms | 896 KB | Output is correct |
67 | Correct | 8 ms | 896 KB | Output is correct |
68 | Correct | 256 ms | 896 KB | Output is correct |
69 | Correct | 99 ms | 896 KB | Output is correct |
70 | Correct | 123 ms | 896 KB | Output is correct |
71 | Correct | 133 ms | 896 KB | Output is correct |
72 | Correct | 8 ms | 896 KB | Output is correct |
73 | Correct | 10 ms | 896 KB | Output is correct |
74 | Correct | 122 ms | 896 KB | Output is correct |
75 | Correct | 90 ms | 896 KB | Output is correct |
76 | Correct | 37 ms | 896 KB | Output is correct |
77 | Correct | 29 ms | 896 KB | Output is correct |
78 | Correct | 95 ms | 896 KB | Output is correct |
79 | Correct | 45 ms | 896 KB | Output is correct |
80 | Correct | 35 ms | 896 KB | Output is correct |
81 | Correct | 55 ms | 896 KB | Output is correct |
82 | Correct | 38 ms | 896 KB | Output is correct |
83 | Correct | 30 ms | 896 KB | Output is correct |
84 | Correct | 63 ms | 896 KB | Output is correct |
85 | Correct | 44 ms | 896 KB | Output is correct |
86 | Correct | 35 ms | 896 KB | Output is correct |
87 | Correct | 19 ms | 896 KB | Output is correct |
88 | Correct | 57 ms | 1344 KB | Output is correct |
89 | Correct | 253 ms | 2644 KB | Output is correct |
90 | Correct | 249 ms | 2644 KB | Output is correct |
91 | Correct | 246 ms | 2720 KB | Output is correct |
92 | Execution timed out | 1079 ms | 2720 KB | Time limit exceeded |
93 | Halted | 0 ms | 0 KB | - |