# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47381 | 2018-05-02T08:40:25 Z | Talant | Construction of Highway (JOI18_construction) | C++17 | 271 ms | 972 KB |
#include <bits/stdc++.h> #define mk make_pair #define sc second #define fr first #define pb emplace_back #define all(s) s.begin(), s.end() #define sz(s) ( (int)s.size() ) #define int long long using namespace std; const int inf = (int)1e9 + 7; const int N = (int)4200; int n; int c[N]; int a,b; int pr[N]; int t[N]; vector <int> vec; void upd (int x) { for (; x < N; x += (x & -x)) t[x] ++; } int get (int x) { int res = 0; for (; x > 0; x -= (x & -x)) { res += t[x]; } return res; } main () { cin >> n; for (int i = 1; i <= n; i ++) { cin >> c[i]; vec.pb(c[i]); } sort (all(vec)); vec.erase (unique(all(vec)),vec.end()); for (int i = 1; i <= n; i ++) c[i] = lower_bound(all(vec),c[i]) - vec.begin() + 2; int q = n - 1; pr[1] = -1; while (q --) { scanf ("%lld%lld", &a,&b); int ans = 0; pr[b] = a; deque <int> v; while (a != -1) { v.push_front(a); a = pr[a]; } for (int i = v.size() - 1; i >= 0; i --) { ans += get(c[v[i]] - 1); upd(c[v[i]]); } for (int i = 0; i < v.size(); i ++) c[v[i]] = c[b]; printf("%lld\n", ans); memset(t,0,sizeof(t)); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 560 KB | Output is correct |
4 | Correct | 3 ms | 560 KB | Output is correct |
5 | Correct | 3 ms | 672 KB | Output is correct |
6 | Correct | 3 ms | 692 KB | Output is correct |
7 | Correct | 3 ms | 692 KB | Output is correct |
8 | Correct | 7 ms | 692 KB | Output is correct |
9 | Correct | 7 ms | 692 KB | Output is correct |
10 | Correct | 8 ms | 692 KB | Output is correct |
11 | Correct | 5 ms | 692 KB | Output is correct |
12 | Correct | 7 ms | 692 KB | Output is correct |
13 | Correct | 6 ms | 692 KB | Output is correct |
14 | Correct | 6 ms | 692 KB | Output is correct |
15 | Correct | 3 ms | 692 KB | Output is correct |
16 | Correct | 3 ms | 692 KB | Output is correct |
17 | Correct | 17 ms | 692 KB | Output is correct |
18 | Correct | 3 ms | 692 KB | Output is correct |
19 | Correct | 5 ms | 692 KB | Output is correct |
20 | Correct | 5 ms | 692 KB | Output is correct |
21 | Correct | 5 ms | 720 KB | Output is correct |
22 | Correct | 4 ms | 720 KB | Output is correct |
23 | Correct | 3 ms | 720 KB | Output is correct |
24 | Correct | 3 ms | 720 KB | Output is correct |
25 | Correct | 4 ms | 720 KB | Output is correct |
26 | Correct | 7 ms | 720 KB | Output is correct |
27 | Correct | 7 ms | 720 KB | Output is correct |
28 | Correct | 7 ms | 720 KB | Output is correct |
29 | Correct | 7 ms | 720 KB | Output is correct |
30 | Correct | 3 ms | 720 KB | Output is correct |
31 | Correct | 3 ms | 720 KB | Output is correct |
32 | Correct | 6 ms | 720 KB | Output is correct |
33 | Correct | 4 ms | 720 KB | Output is correct |
34 | Correct | 5 ms | 720 KB | Output is correct |
35 | Correct | 4 ms | 720 KB | Output is correct |
36 | Correct | 5 ms | 720 KB | Output is correct |
37 | Correct | 3 ms | 720 KB | Output is correct |
38 | Correct | 4 ms | 720 KB | Output is correct |
39 | Correct | 4 ms | 720 KB | Output is correct |
40 | Correct | 4 ms | 720 KB | Output is correct |
41 | Correct | 4 ms | 720 KB | Output is correct |
42 | Correct | 4 ms | 720 KB | Output is correct |
43 | Correct | 4 ms | 720 KB | Output is correct |
44 | Correct | 4 ms | 720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 560 KB | Output is correct |
4 | Correct | 3 ms | 560 KB | Output is correct |
5 | Correct | 3 ms | 672 KB | Output is correct |
6 | Correct | 3 ms | 692 KB | Output is correct |
7 | Correct | 3 ms | 692 KB | Output is correct |
8 | Correct | 7 ms | 692 KB | Output is correct |
9 | Correct | 7 ms | 692 KB | Output is correct |
10 | Correct | 8 ms | 692 KB | Output is correct |
11 | Correct | 5 ms | 692 KB | Output is correct |
12 | Correct | 7 ms | 692 KB | Output is correct |
13 | Correct | 6 ms | 692 KB | Output is correct |
14 | Correct | 6 ms | 692 KB | Output is correct |
15 | Correct | 3 ms | 692 KB | Output is correct |
16 | Correct | 3 ms | 692 KB | Output is correct |
17 | Correct | 17 ms | 692 KB | Output is correct |
18 | Correct | 3 ms | 692 KB | Output is correct |
19 | Correct | 5 ms | 692 KB | Output is correct |
20 | Correct | 5 ms | 692 KB | Output is correct |
21 | Correct | 5 ms | 720 KB | Output is correct |
22 | Correct | 4 ms | 720 KB | Output is correct |
23 | Correct | 3 ms | 720 KB | Output is correct |
24 | Correct | 3 ms | 720 KB | Output is correct |
25 | Correct | 4 ms | 720 KB | Output is correct |
26 | Correct | 7 ms | 720 KB | Output is correct |
27 | Correct | 7 ms | 720 KB | Output is correct |
28 | Correct | 7 ms | 720 KB | Output is correct |
29 | Correct | 7 ms | 720 KB | Output is correct |
30 | Correct | 3 ms | 720 KB | Output is correct |
31 | Correct | 3 ms | 720 KB | Output is correct |
32 | Correct | 6 ms | 720 KB | Output is correct |
33 | Correct | 4 ms | 720 KB | Output is correct |
34 | Correct | 5 ms | 720 KB | Output is correct |
35 | Correct | 4 ms | 720 KB | Output is correct |
36 | Correct | 5 ms | 720 KB | Output is correct |
37 | Correct | 3 ms | 720 KB | Output is correct |
38 | Correct | 4 ms | 720 KB | Output is correct |
39 | Correct | 4 ms | 720 KB | Output is correct |
40 | Correct | 4 ms | 720 KB | Output is correct |
41 | Correct | 4 ms | 720 KB | Output is correct |
42 | Correct | 4 ms | 720 KB | Output is correct |
43 | Correct | 4 ms | 720 KB | Output is correct |
44 | Correct | 4 ms | 720 KB | Output is correct |
45 | Correct | 5 ms | 720 KB | Output is correct |
46 | Correct | 16 ms | 892 KB | Output is correct |
47 | Correct | 13 ms | 892 KB | Output is correct |
48 | Correct | 15 ms | 892 KB | Output is correct |
49 | Correct | 259 ms | 892 KB | Output is correct |
50 | Correct | 259 ms | 924 KB | Output is correct |
51 | Correct | 253 ms | 924 KB | Output is correct |
52 | Correct | 138 ms | 924 KB | Output is correct |
53 | Correct | 143 ms | 924 KB | Output is correct |
54 | Correct | 131 ms | 924 KB | Output is correct |
55 | Correct | 131 ms | 924 KB | Output is correct |
56 | Correct | 136 ms | 924 KB | Output is correct |
57 | Correct | 24 ms | 924 KB | Output is correct |
58 | Correct | 12 ms | 924 KB | Output is correct |
59 | Correct | 12 ms | 924 KB | Output is correct |
60 | Correct | 13 ms | 924 KB | Output is correct |
61 | Correct | 137 ms | 972 KB | Output is correct |
62 | Correct | 131 ms | 972 KB | Output is correct |
63 | Correct | 128 ms | 972 KB | Output is correct |
64 | Correct | 11 ms | 972 KB | Output is correct |
65 | Correct | 12 ms | 972 KB | Output is correct |
66 | Correct | 12 ms | 972 KB | Output is correct |
67 | Correct | 12 ms | 972 KB | Output is correct |
68 | Correct | 271 ms | 972 KB | Output is correct |
69 | Correct | 133 ms | 972 KB | Output is correct |
70 | Correct | 144 ms | 972 KB | Output is correct |
71 | Correct | 143 ms | 972 KB | Output is correct |
72 | Correct | 12 ms | 972 KB | Output is correct |
73 | Correct | 13 ms | 972 KB | Output is correct |
74 | Correct | 145 ms | 972 KB | Output is correct |
75 | Correct | 74 ms | 972 KB | Output is correct |
76 | Correct | 55 ms | 972 KB | Output is correct |
77 | Correct | 44 ms | 972 KB | Output is correct |
78 | Correct | 79 ms | 972 KB | Output is correct |
79 | Correct | 57 ms | 972 KB | Output is correct |
80 | Correct | 46 ms | 972 KB | Output is correct |
81 | Correct | 76 ms | 972 KB | Output is correct |
82 | Correct | 56 ms | 972 KB | Output is correct |
83 | Correct | 47 ms | 972 KB | Output is correct |
84 | Correct | 82 ms | 972 KB | Output is correct |
85 | Correct | 60 ms | 972 KB | Output is correct |
86 | Correct | 46 ms | 972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 560 KB | Output is correct |
4 | Correct | 3 ms | 560 KB | Output is correct |
5 | Correct | 3 ms | 672 KB | Output is correct |
6 | Correct | 3 ms | 692 KB | Output is correct |
7 | Correct | 3 ms | 692 KB | Output is correct |
8 | Correct | 7 ms | 692 KB | Output is correct |
9 | Correct | 7 ms | 692 KB | Output is correct |
10 | Correct | 8 ms | 692 KB | Output is correct |
11 | Correct | 5 ms | 692 KB | Output is correct |
12 | Correct | 7 ms | 692 KB | Output is correct |
13 | Correct | 6 ms | 692 KB | Output is correct |
14 | Correct | 6 ms | 692 KB | Output is correct |
15 | Correct | 3 ms | 692 KB | Output is correct |
16 | Correct | 3 ms | 692 KB | Output is correct |
17 | Correct | 17 ms | 692 KB | Output is correct |
18 | Correct | 3 ms | 692 KB | Output is correct |
19 | Correct | 5 ms | 692 KB | Output is correct |
20 | Correct | 5 ms | 692 KB | Output is correct |
21 | Correct | 5 ms | 720 KB | Output is correct |
22 | Correct | 4 ms | 720 KB | Output is correct |
23 | Correct | 3 ms | 720 KB | Output is correct |
24 | Correct | 3 ms | 720 KB | Output is correct |
25 | Correct | 4 ms | 720 KB | Output is correct |
26 | Correct | 7 ms | 720 KB | Output is correct |
27 | Correct | 7 ms | 720 KB | Output is correct |
28 | Correct | 7 ms | 720 KB | Output is correct |
29 | Correct | 7 ms | 720 KB | Output is correct |
30 | Correct | 3 ms | 720 KB | Output is correct |
31 | Correct | 3 ms | 720 KB | Output is correct |
32 | Correct | 6 ms | 720 KB | Output is correct |
33 | Correct | 4 ms | 720 KB | Output is correct |
34 | Correct | 5 ms | 720 KB | Output is correct |
35 | Correct | 4 ms | 720 KB | Output is correct |
36 | Correct | 5 ms | 720 KB | Output is correct |
37 | Correct | 3 ms | 720 KB | Output is correct |
38 | Correct | 4 ms | 720 KB | Output is correct |
39 | Correct | 4 ms | 720 KB | Output is correct |
40 | Correct | 4 ms | 720 KB | Output is correct |
41 | Correct | 4 ms | 720 KB | Output is correct |
42 | Correct | 4 ms | 720 KB | Output is correct |
43 | Correct | 4 ms | 720 KB | Output is correct |
44 | Correct | 4 ms | 720 KB | Output is correct |
45 | Correct | 5 ms | 720 KB | Output is correct |
46 | Correct | 16 ms | 892 KB | Output is correct |
47 | Correct | 13 ms | 892 KB | Output is correct |
48 | Correct | 15 ms | 892 KB | Output is correct |
49 | Correct | 259 ms | 892 KB | Output is correct |
50 | Correct | 259 ms | 924 KB | Output is correct |
51 | Correct | 253 ms | 924 KB | Output is correct |
52 | Correct | 138 ms | 924 KB | Output is correct |
53 | Correct | 143 ms | 924 KB | Output is correct |
54 | Correct | 131 ms | 924 KB | Output is correct |
55 | Correct | 131 ms | 924 KB | Output is correct |
56 | Correct | 136 ms | 924 KB | Output is correct |
57 | Correct | 24 ms | 924 KB | Output is correct |
58 | Correct | 12 ms | 924 KB | Output is correct |
59 | Correct | 12 ms | 924 KB | Output is correct |
60 | Correct | 13 ms | 924 KB | Output is correct |
61 | Correct | 137 ms | 972 KB | Output is correct |
62 | Correct | 131 ms | 972 KB | Output is correct |
63 | Correct | 128 ms | 972 KB | Output is correct |
64 | Correct | 11 ms | 972 KB | Output is correct |
65 | Correct | 12 ms | 972 KB | Output is correct |
66 | Correct | 12 ms | 972 KB | Output is correct |
67 | Correct | 12 ms | 972 KB | Output is correct |
68 | Correct | 271 ms | 972 KB | Output is correct |
69 | Correct | 133 ms | 972 KB | Output is correct |
70 | Correct | 144 ms | 972 KB | Output is correct |
71 | Correct | 143 ms | 972 KB | Output is correct |
72 | Correct | 12 ms | 972 KB | Output is correct |
73 | Correct | 13 ms | 972 KB | Output is correct |
74 | Correct | 145 ms | 972 KB | Output is correct |
75 | Correct | 74 ms | 972 KB | Output is correct |
76 | Correct | 55 ms | 972 KB | Output is correct |
77 | Correct | 44 ms | 972 KB | Output is correct |
78 | Correct | 79 ms | 972 KB | Output is correct |
79 | Correct | 57 ms | 972 KB | Output is correct |
80 | Correct | 46 ms | 972 KB | Output is correct |
81 | Correct | 76 ms | 972 KB | Output is correct |
82 | Correct | 56 ms | 972 KB | Output is correct |
83 | Correct | 47 ms | 972 KB | Output is correct |
84 | Correct | 82 ms | 972 KB | Output is correct |
85 | Correct | 60 ms | 972 KB | Output is correct |
86 | Correct | 46 ms | 972 KB | Output is correct |
87 | Runtime error | 4 ms | 972 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
88 | Halted | 0 ms | 0 KB | - |