답안 #1033928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033928 2024-07-25T07:48:58 Z Alish Reconstruction Project (JOI22_reconstruction) C++14
100 / 100
1239 ms 53596 KB
#include <bits/stdc++.h>

using namespace std;

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


#define F		        first
#define S		        second
#define pb		        push_back
#define endl            '\n'
#define Mp              make_pair
#define all(x)          x.begin(), x.end()
#define debug(x)        cerr << #x << " = " << x << endl;
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("tests.in" , "r" , stdin) ;

ll mod = 1e9+7;


const int N = 523, M=1e5+23, QQ=1e6+23;

int sz[N], par[N];
int L[M], R[M];
ll pref[QQ], small[QQ];
vector<ll> Q;
vector<pair<ll, pll> > E;
int n, m, q;


int getPar(int v){
    if(par[v]==-1) return v;
    return par[v]=getPar(par[v]);
}

bool Union(int u, int v){
    u=getPar(u);
    v=getPar(v);
    if(v==u) return 0;
    if(sz[v]<sz[u]) swap(u, v);
    par[u]=v;
    sz[v]+=sz[u];
    return 1;
}

int main()
{
    fast_io
    cin>>n>>m;
    for (int i=0; i<m; i++){
        int v, u, w;
        cin>>v>>u>>w;
        E.pb({w, {v, u}});
    }
    sort(all(E));
    cin>>q;
    for (int i=0; i<q; i++){
        int x; cin>>x;
        Q.pb(x);
    }

    for (int i=0; i<m; i++){
        int v=E[i].S.F, u=E[i].S.S;
        for (int j=1; j<=n; j++){
            par[j]=-1;
            sz[j]=1;
        }
        L[i]=-1;
        R[i]=m;
        for (int j=i-1; j>=0; j--)if(Union(E[j].S.F, E[j].S.S) && getPar(u)==getPar(v)){
            L[i]=j;
            break;
        }
        for (int j=1; j<=n; j++){
            par[j]=-1;
            sz[j]=1;
        }
        for (int j=i+1; j<m; j++)if(Union(E[j].S.F, E[j].S.S) && getPar(u)==getPar(v)){
            R[i]=j;
            break;
        }

    }

    for (int i=0; i<m; i++){
        int l=0, mid, r=q;
        if(L[i]!=-1) l=lower_bound(all(Q), (E[i].F+E[L[i]].F+1)/2)-Q.begin();
        pref[l]+=E[i].F;
        small[l]--;
        mid=lower_bound(all(Q), E[i].F)-Q.begin();
        pref[mid]-=2*E[i].F;
        small[mid]+=2;
        if(R[i]!=m) r=lower_bound(all(Q), (E[i].F+E[R[i]].F+1)/2)-Q.begin();
        pref[r]+=E[i].F;
        small[r]--;
    }
    for (int i=1; i<q; i++){
        pref[i]+=pref[i-1];
        small[i]+=small[i-1];
    }
    for (int i=0; i<q; i++) cout<<pref[i]+Q[i]*small[i]<<endl;

}
/*


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1020 ms 5448 KB Output is correct
21 Correct 777 ms 5260 KB Output is correct
22 Correct 849 ms 5420 KB Output is correct
23 Correct 897 ms 5304 KB Output is correct
24 Correct 1063 ms 5564 KB Output is correct
25 Correct 987 ms 5232 KB Output is correct
26 Correct 953 ms 5312 KB Output is correct
27 Correct 990 ms 5316 KB Output is correct
28 Correct 938 ms 5236 KB Output is correct
29 Correct 587 ms 5308 KB Output is correct
30 Correct 1002 ms 5400 KB Output is correct
31 Correct 1068 ms 5284 KB Output is correct
32 Correct 1091 ms 5568 KB Output is correct
33 Correct 1057 ms 5456 KB Output is correct
34 Correct 469 ms 5312 KB Output is correct
35 Correct 1109 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1129 ms 51408 KB Output is correct
5 Correct 1120 ms 51376 KB Output is correct
6 Correct 1182 ms 51384 KB Output is correct
7 Correct 632 ms 53280 KB Output is correct
8 Correct 475 ms 53472 KB Output is correct
9 Correct 455 ms 53512 KB Output is correct
10 Correct 1063 ms 51524 KB Output is correct
11 Correct 537 ms 53596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 142 ms 46012 KB Output is correct
21 Correct 149 ms 45972 KB Output is correct
22 Correct 143 ms 46012 KB Output is correct
23 Correct 156 ms 46020 KB Output is correct
24 Correct 140 ms 45884 KB Output is correct
25 Correct 140 ms 45988 KB Output is correct
26 Correct 144 ms 46008 KB Output is correct
27 Correct 144 ms 46128 KB Output is correct
28 Correct 165 ms 45880 KB Output is correct
29 Correct 144 ms 46020 KB Output is correct
30 Correct 139 ms 46012 KB Output is correct
31 Correct 142 ms 45752 KB Output is correct
32 Correct 147 ms 46528 KB Output is correct
33 Correct 144 ms 45756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1020 ms 5448 KB Output is correct
21 Correct 777 ms 5260 KB Output is correct
22 Correct 849 ms 5420 KB Output is correct
23 Correct 897 ms 5304 KB Output is correct
24 Correct 1063 ms 5564 KB Output is correct
25 Correct 987 ms 5232 KB Output is correct
26 Correct 953 ms 5312 KB Output is correct
27 Correct 990 ms 5316 KB Output is correct
28 Correct 938 ms 5236 KB Output is correct
29 Correct 587 ms 5308 KB Output is correct
30 Correct 1002 ms 5400 KB Output is correct
31 Correct 1068 ms 5284 KB Output is correct
32 Correct 1091 ms 5568 KB Output is correct
33 Correct 1057 ms 5456 KB Output is correct
34 Correct 469 ms 5312 KB Output is correct
35 Correct 1109 ms 5240 KB Output is correct
36 Correct 1074 ms 6364 KB Output is correct
37 Correct 799 ms 6336 KB Output is correct
38 Correct 843 ms 6412 KB Output is correct
39 Correct 968 ms 6328 KB Output is correct
40 Correct 1055 ms 6332 KB Output is correct
41 Correct 1006 ms 6332 KB Output is correct
42 Correct 1028 ms 6368 KB Output is correct
43 Correct 982 ms 6436 KB Output is correct
44 Correct 1018 ms 6380 KB Output is correct
45 Correct 591 ms 6340 KB Output is correct
46 Correct 1046 ms 6352 KB Output is correct
47 Correct 1031 ms 6328 KB Output is correct
48 Correct 1000 ms 6356 KB Output is correct
49 Correct 1066 ms 6468 KB Output is correct
50 Correct 414 ms 6360 KB Output is correct
51 Correct 1030 ms 6256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1020 ms 5448 KB Output is correct
21 Correct 777 ms 5260 KB Output is correct
22 Correct 849 ms 5420 KB Output is correct
23 Correct 897 ms 5304 KB Output is correct
24 Correct 1063 ms 5564 KB Output is correct
25 Correct 987 ms 5232 KB Output is correct
26 Correct 953 ms 5312 KB Output is correct
27 Correct 990 ms 5316 KB Output is correct
28 Correct 938 ms 5236 KB Output is correct
29 Correct 587 ms 5308 KB Output is correct
30 Correct 1002 ms 5400 KB Output is correct
31 Correct 1068 ms 5284 KB Output is correct
32 Correct 1091 ms 5568 KB Output is correct
33 Correct 1057 ms 5456 KB Output is correct
34 Correct 469 ms 5312 KB Output is correct
35 Correct 1109 ms 5240 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1129 ms 51408 KB Output is correct
40 Correct 1120 ms 51376 KB Output is correct
41 Correct 1182 ms 51384 KB Output is correct
42 Correct 632 ms 53280 KB Output is correct
43 Correct 475 ms 53472 KB Output is correct
44 Correct 455 ms 53512 KB Output is correct
45 Correct 1063 ms 51524 KB Output is correct
46 Correct 537 ms 53596 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 142 ms 46012 KB Output is correct
49 Correct 149 ms 45972 KB Output is correct
50 Correct 143 ms 46012 KB Output is correct
51 Correct 156 ms 46020 KB Output is correct
52 Correct 140 ms 45884 KB Output is correct
53 Correct 140 ms 45988 KB Output is correct
54 Correct 144 ms 46008 KB Output is correct
55 Correct 144 ms 46128 KB Output is correct
56 Correct 165 ms 45880 KB Output is correct
57 Correct 144 ms 46020 KB Output is correct
58 Correct 139 ms 46012 KB Output is correct
59 Correct 142 ms 45752 KB Output is correct
60 Correct 147 ms 46528 KB Output is correct
61 Correct 144 ms 45756 KB Output is correct
62 Correct 1074 ms 6364 KB Output is correct
63 Correct 799 ms 6336 KB Output is correct
64 Correct 843 ms 6412 KB Output is correct
65 Correct 968 ms 6328 KB Output is correct
66 Correct 1055 ms 6332 KB Output is correct
67 Correct 1006 ms 6332 KB Output is correct
68 Correct 1028 ms 6368 KB Output is correct
69 Correct 982 ms 6436 KB Output is correct
70 Correct 1018 ms 6380 KB Output is correct
71 Correct 591 ms 6340 KB Output is correct
72 Correct 1046 ms 6352 KB Output is correct
73 Correct 1031 ms 6328 KB Output is correct
74 Correct 1000 ms 6356 KB Output is correct
75 Correct 1066 ms 6468 KB Output is correct
76 Correct 414 ms 6360 KB Output is correct
77 Correct 1030 ms 6256 KB Output is correct
78 Correct 1192 ms 50344 KB Output is correct
79 Correct 859 ms 52360 KB Output is correct
80 Correct 971 ms 51456 KB Output is correct
81 Correct 1084 ms 51532 KB Output is correct
82 Correct 1127 ms 50604 KB Output is correct
83 Correct 1158 ms 50408 KB Output is correct
84 Correct 1166 ms 50544 KB Output is correct
85 Correct 1146 ms 50408 KB Output is correct
86 Correct 1108 ms 50600 KB Output is correct
87 Correct 665 ms 52392 KB Output is correct
88 Correct 1133 ms 50320 KB Output is correct
89 Correct 1239 ms 50336 KB Output is correct
90 Correct 1162 ms 50604 KB Output is correct
91 Correct 1157 ms 50340 KB Output is correct
92 Correct 578 ms 53344 KB Output is correct
93 Correct 1114 ms 51624 KB Output is correct