Submission #884726

# Submission time Handle Problem Language Result Execution time Memory
884726 2023-12-08T09:04:29 Z 406 Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
456 ms 21172 KB
#pragma GCC optimize ("O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ar4 = array<int, 4>;
using ar3 = array<int, 3>;
const int M = 1e5 + 5, N = 1002, Q = 1e6 + 5;
const long long INF = 1e9 + 2;
int n, m;
ar4 E[M];
vector<ar4> bk;
inline namespace dsu {
        short dpr[N];
        void init() {
                memset(dpr, -1, sizeof dpr);
        }
        int gpr(int x) {
                return dpr[x] < 0 ? x : dpr[x] = gpr(dpr[x]);
        }
        bool merge(int u, int v) {
                u = gpr(u), v = gpr(v);
                if (u == v) return false;
                if (dpr[u] < dpr[v]) swap(u, v);
                dpr[v] += dpr[u];
                dpr[u] = v;
                return true;
        }
}

int validate(vector<ar4> &E) {
        dsu::init();
        for (int i = (int) E.size() - 1; ~i; --i) {
                auto [w, u, v, id] = E[i];
                if (!dsu::merge(u, v)) {
                        E.erase(E.begin() + i);
                        return id;
                }
        }
        return -1;
}
int R[M], L[M];

signed main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr); 
        cin >> n >> m;
        vector<ar3> V;
        FOR(i, 0, m) {
                cin >> E[i][1] >> E[i][2] >> E[i][0];
                --E[i][1], --E[i][2];
                if (E[i][1] > E[i][2]) swap(E[i][1], E[i][2]);
                V.push_back({E[i][0], E[i][0] * -2, 2});
        }
        sort(E, E + m);
        FOR(i, 0, m) E[i][3] = i;
        FOR(i, 0, m) {
                auto &[w, u, v, id1] = E[i];
                bk.insert(lower_bound(bk.begin(), bk.end(), E[i]), E[i]);
                int id = validate(bk);
                if (id == -1) L[i] = -INF;
                else {
                        L[i] = (w + E[id][0] + 1) / 2;
                        R[id] = (w + E[id][0] + 1) / 2;
                        V.push_back({R[id], E[id][0], -1});
                }
                V.push_back({L[i], E[i][0], -1});
        }
        sort(V.rbegin(), V.rend());
        long long q, S = 0, td = 0; cin >> q;
        FOR(i, 0, q) {
                int x; cin >> x;
                while (V.size() && V.back()[0] <= x) {
                        auto a = V.back();
                        V.pop_back();
                        S += a[1];
                        td += a[2];
                }
                cout << S + x * td << '\n';
        }
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 276 ms 9344 KB Output is correct
21 Correct 154 ms 10688 KB Output is correct
22 Correct 167 ms 10744 KB Output is correct
23 Correct 175 ms 10352 KB Output is correct
24 Correct 219 ms 9664 KB Output is correct
25 Correct 263 ms 11472 KB Output is correct
26 Correct 272 ms 9608 KB Output is correct
27 Correct 279 ms 9944 KB Output is correct
28 Correct 273 ms 10168 KB Output is correct
29 Correct 142 ms 10176 KB Output is correct
30 Correct 278 ms 10100 KB Output is correct
31 Correct 279 ms 9404 KB Output is correct
32 Correct 280 ms 9336 KB Output is correct
33 Correct 278 ms 9320 KB Output is correct
34 Correct 153 ms 9224 KB Output is correct
35 Correct 277 ms 10828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 320 ms 17280 KB Output is correct
5 Correct 321 ms 18260 KB Output is correct
6 Correct 322 ms 18100 KB Output is correct
7 Correct 235 ms 21172 KB Output is correct
8 Correct 220 ms 20240 KB Output is correct
9 Correct 220 ms 19896 KB Output is correct
10 Correct 311 ms 18360 KB Output is correct
11 Correct 209 ms 19560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 149 ms 14856 KB Output is correct
21 Correct 144 ms 14928 KB Output is correct
22 Correct 153 ms 14848 KB Output is correct
23 Correct 146 ms 14848 KB Output is correct
24 Correct 145 ms 14652 KB Output is correct
25 Correct 143 ms 14672 KB Output is correct
26 Correct 147 ms 14676 KB Output is correct
27 Correct 159 ms 14844 KB Output is correct
28 Correct 150 ms 14944 KB Output is correct
29 Correct 146 ms 15036 KB Output is correct
30 Correct 144 ms 14676 KB Output is correct
31 Correct 143 ms 14672 KB Output is correct
32 Correct 142 ms 15348 KB Output is correct
33 Correct 146 ms 14404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 276 ms 9344 KB Output is correct
21 Correct 154 ms 10688 KB Output is correct
22 Correct 167 ms 10744 KB Output is correct
23 Correct 175 ms 10352 KB Output is correct
24 Correct 219 ms 9664 KB Output is correct
25 Correct 263 ms 11472 KB Output is correct
26 Correct 272 ms 9608 KB Output is correct
27 Correct 279 ms 9944 KB Output is correct
28 Correct 273 ms 10168 KB Output is correct
29 Correct 142 ms 10176 KB Output is correct
30 Correct 278 ms 10100 KB Output is correct
31 Correct 279 ms 9404 KB Output is correct
32 Correct 280 ms 9336 KB Output is correct
33 Correct 278 ms 9320 KB Output is correct
34 Correct 153 ms 9224 KB Output is correct
35 Correct 277 ms 10828 KB Output is correct
36 Correct 281 ms 10056 KB Output is correct
37 Correct 162 ms 10432 KB Output is correct
38 Correct 169 ms 9660 KB Output is correct
39 Correct 184 ms 10600 KB Output is correct
40 Correct 232 ms 10172 KB Output is correct
41 Correct 266 ms 10528 KB Output is correct
42 Correct 286 ms 9840 KB Output is correct
43 Correct 280 ms 10152 KB Output is correct
44 Correct 284 ms 10124 KB Output is correct
45 Correct 145 ms 9144 KB Output is correct
46 Correct 279 ms 10428 KB Output is correct
47 Correct 292 ms 10404 KB Output is correct
48 Correct 278 ms 9916 KB Output is correct
49 Correct 282 ms 11196 KB Output is correct
50 Correct 165 ms 10284 KB Output is correct
51 Correct 294 ms 10596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 276 ms 9344 KB Output is correct
21 Correct 154 ms 10688 KB Output is correct
22 Correct 167 ms 10744 KB Output is correct
23 Correct 175 ms 10352 KB Output is correct
24 Correct 219 ms 9664 KB Output is correct
25 Correct 263 ms 11472 KB Output is correct
26 Correct 272 ms 9608 KB Output is correct
27 Correct 279 ms 9944 KB Output is correct
28 Correct 273 ms 10168 KB Output is correct
29 Correct 142 ms 10176 KB Output is correct
30 Correct 278 ms 10100 KB Output is correct
31 Correct 279 ms 9404 KB Output is correct
32 Correct 280 ms 9336 KB Output is correct
33 Correct 278 ms 9320 KB Output is correct
34 Correct 153 ms 9224 KB Output is correct
35 Correct 277 ms 10828 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 320 ms 17280 KB Output is correct
40 Correct 321 ms 18260 KB Output is correct
41 Correct 322 ms 18100 KB Output is correct
42 Correct 235 ms 21172 KB Output is correct
43 Correct 220 ms 20240 KB Output is correct
44 Correct 220 ms 19896 KB Output is correct
45 Correct 311 ms 18360 KB Output is correct
46 Correct 209 ms 19560 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 149 ms 14856 KB Output is correct
49 Correct 144 ms 14928 KB Output is correct
50 Correct 153 ms 14848 KB Output is correct
51 Correct 146 ms 14848 KB Output is correct
52 Correct 145 ms 14652 KB Output is correct
53 Correct 143 ms 14672 KB Output is correct
54 Correct 147 ms 14676 KB Output is correct
55 Correct 159 ms 14844 KB Output is correct
56 Correct 150 ms 14944 KB Output is correct
57 Correct 146 ms 15036 KB Output is correct
58 Correct 144 ms 14676 KB Output is correct
59 Correct 143 ms 14672 KB Output is correct
60 Correct 142 ms 15348 KB Output is correct
61 Correct 146 ms 14404 KB Output is correct
62 Correct 281 ms 10056 KB Output is correct
63 Correct 162 ms 10432 KB Output is correct
64 Correct 169 ms 9660 KB Output is correct
65 Correct 184 ms 10600 KB Output is correct
66 Correct 232 ms 10172 KB Output is correct
67 Correct 266 ms 10528 KB Output is correct
68 Correct 286 ms 9840 KB Output is correct
69 Correct 280 ms 10152 KB Output is correct
70 Correct 284 ms 10124 KB Output is correct
71 Correct 145 ms 9144 KB Output is correct
72 Correct 279 ms 10428 KB Output is correct
73 Correct 292 ms 10404 KB Output is correct
74 Correct 278 ms 9916 KB Output is correct
75 Correct 282 ms 11196 KB Output is correct
76 Correct 165 ms 10284 KB Output is correct
77 Correct 294 ms 10596 KB Output is correct
78 Correct 423 ms 17100 KB Output is correct
79 Correct 310 ms 20360 KB Output is correct
80 Correct 307 ms 18404 KB Output is correct
81 Correct 326 ms 19188 KB Output is correct
82 Correct 372 ms 16652 KB Output is correct
83 Correct 412 ms 17976 KB Output is correct
84 Correct 456 ms 16804 KB Output is correct
85 Correct 420 ms 17288 KB Output is correct
86 Correct 411 ms 17076 KB Output is correct
87 Correct 299 ms 20388 KB Output is correct
88 Correct 421 ms 18424 KB Output is correct
89 Correct 417 ms 17500 KB Output is correct
90 Correct 417 ms 18248 KB Output is correct
91 Correct 427 ms 16584 KB Output is correct
92 Correct 303 ms 19380 KB Output is correct
93 Correct 411 ms 17824 KB Output is correct