#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) ((int)x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
typedef pair<int,pair<int,int>> shit;
const int maxn=505,maxm=1e5+99,inf=2e9;
int n,m,q,L[maxm],R[maxm],fenwik[2][maxm];
pair<int,int> par[maxn];
vector<shit> a,b;
vector<pair<int,int>> g[maxn];
void add(int x, int val,int s){ for(x++;x<maxm;x+=x&-x) fenwik[s][x]+=val; }
int get(int x,int s) { int res=0; for (x++;x>0;x-=x&-x) res+=fenwik[s][x]; return res; }
void dfs(int u,int p){
for(auto [v,w] : g[u]){
if(v==p) continue ;
dfs(v,u);
par[v]={u,w};
}
}
vector<int> solve(vector<shit> vec){
f(i,1,n+1) g[i].clear();
vector<int> ans;
int i=0;
for(auto [w,edge] : vec){
fill(par,par+maxn,mp(0,0));
dfs(edge.F,0);
if(par[edge.S].F){
int u=0,v=0,mn=sz(vec);
for(int x=edge.S;x!=edge.F;x=par[x].F){
if(par[x].S<mn){
u=x,v=par[x].F;
mn=par[x].S;;
}
}
f(i,0,g[u].size()) if(g[u][i].F==v){
g[u].erase(g[u].begin()+i);
}
f(i,0,g[v].size()) if(g[v][i].F==u){
g[v].erase(g[v].begin()+i);
}
ans.pb(mn);
}
else{
ans.pb(-1);
}
g[edge.F].pb({edge.S,i});
g[edge.S].pb({edge.F,i});
i++;
}
return ans;
}
int32_t main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n>>m;
f(i,0,m){
int u,v,w;
cin>>u>>v>>w;
a.pb({w,{u,v}});
b.pb({-w,{u,v}});
}
sort(all(a));
sort(all(b));
vector<int> A=solve(a),B=solve(b);
vector<shit> vec;
reverse(all(B));
f(i,0,B.size()) B[i]=m-B[i]-1;
f(i,0,m){
if(A[i]==-1) L[i]=0;
else L[i]=(a[i].F+a[A[i]].F)/2+1;
}
f(i,0,m){
if(B[i]==m) R[i]=inf;
else{
R[i]=(a[B[i]].F+a[i].F)/2+1;
}
vec.pb({L[i],{i,+1}});
vec.pb({R[i],{i,-1}});
}
int sum=0,cnt=0,p=0;
sort(all(vec));
cin>>q;
f(i,0,q){
int x;
cin>>x;
while(p<vec.size() && vec[p].F<=x){
add(vec[p].S.F,vec[p].S.S,0);
add(vec[p].S.F,vec[p].S.S*a[vec[p].S.F].F,1);
p++;
}
int l=-1,r=m;
while(l+1<r){
int mid=(l+r)>>1;
if(a[mid].F<=x) l=mid;
else r=mid;
}
cout<<get(l,0)*x-get(l,1)+(get(m,1)-get(l,1))-x*(get(m,0)-get(l,0))<<'\n';
}
}
Compilation message
reconstruction.cpp: In function 'void dfs(long long int, long long int)':
reconstruction.cpp:37:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | for(auto [v,w] : g[u]){
| ^
reconstruction.cpp: In function 'std::vector<long long int> solve(std::vector<std::pair<long long int, std::pair<long long int, long long int> > >)':
reconstruction.cpp:47:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [w,edge] : vec){
| ^
reconstruction.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
58 | f(i,0,g[u].size()) if(g[u][i].F==v){
| ~~~~~~~~~~~~~~~
reconstruction.cpp:58:4: note: in expansion of macro 'f'
58 | f(i,0,g[u].size()) if(g[u][i].F==v){
| ^
reconstruction.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
61 | f(i,0,g[v].size()) if(g[v][i].F==u){
| ~~~~~~~~~~~~~~~
reconstruction.cpp:61:4: note: in expansion of macro 'f'
61 | f(i,0,g[v].size()) if(g[v][i].F==u){
| ^
reconstruction.cpp: In function 'int32_t main()':
reconstruction.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
89 | f(i,0,B.size()) B[i]=m-B[i]-1;
| ~~~~~~~~~~~~
reconstruction.cpp:89:2: note: in expansion of macro 'f'
89 | f(i,0,B.size()) B[i]=m-B[i]-1;
| ^
reconstruction.cpp:108:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | while(p<vec.size() && vec[p].F<=x){
| ~^~~~~~~~~~~
reconstruction.cpp:102:6: warning: unused variable 'sum' [-Wunused-variable]
102 | int sum=0,cnt=0,p=0;
| ^~~
reconstruction.cpp:102:12: warning: unused variable 'cnt' [-Wunused-variable]
102 | int sum=0,cnt=0,p=0;
| ^~~
# |
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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2350 ms |
19760 KB |
Output is correct |
21 |
Correct |
1231 ms |
18388 KB |
Output is correct |
22 |
Correct |
1984 ms |
18612 KB |
Output is correct |
23 |
Correct |
2208 ms |
18368 KB |
Output is correct |
24 |
Correct |
2281 ms |
18560 KB |
Output is correct |
25 |
Correct |
2305 ms |
18396 KB |
Output is correct |
26 |
Correct |
2345 ms |
19976 KB |
Output is correct |
27 |
Correct |
2457 ms |
19856 KB |
Output is correct |
28 |
Correct |
2580 ms |
19736 KB |
Output is correct |
29 |
Correct |
1269 ms |
19908 KB |
Output is correct |
30 |
Correct |
2505 ms |
19440 KB |
Output is correct |
31 |
Correct |
2536 ms |
19600 KB |
Output is correct |
32 |
Correct |
2480 ms |
19920 KB |
Output is correct |
33 |
Correct |
2501 ms |
17976 KB |
Output is correct |
34 |
Correct |
1174 ms |
21248 KB |
Output is correct |
35 |
Correct |
2562 ms |
19420 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
2193 ms |
39316 KB |
Output is correct |
5 |
Correct |
2205 ms |
40672 KB |
Output is correct |
6 |
Correct |
2175 ms |
40532 KB |
Output is correct |
7 |
Correct |
453 ms |
42512 KB |
Output is correct |
8 |
Correct |
448 ms |
42524 KB |
Output is correct |
9 |
Correct |
460 ms |
42724 KB |
Output is correct |
10 |
Correct |
2115 ms |
40132 KB |
Output is correct |
11 |
Correct |
444 ms |
42616 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
237 ms |
14196 KB |
Output is correct |
21 |
Correct |
227 ms |
14368 KB |
Output is correct |
22 |
Correct |
229 ms |
14280 KB |
Output is correct |
23 |
Correct |
253 ms |
14312 KB |
Output is correct |
24 |
Correct |
237 ms |
14232 KB |
Output is correct |
25 |
Correct |
257 ms |
14304 KB |
Output is correct |
26 |
Correct |
233 ms |
14196 KB |
Output is correct |
27 |
Correct |
227 ms |
14288 KB |
Output is correct |
28 |
Correct |
273 ms |
14184 KB |
Output is correct |
29 |
Correct |
235 ms |
14288 KB |
Output is correct |
30 |
Correct |
234 ms |
14284 KB |
Output is correct |
31 |
Correct |
243 ms |
14240 KB |
Output is correct |
32 |
Correct |
304 ms |
14668 KB |
Output is correct |
33 |
Correct |
250 ms |
13980 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2350 ms |
19760 KB |
Output is correct |
21 |
Correct |
1231 ms |
18388 KB |
Output is correct |
22 |
Correct |
1984 ms |
18612 KB |
Output is correct |
23 |
Correct |
2208 ms |
18368 KB |
Output is correct |
24 |
Correct |
2281 ms |
18560 KB |
Output is correct |
25 |
Correct |
2305 ms |
18396 KB |
Output is correct |
26 |
Correct |
2345 ms |
19976 KB |
Output is correct |
27 |
Correct |
2457 ms |
19856 KB |
Output is correct |
28 |
Correct |
2580 ms |
19736 KB |
Output is correct |
29 |
Correct |
1269 ms |
19908 KB |
Output is correct |
30 |
Correct |
2505 ms |
19440 KB |
Output is correct |
31 |
Correct |
2536 ms |
19600 KB |
Output is correct |
32 |
Correct |
2480 ms |
19920 KB |
Output is correct |
33 |
Correct |
2501 ms |
17976 KB |
Output is correct |
34 |
Correct |
1174 ms |
21248 KB |
Output is correct |
35 |
Correct |
2562 ms |
19420 KB |
Output is correct |
36 |
Correct |
2478 ms |
19772 KB |
Output is correct |
37 |
Correct |
1400 ms |
19844 KB |
Output is correct |
38 |
Correct |
2176 ms |
18796 KB |
Output is correct |
39 |
Correct |
2322 ms |
18576 KB |
Output is correct |
40 |
Correct |
2469 ms |
18584 KB |
Output is correct |
41 |
Correct |
2502 ms |
18564 KB |
Output is correct |
42 |
Correct |
2557 ms |
19500 KB |
Output is correct |
43 |
Correct |
2551 ms |
19832 KB |
Output is correct |
44 |
Correct |
2543 ms |
19612 KB |
Output is correct |
45 |
Correct |
1266 ms |
19760 KB |
Output is correct |
46 |
Correct |
2515 ms |
19704 KB |
Output is correct |
47 |
Correct |
2464 ms |
19620 KB |
Output is correct |
48 |
Correct |
2458 ms |
19564 KB |
Output is correct |
49 |
Correct |
2496 ms |
17964 KB |
Output is correct |
50 |
Correct |
1137 ms |
19728 KB |
Output is correct |
51 |
Correct |
2477 ms |
17976 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2350 ms |
19760 KB |
Output is correct |
21 |
Correct |
1231 ms |
18388 KB |
Output is correct |
22 |
Correct |
1984 ms |
18612 KB |
Output is correct |
23 |
Correct |
2208 ms |
18368 KB |
Output is correct |
24 |
Correct |
2281 ms |
18560 KB |
Output is correct |
25 |
Correct |
2305 ms |
18396 KB |
Output is correct |
26 |
Correct |
2345 ms |
19976 KB |
Output is correct |
27 |
Correct |
2457 ms |
19856 KB |
Output is correct |
28 |
Correct |
2580 ms |
19736 KB |
Output is correct |
29 |
Correct |
1269 ms |
19908 KB |
Output is correct |
30 |
Correct |
2505 ms |
19440 KB |
Output is correct |
31 |
Correct |
2536 ms |
19600 KB |
Output is correct |
32 |
Correct |
2480 ms |
19920 KB |
Output is correct |
33 |
Correct |
2501 ms |
17976 KB |
Output is correct |
34 |
Correct |
1174 ms |
21248 KB |
Output is correct |
35 |
Correct |
2562 ms |
19420 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
2193 ms |
39316 KB |
Output is correct |
40 |
Correct |
2205 ms |
40672 KB |
Output is correct |
41 |
Correct |
2175 ms |
40532 KB |
Output is correct |
42 |
Correct |
453 ms |
42512 KB |
Output is correct |
43 |
Correct |
448 ms |
42524 KB |
Output is correct |
44 |
Correct |
460 ms |
42724 KB |
Output is correct |
45 |
Correct |
2115 ms |
40132 KB |
Output is correct |
46 |
Correct |
444 ms |
42616 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
237 ms |
14196 KB |
Output is correct |
49 |
Correct |
227 ms |
14368 KB |
Output is correct |
50 |
Correct |
229 ms |
14280 KB |
Output is correct |
51 |
Correct |
253 ms |
14312 KB |
Output is correct |
52 |
Correct |
237 ms |
14232 KB |
Output is correct |
53 |
Correct |
257 ms |
14304 KB |
Output is correct |
54 |
Correct |
233 ms |
14196 KB |
Output is correct |
55 |
Correct |
227 ms |
14288 KB |
Output is correct |
56 |
Correct |
273 ms |
14184 KB |
Output is correct |
57 |
Correct |
235 ms |
14288 KB |
Output is correct |
58 |
Correct |
234 ms |
14284 KB |
Output is correct |
59 |
Correct |
243 ms |
14240 KB |
Output is correct |
60 |
Correct |
304 ms |
14668 KB |
Output is correct |
61 |
Correct |
250 ms |
13980 KB |
Output is correct |
62 |
Correct |
2478 ms |
19772 KB |
Output is correct |
63 |
Correct |
1400 ms |
19844 KB |
Output is correct |
64 |
Correct |
2176 ms |
18796 KB |
Output is correct |
65 |
Correct |
2322 ms |
18576 KB |
Output is correct |
66 |
Correct |
2469 ms |
18584 KB |
Output is correct |
67 |
Correct |
2502 ms |
18564 KB |
Output is correct |
68 |
Correct |
2557 ms |
19500 KB |
Output is correct |
69 |
Correct |
2551 ms |
19832 KB |
Output is correct |
70 |
Correct |
2543 ms |
19612 KB |
Output is correct |
71 |
Correct |
1266 ms |
19760 KB |
Output is correct |
72 |
Correct |
2515 ms |
19704 KB |
Output is correct |
73 |
Correct |
2464 ms |
19620 KB |
Output is correct |
74 |
Correct |
2458 ms |
19564 KB |
Output is correct |
75 |
Correct |
2496 ms |
17964 KB |
Output is correct |
76 |
Correct |
1137 ms |
19728 KB |
Output is correct |
77 |
Correct |
2477 ms |
17976 KB |
Output is correct |
78 |
Correct |
2716 ms |
31620 KB |
Output is correct |
79 |
Correct |
1569 ms |
39272 KB |
Output is correct |
80 |
Correct |
2413 ms |
40720 KB |
Output is correct |
81 |
Correct |
2570 ms |
40600 KB |
Output is correct |
82 |
Correct |
2695 ms |
39652 KB |
Output is correct |
83 |
Correct |
2695 ms |
39176 KB |
Output is correct |
84 |
Correct |
2767 ms |
36572 KB |
Output is correct |
85 |
Correct |
2750 ms |
39556 KB |
Output is correct |
86 |
Correct |
2721 ms |
28392 KB |
Output is correct |
87 |
Correct |
1480 ms |
34336 KB |
Output is correct |
88 |
Correct |
2921 ms |
39424 KB |
Output is correct |
89 |
Correct |
2971 ms |
39356 KB |
Output is correct |
90 |
Correct |
2747 ms |
37908 KB |
Output is correct |
91 |
Correct |
2735 ms |
27604 KB |
Output is correct |
92 |
Correct |
1394 ms |
31496 KB |
Output is correct |
93 |
Correct |
2706 ms |
28696 KB |
Output is correct |