#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 101010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int p[MAX][505];
ll r[MAX];
ll l[MAX];
int A[MAX];
int B[MAX];
ll W[MAX];
int find(int t, int x) {
if (!p[t][x]) return x;
else return p[t][x] = find(t, p[t][x]);
}
bool uni(int t, int u, int v) {
u = find(t, u);
v = find(t, v);
if (u == v) return false;
p[t][u] = v;
return true;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
cin >> N >> M;
int i, j;
vector<pair<ll, pii>> in;
int a, b, c;
in.push_back({ 0, {0, 0} });
for (i = 1; i <= M; i++) cin >> a >> b >> c, in.push_back(make_pair(c, pii(a, b)));
sort(in.begin(), in.end());
for (i = 1; i <= M; i++) tie(A[i], B[i], W[i]) = make_tuple(in[i].second.first, in[i].second.second, in[i].first);
W[0] = -2000000010;
W[M + 1] = 2000000010;
for (i = M; i >= 1; i--) {
for (j = i; j <= M; j++) if (!uni(j, A[i], B[i])) break;
r[i] = W[j];
}
memset(p, 0, sizeof(p));
for (i = 1; i <= M; i++) {
for (j = i; j >= 1; j--) if (!uni(j, A[i], B[i])) break;
l[i] = W[j];
}
vector<pll> sum, mul;
for (i = 1; i <= M; i++) {
if (l[i] != W[i]) {
ll loc = (W[i] + l[i]) / 2 + 1;
sum.emplace_back(loc, W[i]);
sum.emplace_back(W[i], -W[i]);
mul.emplace_back(loc, -1);
mul.emplace_back(W[i], 1);
}
if (r[i] != W[i]) {
ll loc = (W[i] + r[i]) / 2;
sum.emplace_back(W[i] + 1, -W[i]);
sum.emplace_back(loc + 1, W[i]);
mul.emplace_back(W[i] + 1, 1);
mul.emplace_back(loc + 1, -1);
}
}
sort(mul.begin(), mul.end());
sort(sum.begin(), sum.end());
int Q;
cin >> Q;
ll s, m;
s = m = 0;
int ptr1, ptr2;
ptr1 = 0, ptr2 = 0;
while (Q--) {
ll x;
cin >> x;
while (ptr1 < sum.size() && sum[ptr1].first <= x) s += sum[ptr1++].second;
while (ptr2 < mul.size() && mul[ptr2].first <= x) m += mul[ptr2++].second;
cout << x * m + s << ln;
}
}
Compilation message
reconstruction.cpp: In function 'int main()':
reconstruction.cpp:83:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | while (ptr1 < sum.size() && sum[ptr1].first <= x) s += sum[ptr1++].second;
| ~~~~~^~~~~~~~~~~~
reconstruction.cpp:84:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | while (ptr2 < mul.size() && mul[ptr2].first <= x) m += mul[ptr2++].second;
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
199980 KB |
Output is correct |
2 |
Correct |
76 ms |
199948 KB |
Output is correct |
3 |
Correct |
83 ms |
199976 KB |
Output is correct |
4 |
Correct |
83 ms |
199896 KB |
Output is correct |
5 |
Correct |
73 ms |
199952 KB |
Output is correct |
6 |
Correct |
73 ms |
199932 KB |
Output is correct |
7 |
Correct |
75 ms |
199884 KB |
Output is correct |
8 |
Correct |
72 ms |
199872 KB |
Output is correct |
9 |
Correct |
73 ms |
199956 KB |
Output is correct |
10 |
Correct |
74 ms |
199904 KB |
Output is correct |
11 |
Correct |
73 ms |
199880 KB |
Output is correct |
12 |
Correct |
74 ms |
199876 KB |
Output is correct |
13 |
Correct |
75 ms |
199940 KB |
Output is correct |
14 |
Correct |
72 ms |
199884 KB |
Output is correct |
15 |
Correct |
75 ms |
199920 KB |
Output is correct |
16 |
Correct |
81 ms |
199920 KB |
Output is correct |
17 |
Correct |
76 ms |
199884 KB |
Output is correct |
18 |
Correct |
79 ms |
199880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
199980 KB |
Output is correct |
2 |
Correct |
76 ms |
199948 KB |
Output is correct |
3 |
Correct |
83 ms |
199976 KB |
Output is correct |
4 |
Correct |
83 ms |
199896 KB |
Output is correct |
5 |
Correct |
73 ms |
199952 KB |
Output is correct |
6 |
Correct |
73 ms |
199932 KB |
Output is correct |
7 |
Correct |
75 ms |
199884 KB |
Output is correct |
8 |
Correct |
72 ms |
199872 KB |
Output is correct |
9 |
Correct |
73 ms |
199956 KB |
Output is correct |
10 |
Correct |
74 ms |
199904 KB |
Output is correct |
11 |
Correct |
73 ms |
199880 KB |
Output is correct |
12 |
Correct |
74 ms |
199876 KB |
Output is correct |
13 |
Correct |
75 ms |
199940 KB |
Output is correct |
14 |
Correct |
72 ms |
199884 KB |
Output is correct |
15 |
Correct |
75 ms |
199920 KB |
Output is correct |
16 |
Correct |
81 ms |
199920 KB |
Output is correct |
17 |
Correct |
76 ms |
199884 KB |
Output is correct |
18 |
Correct |
79 ms |
199880 KB |
Output is correct |
19 |
Correct |
76 ms |
199932 KB |
Output is correct |
20 |
Correct |
2960 ms |
220724 KB |
Output is correct |
21 |
Correct |
3902 ms |
220708 KB |
Output is correct |
22 |
Correct |
4309 ms |
220604 KB |
Output is correct |
23 |
Correct |
2540 ms |
220588 KB |
Output is correct |
24 |
Correct |
2709 ms |
220632 KB |
Output is correct |
25 |
Correct |
3615 ms |
220644 KB |
Output is correct |
26 |
Correct |
3162 ms |
220528 KB |
Output is correct |
27 |
Correct |
2941 ms |
220612 KB |
Output is correct |
28 |
Correct |
2820 ms |
220528 KB |
Output is correct |
29 |
Correct |
3619 ms |
205756 KB |
Output is correct |
30 |
Correct |
3402 ms |
220588 KB |
Output is correct |
31 |
Correct |
2804 ms |
220664 KB |
Output is correct |
32 |
Correct |
2781 ms |
220536 KB |
Output is correct |
33 |
Correct |
2808 ms |
220624 KB |
Output is correct |
34 |
Correct |
2299 ms |
204768 KB |
Output is correct |
35 |
Correct |
2813 ms |
220712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
199972 KB |
Output is correct |
2 |
Correct |
91 ms |
199964 KB |
Output is correct |
3 |
Correct |
77 ms |
199888 KB |
Output is correct |
4 |
Correct |
1646 ms |
231820 KB |
Output is correct |
5 |
Correct |
1710 ms |
231664 KB |
Output is correct |
6 |
Correct |
1653 ms |
231672 KB |
Output is correct |
7 |
Correct |
1765 ms |
233524 KB |
Output is correct |
8 |
Correct |
1770 ms |
233704 KB |
Output is correct |
9 |
Correct |
1976 ms |
233760 KB |
Output is correct |
10 |
Correct |
1651 ms |
231728 KB |
Output is correct |
11 |
Correct |
2024 ms |
233800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
199980 KB |
Output is correct |
2 |
Correct |
76 ms |
199948 KB |
Output is correct |
3 |
Correct |
83 ms |
199976 KB |
Output is correct |
4 |
Correct |
83 ms |
199896 KB |
Output is correct |
5 |
Correct |
73 ms |
199952 KB |
Output is correct |
6 |
Correct |
73 ms |
199932 KB |
Output is correct |
7 |
Correct |
75 ms |
199884 KB |
Output is correct |
8 |
Correct |
72 ms |
199872 KB |
Output is correct |
9 |
Correct |
73 ms |
199956 KB |
Output is correct |
10 |
Correct |
74 ms |
199904 KB |
Output is correct |
11 |
Correct |
73 ms |
199880 KB |
Output is correct |
12 |
Correct |
74 ms |
199876 KB |
Output is correct |
13 |
Correct |
75 ms |
199940 KB |
Output is correct |
14 |
Correct |
72 ms |
199884 KB |
Output is correct |
15 |
Correct |
75 ms |
199920 KB |
Output is correct |
16 |
Correct |
81 ms |
199920 KB |
Output is correct |
17 |
Correct |
76 ms |
199884 KB |
Output is correct |
18 |
Correct |
79 ms |
199880 KB |
Output is correct |
19 |
Correct |
75 ms |
199880 KB |
Output is correct |
20 |
Correct |
268 ms |
212364 KB |
Output is correct |
21 |
Correct |
257 ms |
212556 KB |
Output is correct |
22 |
Correct |
269 ms |
212496 KB |
Output is correct |
23 |
Correct |
316 ms |
212436 KB |
Output is correct |
24 |
Correct |
265 ms |
212504 KB |
Output is correct |
25 |
Correct |
266 ms |
212420 KB |
Output is correct |
26 |
Correct |
264 ms |
212428 KB |
Output is correct |
27 |
Correct |
275 ms |
212528 KB |
Output is correct |
28 |
Correct |
269 ms |
212364 KB |
Output is correct |
29 |
Correct |
302 ms |
212432 KB |
Output is correct |
30 |
Correct |
277 ms |
212616 KB |
Output is correct |
31 |
Correct |
260 ms |
212460 KB |
Output is correct |
32 |
Correct |
270 ms |
212940 KB |
Output is correct |
33 |
Correct |
258 ms |
212304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
199980 KB |
Output is correct |
2 |
Correct |
76 ms |
199948 KB |
Output is correct |
3 |
Correct |
83 ms |
199976 KB |
Output is correct |
4 |
Correct |
83 ms |
199896 KB |
Output is correct |
5 |
Correct |
73 ms |
199952 KB |
Output is correct |
6 |
Correct |
73 ms |
199932 KB |
Output is correct |
7 |
Correct |
75 ms |
199884 KB |
Output is correct |
8 |
Correct |
72 ms |
199872 KB |
Output is correct |
9 |
Correct |
73 ms |
199956 KB |
Output is correct |
10 |
Correct |
74 ms |
199904 KB |
Output is correct |
11 |
Correct |
73 ms |
199880 KB |
Output is correct |
12 |
Correct |
74 ms |
199876 KB |
Output is correct |
13 |
Correct |
75 ms |
199940 KB |
Output is correct |
14 |
Correct |
72 ms |
199884 KB |
Output is correct |
15 |
Correct |
75 ms |
199920 KB |
Output is correct |
16 |
Correct |
81 ms |
199920 KB |
Output is correct |
17 |
Correct |
76 ms |
199884 KB |
Output is correct |
18 |
Correct |
79 ms |
199880 KB |
Output is correct |
19 |
Correct |
76 ms |
199932 KB |
Output is correct |
20 |
Correct |
2960 ms |
220724 KB |
Output is correct |
21 |
Correct |
3902 ms |
220708 KB |
Output is correct |
22 |
Correct |
4309 ms |
220604 KB |
Output is correct |
23 |
Correct |
2540 ms |
220588 KB |
Output is correct |
24 |
Correct |
2709 ms |
220632 KB |
Output is correct |
25 |
Correct |
3615 ms |
220644 KB |
Output is correct |
26 |
Correct |
3162 ms |
220528 KB |
Output is correct |
27 |
Correct |
2941 ms |
220612 KB |
Output is correct |
28 |
Correct |
2820 ms |
220528 KB |
Output is correct |
29 |
Correct |
3619 ms |
205756 KB |
Output is correct |
30 |
Correct |
3402 ms |
220588 KB |
Output is correct |
31 |
Correct |
2804 ms |
220664 KB |
Output is correct |
32 |
Correct |
2781 ms |
220536 KB |
Output is correct |
33 |
Correct |
2808 ms |
220624 KB |
Output is correct |
34 |
Correct |
2299 ms |
204768 KB |
Output is correct |
35 |
Correct |
2813 ms |
220712 KB |
Output is correct |
36 |
Correct |
2761 ms |
220792 KB |
Output is correct |
37 |
Correct |
3649 ms |
220864 KB |
Output is correct |
38 |
Correct |
4502 ms |
220840 KB |
Output is correct |
39 |
Correct |
2436 ms |
220960 KB |
Output is correct |
40 |
Correct |
2421 ms |
220872 KB |
Output is correct |
41 |
Correct |
3013 ms |
220868 KB |
Output is correct |
42 |
Correct |
2877 ms |
220764 KB |
Output is correct |
43 |
Correct |
2681 ms |
220864 KB |
Output is correct |
44 |
Correct |
2588 ms |
220816 KB |
Output is correct |
45 |
Correct |
3050 ms |
206060 KB |
Output is correct |
46 |
Correct |
2646 ms |
220804 KB |
Output is correct |
47 |
Correct |
2707 ms |
220748 KB |
Output is correct |
48 |
Correct |
2799 ms |
220860 KB |
Output is correct |
49 |
Correct |
2711 ms |
220732 KB |
Output is correct |
50 |
Correct |
2214 ms |
204968 KB |
Output is correct |
51 |
Correct |
2750 ms |
220776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
199980 KB |
Output is correct |
2 |
Correct |
76 ms |
199948 KB |
Output is correct |
3 |
Correct |
83 ms |
199976 KB |
Output is correct |
4 |
Correct |
83 ms |
199896 KB |
Output is correct |
5 |
Correct |
73 ms |
199952 KB |
Output is correct |
6 |
Correct |
73 ms |
199932 KB |
Output is correct |
7 |
Correct |
75 ms |
199884 KB |
Output is correct |
8 |
Correct |
72 ms |
199872 KB |
Output is correct |
9 |
Correct |
73 ms |
199956 KB |
Output is correct |
10 |
Correct |
74 ms |
199904 KB |
Output is correct |
11 |
Correct |
73 ms |
199880 KB |
Output is correct |
12 |
Correct |
74 ms |
199876 KB |
Output is correct |
13 |
Correct |
75 ms |
199940 KB |
Output is correct |
14 |
Correct |
72 ms |
199884 KB |
Output is correct |
15 |
Correct |
75 ms |
199920 KB |
Output is correct |
16 |
Correct |
81 ms |
199920 KB |
Output is correct |
17 |
Correct |
76 ms |
199884 KB |
Output is correct |
18 |
Correct |
79 ms |
199880 KB |
Output is correct |
19 |
Correct |
76 ms |
199932 KB |
Output is correct |
20 |
Correct |
2960 ms |
220724 KB |
Output is correct |
21 |
Correct |
3902 ms |
220708 KB |
Output is correct |
22 |
Correct |
4309 ms |
220604 KB |
Output is correct |
23 |
Correct |
2540 ms |
220588 KB |
Output is correct |
24 |
Correct |
2709 ms |
220632 KB |
Output is correct |
25 |
Correct |
3615 ms |
220644 KB |
Output is correct |
26 |
Correct |
3162 ms |
220528 KB |
Output is correct |
27 |
Correct |
2941 ms |
220612 KB |
Output is correct |
28 |
Correct |
2820 ms |
220528 KB |
Output is correct |
29 |
Correct |
3619 ms |
205756 KB |
Output is correct |
30 |
Correct |
3402 ms |
220588 KB |
Output is correct |
31 |
Correct |
2804 ms |
220664 KB |
Output is correct |
32 |
Correct |
2781 ms |
220536 KB |
Output is correct |
33 |
Correct |
2808 ms |
220624 KB |
Output is correct |
34 |
Correct |
2299 ms |
204768 KB |
Output is correct |
35 |
Correct |
2813 ms |
220712 KB |
Output is correct |
36 |
Correct |
76 ms |
199972 KB |
Output is correct |
37 |
Correct |
91 ms |
199964 KB |
Output is correct |
38 |
Correct |
77 ms |
199888 KB |
Output is correct |
39 |
Correct |
1646 ms |
231820 KB |
Output is correct |
40 |
Correct |
1710 ms |
231664 KB |
Output is correct |
41 |
Correct |
1653 ms |
231672 KB |
Output is correct |
42 |
Correct |
1765 ms |
233524 KB |
Output is correct |
43 |
Correct |
1770 ms |
233704 KB |
Output is correct |
44 |
Correct |
1976 ms |
233760 KB |
Output is correct |
45 |
Correct |
1651 ms |
231728 KB |
Output is correct |
46 |
Correct |
2024 ms |
233800 KB |
Output is correct |
47 |
Correct |
75 ms |
199880 KB |
Output is correct |
48 |
Correct |
268 ms |
212364 KB |
Output is correct |
49 |
Correct |
257 ms |
212556 KB |
Output is correct |
50 |
Correct |
269 ms |
212496 KB |
Output is correct |
51 |
Correct |
316 ms |
212436 KB |
Output is correct |
52 |
Correct |
265 ms |
212504 KB |
Output is correct |
53 |
Correct |
266 ms |
212420 KB |
Output is correct |
54 |
Correct |
264 ms |
212428 KB |
Output is correct |
55 |
Correct |
275 ms |
212528 KB |
Output is correct |
56 |
Correct |
269 ms |
212364 KB |
Output is correct |
57 |
Correct |
302 ms |
212432 KB |
Output is correct |
58 |
Correct |
277 ms |
212616 KB |
Output is correct |
59 |
Correct |
260 ms |
212460 KB |
Output is correct |
60 |
Correct |
270 ms |
212940 KB |
Output is correct |
61 |
Correct |
258 ms |
212304 KB |
Output is correct |
62 |
Correct |
2761 ms |
220792 KB |
Output is correct |
63 |
Correct |
3649 ms |
220864 KB |
Output is correct |
64 |
Correct |
4502 ms |
220840 KB |
Output is correct |
65 |
Correct |
2436 ms |
220960 KB |
Output is correct |
66 |
Correct |
2421 ms |
220872 KB |
Output is correct |
67 |
Correct |
3013 ms |
220868 KB |
Output is correct |
68 |
Correct |
2877 ms |
220764 KB |
Output is correct |
69 |
Correct |
2681 ms |
220864 KB |
Output is correct |
70 |
Correct |
2588 ms |
220816 KB |
Output is correct |
71 |
Correct |
3050 ms |
206060 KB |
Output is correct |
72 |
Correct |
2646 ms |
220804 KB |
Output is correct |
73 |
Correct |
2707 ms |
220748 KB |
Output is correct |
74 |
Correct |
2799 ms |
220860 KB |
Output is correct |
75 |
Correct |
2711 ms |
220732 KB |
Output is correct |
76 |
Correct |
2214 ms |
204968 KB |
Output is correct |
77 |
Correct |
2750 ms |
220776 KB |
Output is correct |
78 |
Correct |
2876 ms |
230804 KB |
Output is correct |
79 |
Correct |
3770 ms |
232788 KB |
Output is correct |
80 |
Correct |
4411 ms |
231600 KB |
Output is correct |
81 |
Correct |
2521 ms |
243212 KB |
Output is correct |
82 |
Correct |
2484 ms |
242216 KB |
Output is correct |
83 |
Correct |
3213 ms |
242072 KB |
Output is correct |
84 |
Correct |
2910 ms |
242124 KB |
Output is correct |
85 |
Correct |
2824 ms |
242156 KB |
Output is correct |
86 |
Correct |
2721 ms |
242180 KB |
Output is correct |
87 |
Correct |
3170 ms |
228884 KB |
Output is correct |
88 |
Correct |
3139 ms |
242080 KB |
Output is correct |
89 |
Correct |
2853 ms |
242036 KB |
Output is correct |
90 |
Correct |
2871 ms |
242184 KB |
Output is correct |
91 |
Correct |
2823 ms |
242084 KB |
Output is correct |
92 |
Correct |
2371 ms |
229128 KB |
Output is correct |
93 |
Correct |
2936 ms |
243496 KB |
Output is correct |