답안 #674063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674063 2022-12-22T20:15:48 Z doowey Reconstruction Project (JOI22_reconstruction) C++14
100 / 100
2482 ms 37416 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 510;

struct segm{
    ll pos;
    ll coeff;
    ll add;
    bool operator< (const segm &pq){
        return pos < pq.pos;
    }
};

struct edge{
    int ui;
    int vi;
    ll weight;
    bool operator< (const edge &E) {
        return weight < E.weight;
    }
};

int par[N];

int fin(int u){
    if(par[u] == u) return u;
    return par[u]=fin(par[u]);
}

bool unite(int u, int v){
    u=fin(u);
    v=fin(v);
    if(u==v) return false;
    par[u]=v;
    return true;
}

int main(){
    fastIO;
    //freopen("in.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vector<edge> E;
    int u, v;
    ll w;
    for(int i = 0 ; i < m ; i ++ ){
        cin >> u >> v >> w;
        w *= 2;
        E.push_back({u, v, w});
    }
    sort(E.begin(), E.end());
    int li;
    int ri;
    vector<segm> sweep;
    for(int ii = 0 ; ii < m; ii ++ ){
        for(int i = 1; i <= n; i ++ ) par[i] = i;
        li = ii - 1;
        while(li >= 0){
            unite(E[li].ui, E[li].vi);
            if(fin(E[ii].ui) == fin(E[ii].vi)){
                break;
            }
            li -- ;
        }
        for(int i = 1; i <= n; i ++ ) par[i] = i;
        ri = ii + 1;
        while(ri < E.size()){
            unite(E[ri].ui, E[ri].vi);
            if(fin(E[ii].ui) == fin(E[ii].vi)){
                break;
            }
            ri ++ ;
        }
        if(li < 0){
            sweep.push_back({0, -1, +E[ii].weight});
            sweep.push_back({E[ii].weight, +1, -E[ii].weight});
        }
        else{
            sweep.push_back({(E[ii].weight + E[li].weight) / 2ll, -1, +E[ii].weight});
            sweep.push_back({E[ii].weight, +1, -E[ii].weight});
        }
        if(ri == E.size()){
            sweep.push_back({E[ii].weight, +1, -E[ii].weight});
        }
        else{
            sweep.push_back({E[ii].weight, +1, -E[ii].weight});
            sweep.push_back({(E[ii].weight + E[ri].weight) / 2ll, -1, +E[ii].weight});
        }
    }
    sort(sweep.begin(), sweep.end());
    int id = 0;
    ll coeff = 0ll;
    ll add = 0;
    int q;
    cin >> q;
    ll xi;
    for(int iq = 1; iq <= q; iq ++ ){
        cin >> xi;
        xi *= 2ll;
        while(id < sweep.size() && sweep[id].pos <= xi){
            coeff += sweep[id].coeff;
            add += sweep[id].add;
            id ++ ;
        }
        cout << (xi * 1ll * coeff + add) / 2ll << "\n";
    }
    return 0;
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         while(ri < E.size()){
      |               ~~~^~~~~~~~~~
reconstruction.cpp:92:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         if(ri == E.size()){
      |            ~~~^~~~~~~~~~~
reconstruction.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<segm>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         while(id < sweep.size() && sweep[id].pos <= xi){
      |               ~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2203 ms 17428 KB Output is correct
21 Correct 1257 ms 17388 KB Output is correct
22 Correct 1392 ms 17420 KB Output is correct
23 Correct 1579 ms 17364 KB Output is correct
24 Correct 1965 ms 17660 KB Output is correct
25 Correct 2277 ms 17388 KB Output is correct
26 Correct 2209 ms 17484 KB Output is correct
27 Correct 2202 ms 17364 KB Output is correct
28 Correct 2206 ms 17488 KB Output is correct
29 Correct 2191 ms 17456 KB Output is correct
30 Correct 2250 ms 17624 KB Output is correct
31 Correct 2202 ms 17516 KB Output is correct
32 Correct 2208 ms 17460 KB Output is correct
33 Correct 2203 ms 17500 KB Output is correct
34 Correct 2186 ms 17484 KB Output is correct
35 Correct 2215 ms 17396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1496 ms 35348 KB Output is correct
5 Correct 1501 ms 35244 KB Output is correct
6 Correct 1513 ms 35324 KB Output is correct
7 Correct 826 ms 37068 KB Output is correct
8 Correct 707 ms 37156 KB Output is correct
9 Correct 578 ms 37308 KB Output is correct
10 Correct 1495 ms 35484 KB Output is correct
11 Correct 696 ms 37416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 200 ms 22356 KB Output is correct
21 Correct 199 ms 22552 KB Output is correct
22 Correct 206 ms 22420 KB Output is correct
23 Correct 205 ms 22416 KB Output is correct
24 Correct 203 ms 22484 KB Output is correct
25 Correct 206 ms 22468 KB Output is correct
26 Correct 197 ms 22476 KB Output is correct
27 Correct 202 ms 22388 KB Output is correct
28 Correct 200 ms 22428 KB Output is correct
29 Correct 203 ms 22340 KB Output is correct
30 Correct 198 ms 22484 KB Output is correct
31 Correct 206 ms 22476 KB Output is correct
32 Correct 206 ms 23116 KB Output is correct
33 Correct 199 ms 22268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2203 ms 17428 KB Output is correct
21 Correct 1257 ms 17388 KB Output is correct
22 Correct 1392 ms 17420 KB Output is correct
23 Correct 1579 ms 17364 KB Output is correct
24 Correct 1965 ms 17660 KB Output is correct
25 Correct 2277 ms 17388 KB Output is correct
26 Correct 2209 ms 17484 KB Output is correct
27 Correct 2202 ms 17364 KB Output is correct
28 Correct 2206 ms 17488 KB Output is correct
29 Correct 2191 ms 17456 KB Output is correct
30 Correct 2250 ms 17624 KB Output is correct
31 Correct 2202 ms 17516 KB Output is correct
32 Correct 2208 ms 17460 KB Output is correct
33 Correct 2203 ms 17500 KB Output is correct
34 Correct 2186 ms 17484 KB Output is correct
35 Correct 2215 ms 17396 KB Output is correct
36 Correct 2210 ms 17844 KB Output is correct
37 Correct 1271 ms 17584 KB Output is correct
38 Correct 1378 ms 17584 KB Output is correct
39 Correct 1588 ms 17852 KB Output is correct
40 Correct 1977 ms 17812 KB Output is correct
41 Correct 2310 ms 17728 KB Output is correct
42 Correct 2239 ms 17656 KB Output is correct
43 Correct 2215 ms 17772 KB Output is correct
44 Correct 2195 ms 17720 KB Output is correct
45 Correct 2200 ms 17736 KB Output is correct
46 Correct 2236 ms 17616 KB Output is correct
47 Correct 2196 ms 17560 KB Output is correct
48 Correct 2196 ms 17676 KB Output is correct
49 Correct 2201 ms 17724 KB Output is correct
50 Correct 2170 ms 17832 KB Output is correct
51 Correct 2207 ms 17948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2203 ms 17428 KB Output is correct
21 Correct 1257 ms 17388 KB Output is correct
22 Correct 1392 ms 17420 KB Output is correct
23 Correct 1579 ms 17364 KB Output is correct
24 Correct 1965 ms 17660 KB Output is correct
25 Correct 2277 ms 17388 KB Output is correct
26 Correct 2209 ms 17484 KB Output is correct
27 Correct 2202 ms 17364 KB Output is correct
28 Correct 2206 ms 17488 KB Output is correct
29 Correct 2191 ms 17456 KB Output is correct
30 Correct 2250 ms 17624 KB Output is correct
31 Correct 2202 ms 17516 KB Output is correct
32 Correct 2208 ms 17460 KB Output is correct
33 Correct 2203 ms 17500 KB Output is correct
34 Correct 2186 ms 17484 KB Output is correct
35 Correct 2215 ms 17396 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1496 ms 35348 KB Output is correct
40 Correct 1501 ms 35244 KB Output is correct
41 Correct 1513 ms 35324 KB Output is correct
42 Correct 826 ms 37068 KB Output is correct
43 Correct 707 ms 37156 KB Output is correct
44 Correct 578 ms 37308 KB Output is correct
45 Correct 1495 ms 35484 KB Output is correct
46 Correct 696 ms 37416 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 200 ms 22356 KB Output is correct
49 Correct 199 ms 22552 KB Output is correct
50 Correct 206 ms 22420 KB Output is correct
51 Correct 205 ms 22416 KB Output is correct
52 Correct 203 ms 22484 KB Output is correct
53 Correct 206 ms 22468 KB Output is correct
54 Correct 197 ms 22476 KB Output is correct
55 Correct 202 ms 22388 KB Output is correct
56 Correct 200 ms 22428 KB Output is correct
57 Correct 203 ms 22340 KB Output is correct
58 Correct 198 ms 22484 KB Output is correct
59 Correct 206 ms 22476 KB Output is correct
60 Correct 206 ms 23116 KB Output is correct
61 Correct 199 ms 22268 KB Output is correct
62 Correct 2210 ms 17844 KB Output is correct
63 Correct 1271 ms 17584 KB Output is correct
64 Correct 1378 ms 17584 KB Output is correct
65 Correct 1588 ms 17852 KB Output is correct
66 Correct 1977 ms 17812 KB Output is correct
67 Correct 2310 ms 17728 KB Output is correct
68 Correct 2239 ms 17656 KB Output is correct
69 Correct 2215 ms 17772 KB Output is correct
70 Correct 2195 ms 17720 KB Output is correct
71 Correct 2200 ms 17736 KB Output is correct
72 Correct 2236 ms 17616 KB Output is correct
73 Correct 2196 ms 17560 KB Output is correct
74 Correct 2196 ms 17676 KB Output is correct
75 Correct 2201 ms 17724 KB Output is correct
76 Correct 2170 ms 17832 KB Output is correct
77 Correct 2207 ms 17948 KB Output is correct
78 Correct 2394 ms 34184 KB Output is correct
79 Correct 1430 ms 36192 KB Output is correct
80 Correct 1537 ms 35192 KB Output is correct
81 Correct 1750 ms 35496 KB Output is correct
82 Correct 2136 ms 34392 KB Output is correct
83 Correct 2482 ms 34188 KB Output is correct
84 Correct 2383 ms 34324 KB Output is correct
85 Correct 2378 ms 34424 KB Output is correct
86 Correct 2359 ms 34316 KB Output is correct
87 Correct 2353 ms 35848 KB Output is correct
88 Correct 2361 ms 34364 KB Output is correct
89 Correct 2360 ms 34260 KB Output is correct
90 Correct 2355 ms 34436 KB Output is correct
91 Correct 2377 ms 34184 KB Output is correct
92 Correct 2348 ms 37244 KB Output is correct
93 Correct 2379 ms 35368 KB Output is correct