#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] == 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);
for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) p[j][i] = i;
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];
}
for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) p[j][i] = i;
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: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 (ptr1 < sum.size() && sum[ptr1].first <= x) s += sum[ptr1++].second;
| ~~~~~^~~~~~~~~~~~
reconstruction.cpp:85: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]
85 | while (ptr2 < mul.size() && mul[ptr2].first <= x) m += mul[ptr2++].second;
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
3121 ms |
218680 KB |
Output is correct |
21 |
Correct |
4431 ms |
218708 KB |
Output is correct |
22 |
Correct |
4950 ms |
218628 KB |
Output is correct |
23 |
Correct |
3134 ms |
220348 KB |
Output is correct |
24 |
Correct |
2933 ms |
220420 KB |
Output is correct |
25 |
Correct |
3382 ms |
220336 KB |
Output is correct |
26 |
Correct |
3073 ms |
220560 KB |
Output is correct |
27 |
Correct |
3182 ms |
220480 KB |
Output is correct |
28 |
Correct |
2827 ms |
220376 KB |
Output is correct |
29 |
Correct |
3254 ms |
205584 KB |
Output is correct |
30 |
Correct |
3069 ms |
220260 KB |
Output is correct |
31 |
Correct |
3101 ms |
220312 KB |
Output is correct |
32 |
Correct |
3118 ms |
220312 KB |
Output is correct |
33 |
Correct |
3118 ms |
220256 KB |
Output is correct |
34 |
Correct |
2815 ms |
204704 KB |
Output is correct |
35 |
Correct |
3006 ms |
220448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1936 ms |
229920 KB |
Output is correct |
5 |
Correct |
2058 ms |
229660 KB |
Output is correct |
6 |
Correct |
1875 ms |
229644 KB |
Output is correct |
7 |
Correct |
2137 ms |
231680 KB |
Output is correct |
8 |
Correct |
2172 ms |
232128 KB |
Output is correct |
9 |
Correct |
2092 ms |
231676 KB |
Output is correct |
10 |
Correct |
1875 ms |
229688 KB |
Output is correct |
11 |
Correct |
2194 ms |
231628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
196 ms |
14752 KB |
Output is correct |
21 |
Correct |
191 ms |
14860 KB |
Output is correct |
22 |
Correct |
201 ms |
14852 KB |
Output is correct |
23 |
Correct |
205 ms |
14812 KB |
Output is correct |
24 |
Correct |
194 ms |
14756 KB |
Output is correct |
25 |
Correct |
195 ms |
15068 KB |
Output is correct |
26 |
Correct |
203 ms |
14768 KB |
Output is correct |
27 |
Correct |
199 ms |
14832 KB |
Output is correct |
28 |
Correct |
201 ms |
14848 KB |
Output is correct |
29 |
Correct |
195 ms |
14812 KB |
Output is correct |
30 |
Correct |
210 ms |
14800 KB |
Output is correct |
31 |
Correct |
213 ms |
14752 KB |
Output is correct |
32 |
Correct |
194 ms |
15288 KB |
Output is correct |
33 |
Correct |
194 ms |
14592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
3121 ms |
218680 KB |
Output is correct |
21 |
Correct |
4431 ms |
218708 KB |
Output is correct |
22 |
Correct |
4950 ms |
218628 KB |
Output is correct |
23 |
Correct |
3134 ms |
220348 KB |
Output is correct |
24 |
Correct |
2933 ms |
220420 KB |
Output is correct |
25 |
Correct |
3382 ms |
220336 KB |
Output is correct |
26 |
Correct |
3073 ms |
220560 KB |
Output is correct |
27 |
Correct |
3182 ms |
220480 KB |
Output is correct |
28 |
Correct |
2827 ms |
220376 KB |
Output is correct |
29 |
Correct |
3254 ms |
205584 KB |
Output is correct |
30 |
Correct |
3069 ms |
220260 KB |
Output is correct |
31 |
Correct |
3101 ms |
220312 KB |
Output is correct |
32 |
Correct |
3118 ms |
220312 KB |
Output is correct |
33 |
Correct |
3118 ms |
220256 KB |
Output is correct |
34 |
Correct |
2815 ms |
204704 KB |
Output is correct |
35 |
Correct |
3006 ms |
220448 KB |
Output is correct |
36 |
Correct |
3043 ms |
220752 KB |
Output is correct |
37 |
Correct |
4327 ms |
220684 KB |
Output is correct |
38 |
Correct |
4679 ms |
220708 KB |
Output is correct |
39 |
Correct |
2776 ms |
220676 KB |
Output is correct |
40 |
Correct |
2765 ms |
220724 KB |
Output is correct |
41 |
Correct |
3237 ms |
220808 KB |
Output is correct |
42 |
Correct |
3005 ms |
220636 KB |
Output is correct |
43 |
Correct |
2993 ms |
220892 KB |
Output is correct |
44 |
Correct |
2787 ms |
220708 KB |
Output is correct |
45 |
Correct |
3161 ms |
205976 KB |
Output is correct |
46 |
Correct |
3022 ms |
220840 KB |
Output is correct |
47 |
Correct |
3029 ms |
220736 KB |
Output is correct |
48 |
Correct |
2961 ms |
220732 KB |
Output is correct |
49 |
Correct |
2941 ms |
220724 KB |
Output is correct |
50 |
Correct |
2726 ms |
205092 KB |
Output is correct |
51 |
Correct |
2951 ms |
220840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
3121 ms |
218680 KB |
Output is correct |
21 |
Correct |
4431 ms |
218708 KB |
Output is correct |
22 |
Correct |
4950 ms |
218628 KB |
Output is correct |
23 |
Correct |
3134 ms |
220348 KB |
Output is correct |
24 |
Correct |
2933 ms |
220420 KB |
Output is correct |
25 |
Correct |
3382 ms |
220336 KB |
Output is correct |
26 |
Correct |
3073 ms |
220560 KB |
Output is correct |
27 |
Correct |
3182 ms |
220480 KB |
Output is correct |
28 |
Correct |
2827 ms |
220376 KB |
Output is correct |
29 |
Correct |
3254 ms |
205584 KB |
Output is correct |
30 |
Correct |
3069 ms |
220260 KB |
Output is correct |
31 |
Correct |
3101 ms |
220312 KB |
Output is correct |
32 |
Correct |
3118 ms |
220312 KB |
Output is correct |
33 |
Correct |
3118 ms |
220256 KB |
Output is correct |
34 |
Correct |
2815 ms |
204704 KB |
Output is correct |
35 |
Correct |
3006 ms |
220448 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1936 ms |
229920 KB |
Output is correct |
40 |
Correct |
2058 ms |
229660 KB |
Output is correct |
41 |
Correct |
1875 ms |
229644 KB |
Output is correct |
42 |
Correct |
2137 ms |
231680 KB |
Output is correct |
43 |
Correct |
2172 ms |
232128 KB |
Output is correct |
44 |
Correct |
2092 ms |
231676 KB |
Output is correct |
45 |
Correct |
1875 ms |
229688 KB |
Output is correct |
46 |
Correct |
2194 ms |
231628 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
196 ms |
14752 KB |
Output is correct |
49 |
Correct |
191 ms |
14860 KB |
Output is correct |
50 |
Correct |
201 ms |
14852 KB |
Output is correct |
51 |
Correct |
205 ms |
14812 KB |
Output is correct |
52 |
Correct |
194 ms |
14756 KB |
Output is correct |
53 |
Correct |
195 ms |
15068 KB |
Output is correct |
54 |
Correct |
203 ms |
14768 KB |
Output is correct |
55 |
Correct |
199 ms |
14832 KB |
Output is correct |
56 |
Correct |
201 ms |
14848 KB |
Output is correct |
57 |
Correct |
195 ms |
14812 KB |
Output is correct |
58 |
Correct |
210 ms |
14800 KB |
Output is correct |
59 |
Correct |
213 ms |
14752 KB |
Output is correct |
60 |
Correct |
194 ms |
15288 KB |
Output is correct |
61 |
Correct |
194 ms |
14592 KB |
Output is correct |
62 |
Correct |
3043 ms |
220752 KB |
Output is correct |
63 |
Correct |
4327 ms |
220684 KB |
Output is correct |
64 |
Correct |
4679 ms |
220708 KB |
Output is correct |
65 |
Correct |
2776 ms |
220676 KB |
Output is correct |
66 |
Correct |
2765 ms |
220724 KB |
Output is correct |
67 |
Correct |
3237 ms |
220808 KB |
Output is correct |
68 |
Correct |
3005 ms |
220636 KB |
Output is correct |
69 |
Correct |
2993 ms |
220892 KB |
Output is correct |
70 |
Correct |
2787 ms |
220708 KB |
Output is correct |
71 |
Correct |
3161 ms |
205976 KB |
Output is correct |
72 |
Correct |
3022 ms |
220840 KB |
Output is correct |
73 |
Correct |
3029 ms |
220736 KB |
Output is correct |
74 |
Correct |
2961 ms |
220732 KB |
Output is correct |
75 |
Correct |
2941 ms |
220724 KB |
Output is correct |
76 |
Correct |
2726 ms |
205092 KB |
Output is correct |
77 |
Correct |
2951 ms |
220840 KB |
Output is correct |
78 |
Correct |
3158 ms |
240196 KB |
Output is correct |
79 |
Correct |
4340 ms |
242024 KB |
Output is correct |
80 |
Execution timed out |
5056 ms |
241044 KB |
Time limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |