# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
897707 | 2024-01-03T15:14:13 Z | lovrot | Construction of Highway (JOI18_construction) | C++17 | 278 ms | 856 KB |
#include <cstdio> #include <vector> #include <algorithm> #define EB emplace_back using namespace std; typedef long long ll; const int LOG = 12; const int N = 1 << LOG; int n, C[N]; int F[N]; void add(int x, int val) { for(++x; x < N; x += x & -x) F[x] += val; } int sum(int x) { int sum = 0; for(++x; x; x -= x & -x) sum += F[x]; return sum; } int P[N]; vector<int> S; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d", C + i); S.EB(C[i]); } sort(S.begin(), S.end()); S.erase(unique(S.begin(), S.end()), S.end()); for(int i = 0; i < n - 1; ++i) { int a, b; scanf("%d%d", &a, &b); ll cost = 0; for(int _a = a; _a; _a = P[_a]) { int pos = lower_bound(S.begin(), S.end(), C[_a]) - S.begin() + 1; cost += (ll) sum(pos - 1); add(pos, 1); } printf("%lld\n", cost); for(int _a = a; _a; _a = P[_a]) { int pos = lower_bound(S.begin(), S.end(), C[_a]) - S.begin() + 1; add(pos, -1); C[_a] = C[b]; } P[b] = a; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 456 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 1 ms | 500 KB | Output is correct |
7 | Correct | 1 ms | 432 KB | Output is correct |
8 | Correct | 4 ms | 432 KB | Output is correct |
9 | Correct | 4 ms | 348 KB | Output is correct |
10 | Correct | 4 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 3 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 3 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 2 ms | 348 KB | Output is correct |
20 | Correct | 2 ms | 344 KB | Output is correct |
21 | Correct | 2 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 1 ms | 348 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 4 ms | 348 KB | Output is correct |
27 | Correct | 2 ms | 348 KB | Output is correct |
28 | Correct | 2 ms | 348 KB | Output is correct |
29 | Correct | 2 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 348 KB | Output is correct |
31 | Correct | 1 ms | 348 KB | Output is correct |
32 | Correct | 2 ms | 456 KB | Output is correct |
33 | Correct | 2 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 456 KB | Output is correct |
35 | Correct | 1 ms | 348 KB | Output is correct |
36 | Correct | 1 ms | 428 KB | Output is correct |
37 | Correct | 1 ms | 348 KB | Output is correct |
38 | Correct | 1 ms | 348 KB | Output is correct |
39 | Correct | 2 ms | 428 KB | Output is correct |
40 | Correct | 1 ms | 348 KB | Output is correct |
41 | Correct | 1 ms | 348 KB | Output is correct |
42 | Correct | 1 ms | 600 KB | Output is correct |
43 | Correct | 1 ms | 348 KB | Output is correct |
44 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 456 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 1 ms | 500 KB | Output is correct |
7 | Correct | 1 ms | 432 KB | Output is correct |
8 | Correct | 4 ms | 432 KB | Output is correct |
9 | Correct | 4 ms | 348 KB | Output is correct |
10 | Correct | 4 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 3 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 3 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 2 ms | 348 KB | Output is correct |
20 | Correct | 2 ms | 344 KB | Output is correct |
21 | Correct | 2 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 1 ms | 348 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 4 ms | 348 KB | Output is correct |
27 | Correct | 2 ms | 348 KB | Output is correct |
28 | Correct | 2 ms | 348 KB | Output is correct |
29 | Correct | 2 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 348 KB | Output is correct |
31 | Correct | 1 ms | 348 KB | Output is correct |
32 | Correct | 2 ms | 456 KB | Output is correct |
33 | Correct | 2 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 456 KB | Output is correct |
35 | Correct | 1 ms | 348 KB | Output is correct |
36 | Correct | 1 ms | 428 KB | Output is correct |
37 | Correct | 1 ms | 348 KB | Output is correct |
38 | Correct | 1 ms | 348 KB | Output is correct |
39 | Correct | 2 ms | 428 KB | Output is correct |
40 | Correct | 1 ms | 348 KB | Output is correct |
41 | Correct | 1 ms | 348 KB | Output is correct |
42 | Correct | 1 ms | 600 KB | Output is correct |
43 | Correct | 1 ms | 348 KB | Output is correct |
44 | Correct | 1 ms | 344 KB | Output is correct |
45 | Correct | 1 ms | 348 KB | Output is correct |
46 | Correct | 6 ms | 520 KB | Output is correct |
47 | Correct | 6 ms | 576 KB | Output is correct |
48 | Correct | 5 ms | 576 KB | Output is correct |
49 | Correct | 261 ms | 360 KB | Output is correct |
50 | Correct | 278 ms | 556 KB | Output is correct |
51 | Correct | 257 ms | 348 KB | Output is correct |
52 | Correct | 130 ms | 348 KB | Output is correct |
53 | Correct | 150 ms | 556 KB | Output is correct |
54 | Correct | 132 ms | 348 KB | Output is correct |
55 | Correct | 133 ms | 556 KB | Output is correct |
56 | Correct | 136 ms | 348 KB | Output is correct |
57 | Correct | 6 ms | 344 KB | Output is correct |
58 | Correct | 8 ms | 520 KB | Output is correct |
59 | Correct | 8 ms | 344 KB | Output is correct |
60 | Correct | 8 ms | 348 KB | Output is correct |
61 | Correct | 131 ms | 348 KB | Output is correct |
62 | Correct | 144 ms | 560 KB | Output is correct |
63 | Correct | 132 ms | 344 KB | Output is correct |
64 | Correct | 2 ms | 348 KB | Output is correct |
65 | Correct | 3 ms | 348 KB | Output is correct |
66 | Correct | 5 ms | 444 KB | Output is correct |
67 | Correct | 5 ms | 344 KB | Output is correct |
68 | Correct | 211 ms | 344 KB | Output is correct |
69 | Correct | 131 ms | 348 KB | Output is correct |
70 | Correct | 112 ms | 348 KB | Output is correct |
71 | Correct | 123 ms | 524 KB | Output is correct |
72 | Correct | 6 ms | 348 KB | Output is correct |
73 | Correct | 5 ms | 348 KB | Output is correct |
74 | Correct | 105 ms | 528 KB | Output is correct |
75 | Correct | 69 ms | 552 KB | Output is correct |
76 | Correct | 47 ms | 344 KB | Output is correct |
77 | Correct | 36 ms | 344 KB | Output is correct |
78 | Correct | 53 ms | 520 KB | Output is correct |
79 | Correct | 40 ms | 600 KB | Output is correct |
80 | Correct | 27 ms | 344 KB | Output is correct |
81 | Correct | 69 ms | 548 KB | Output is correct |
82 | Correct | 51 ms | 564 KB | Output is correct |
83 | Correct | 37 ms | 348 KB | Output is correct |
84 | Correct | 56 ms | 348 KB | Output is correct |
85 | Correct | 37 ms | 344 KB | Output is correct |
86 | Correct | 28 ms | 528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 456 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 1 ms | 500 KB | Output is correct |
7 | Correct | 1 ms | 432 KB | Output is correct |
8 | Correct | 4 ms | 432 KB | Output is correct |
9 | Correct | 4 ms | 348 KB | Output is correct |
10 | Correct | 4 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 3 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 3 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 2 ms | 348 KB | Output is correct |
20 | Correct | 2 ms | 344 KB | Output is correct |
21 | Correct | 2 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 1 ms | 348 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 4 ms | 348 KB | Output is correct |
27 | Correct | 2 ms | 348 KB | Output is correct |
28 | Correct | 2 ms | 348 KB | Output is correct |
29 | Correct | 2 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 348 KB | Output is correct |
31 | Correct | 1 ms | 348 KB | Output is correct |
32 | Correct | 2 ms | 456 KB | Output is correct |
33 | Correct | 2 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 456 KB | Output is correct |
35 | Correct | 1 ms | 348 KB | Output is correct |
36 | Correct | 1 ms | 428 KB | Output is correct |
37 | Correct | 1 ms | 348 KB | Output is correct |
38 | Correct | 1 ms | 348 KB | Output is correct |
39 | Correct | 2 ms | 428 KB | Output is correct |
40 | Correct | 1 ms | 348 KB | Output is correct |
41 | Correct | 1 ms | 348 KB | Output is correct |
42 | Correct | 1 ms | 600 KB | Output is correct |
43 | Correct | 1 ms | 348 KB | Output is correct |
44 | Correct | 1 ms | 344 KB | Output is correct |
45 | Correct | 1 ms | 348 KB | Output is correct |
46 | Correct | 6 ms | 520 KB | Output is correct |
47 | Correct | 6 ms | 576 KB | Output is correct |
48 | Correct | 5 ms | 576 KB | Output is correct |
49 | Correct | 261 ms | 360 KB | Output is correct |
50 | Correct | 278 ms | 556 KB | Output is correct |
51 | Correct | 257 ms | 348 KB | Output is correct |
52 | Correct | 130 ms | 348 KB | Output is correct |
53 | Correct | 150 ms | 556 KB | Output is correct |
54 | Correct | 132 ms | 348 KB | Output is correct |
55 | Correct | 133 ms | 556 KB | Output is correct |
56 | Correct | 136 ms | 348 KB | Output is correct |
57 | Correct | 6 ms | 344 KB | Output is correct |
58 | Correct | 8 ms | 520 KB | Output is correct |
59 | Correct | 8 ms | 344 KB | Output is correct |
60 | Correct | 8 ms | 348 KB | Output is correct |
61 | Correct | 131 ms | 348 KB | Output is correct |
62 | Correct | 144 ms | 560 KB | Output is correct |
63 | Correct | 132 ms | 344 KB | Output is correct |
64 | Correct | 2 ms | 348 KB | Output is correct |
65 | Correct | 3 ms | 348 KB | Output is correct |
66 | Correct | 5 ms | 444 KB | Output is correct |
67 | Correct | 5 ms | 344 KB | Output is correct |
68 | Correct | 211 ms | 344 KB | Output is correct |
69 | Correct | 131 ms | 348 KB | Output is correct |
70 | Correct | 112 ms | 348 KB | Output is correct |
71 | Correct | 123 ms | 524 KB | Output is correct |
72 | Correct | 6 ms | 348 KB | Output is correct |
73 | Correct | 5 ms | 348 KB | Output is correct |
74 | Correct | 105 ms | 528 KB | Output is correct |
75 | Correct | 69 ms | 552 KB | Output is correct |
76 | Correct | 47 ms | 344 KB | Output is correct |
77 | Correct | 36 ms | 344 KB | Output is correct |
78 | Correct | 53 ms | 520 KB | Output is correct |
79 | Correct | 40 ms | 600 KB | Output is correct |
80 | Correct | 27 ms | 344 KB | Output is correct |
81 | Correct | 69 ms | 548 KB | Output is correct |
82 | Correct | 51 ms | 564 KB | Output is correct |
83 | Correct | 37 ms | 348 KB | Output is correct |
84 | Correct | 56 ms | 348 KB | Output is correct |
85 | Correct | 37 ms | 344 KB | Output is correct |
86 | Correct | 28 ms | 528 KB | Output is correct |
87 | Runtime error | 2 ms | 856 KB | Execution killed with signal 11 |
88 | Halted | 0 ms | 0 KB | - |