#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+=3;x<maxm;x+=x&-x) fenwik[s][x]+=val; }
int get(int x,int s) { int res=0; for (x+=3;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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2498 ms |
18508 KB |
Output is correct |
21 |
Correct |
1319 ms |
18316 KB |
Output is correct |
22 |
Correct |
2114 ms |
18340 KB |
Output is correct |
23 |
Correct |
2318 ms |
18312 KB |
Output is correct |
24 |
Correct |
2408 ms |
18456 KB |
Output is correct |
25 |
Correct |
2492 ms |
18264 KB |
Output is correct |
26 |
Correct |
2563 ms |
18436 KB |
Output is correct |
27 |
Correct |
2572 ms |
18332 KB |
Output is correct |
28 |
Correct |
2504 ms |
18376 KB |
Output is correct |
29 |
Correct |
1256 ms |
18436 KB |
Output is correct |
30 |
Correct |
2462 ms |
18072 KB |
Output is correct |
31 |
Correct |
2535 ms |
18168 KB |
Output is correct |
32 |
Correct |
2496 ms |
18348 KB |
Output is correct |
33 |
Correct |
2581 ms |
17928 KB |
Output is correct |
34 |
Correct |
1183 ms |
19760 KB |
Output is correct |
35 |
Correct |
2536 ms |
17956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
2176 ms |
29332 KB |
Output is correct |
5 |
Correct |
2277 ms |
29428 KB |
Output is correct |
6 |
Correct |
2156 ms |
29404 KB |
Output is correct |
7 |
Correct |
474 ms |
31252 KB |
Output is correct |
8 |
Correct |
465 ms |
31420 KB |
Output is correct |
9 |
Correct |
448 ms |
31340 KB |
Output is correct |
10 |
Correct |
2125 ms |
28660 KB |
Output is correct |
11 |
Correct |
433 ms |
31588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
250 ms |
13004 KB |
Output is correct |
21 |
Correct |
235 ms |
12904 KB |
Output is correct |
22 |
Correct |
241 ms |
12924 KB |
Output is correct |
23 |
Correct |
254 ms |
12904 KB |
Output is correct |
24 |
Correct |
254 ms |
12924 KB |
Output is correct |
25 |
Correct |
242 ms |
12856 KB |
Output is correct |
26 |
Correct |
243 ms |
12852 KB |
Output is correct |
27 |
Correct |
245 ms |
12864 KB |
Output is correct |
28 |
Correct |
251 ms |
12784 KB |
Output is correct |
29 |
Correct |
249 ms |
12812 KB |
Output is correct |
30 |
Correct |
239 ms |
12876 KB |
Output is correct |
31 |
Correct |
241 ms |
12880 KB |
Output is correct |
32 |
Correct |
227 ms |
13520 KB |
Output is correct |
33 |
Correct |
241 ms |
12768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2498 ms |
18508 KB |
Output is correct |
21 |
Correct |
1319 ms |
18316 KB |
Output is correct |
22 |
Correct |
2114 ms |
18340 KB |
Output is correct |
23 |
Correct |
2318 ms |
18312 KB |
Output is correct |
24 |
Correct |
2408 ms |
18456 KB |
Output is correct |
25 |
Correct |
2492 ms |
18264 KB |
Output is correct |
26 |
Correct |
2563 ms |
18436 KB |
Output is correct |
27 |
Correct |
2572 ms |
18332 KB |
Output is correct |
28 |
Correct |
2504 ms |
18376 KB |
Output is correct |
29 |
Correct |
1256 ms |
18436 KB |
Output is correct |
30 |
Correct |
2462 ms |
18072 KB |
Output is correct |
31 |
Correct |
2535 ms |
18168 KB |
Output is correct |
32 |
Correct |
2496 ms |
18348 KB |
Output is correct |
33 |
Correct |
2581 ms |
17928 KB |
Output is correct |
34 |
Correct |
1183 ms |
19760 KB |
Output is correct |
35 |
Correct |
2536 ms |
17956 KB |
Output is correct |
36 |
Correct |
2524 ms |
18632 KB |
Output is correct |
37 |
Correct |
1386 ms |
18704 KB |
Output is correct |
38 |
Correct |
2141 ms |
18516 KB |
Output is correct |
39 |
Correct |
2331 ms |
18560 KB |
Output is correct |
40 |
Correct |
2417 ms |
18480 KB |
Output is correct |
41 |
Correct |
2424 ms |
18528 KB |
Output is correct |
42 |
Correct |
2449 ms |
18508 KB |
Output is correct |
43 |
Correct |
2515 ms |
18456 KB |
Output is correct |
44 |
Correct |
2485 ms |
18464 KB |
Output is correct |
45 |
Correct |
1252 ms |
18704 KB |
Output is correct |
46 |
Correct |
2566 ms |
18564 KB |
Output is correct |
47 |
Correct |
2471 ms |
18564 KB |
Output is correct |
48 |
Correct |
2459 ms |
18552 KB |
Output is correct |
49 |
Correct |
2517 ms |
18012 KB |
Output is correct |
50 |
Correct |
1145 ms |
19764 KB |
Output is correct |
51 |
Correct |
2517 ms |
18008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2498 ms |
18508 KB |
Output is correct |
21 |
Correct |
1319 ms |
18316 KB |
Output is correct |
22 |
Correct |
2114 ms |
18340 KB |
Output is correct |
23 |
Correct |
2318 ms |
18312 KB |
Output is correct |
24 |
Correct |
2408 ms |
18456 KB |
Output is correct |
25 |
Correct |
2492 ms |
18264 KB |
Output is correct |
26 |
Correct |
2563 ms |
18436 KB |
Output is correct |
27 |
Correct |
2572 ms |
18332 KB |
Output is correct |
28 |
Correct |
2504 ms |
18376 KB |
Output is correct |
29 |
Correct |
1256 ms |
18436 KB |
Output is correct |
30 |
Correct |
2462 ms |
18072 KB |
Output is correct |
31 |
Correct |
2535 ms |
18168 KB |
Output is correct |
32 |
Correct |
2496 ms |
18348 KB |
Output is correct |
33 |
Correct |
2581 ms |
17928 KB |
Output is correct |
34 |
Correct |
1183 ms |
19760 KB |
Output is correct |
35 |
Correct |
2536 ms |
17956 KB |
Output is correct |
36 |
Correct |
1 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 |
2176 ms |
29332 KB |
Output is correct |
40 |
Correct |
2277 ms |
29428 KB |
Output is correct |
41 |
Correct |
2156 ms |
29404 KB |
Output is correct |
42 |
Correct |
474 ms |
31252 KB |
Output is correct |
43 |
Correct |
465 ms |
31420 KB |
Output is correct |
44 |
Correct |
448 ms |
31340 KB |
Output is correct |
45 |
Correct |
2125 ms |
28660 KB |
Output is correct |
46 |
Correct |
433 ms |
31588 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
250 ms |
13004 KB |
Output is correct |
49 |
Correct |
235 ms |
12904 KB |
Output is correct |
50 |
Correct |
241 ms |
12924 KB |
Output is correct |
51 |
Correct |
254 ms |
12904 KB |
Output is correct |
52 |
Correct |
254 ms |
12924 KB |
Output is correct |
53 |
Correct |
242 ms |
12856 KB |
Output is correct |
54 |
Correct |
243 ms |
12852 KB |
Output is correct |
55 |
Correct |
245 ms |
12864 KB |
Output is correct |
56 |
Correct |
251 ms |
12784 KB |
Output is correct |
57 |
Correct |
249 ms |
12812 KB |
Output is correct |
58 |
Correct |
239 ms |
12876 KB |
Output is correct |
59 |
Correct |
241 ms |
12880 KB |
Output is correct |
60 |
Correct |
227 ms |
13520 KB |
Output is correct |
61 |
Correct |
241 ms |
12768 KB |
Output is correct |
62 |
Correct |
2524 ms |
18632 KB |
Output is correct |
63 |
Correct |
1386 ms |
18704 KB |
Output is correct |
64 |
Correct |
2141 ms |
18516 KB |
Output is correct |
65 |
Correct |
2331 ms |
18560 KB |
Output is correct |
66 |
Correct |
2417 ms |
18480 KB |
Output is correct |
67 |
Correct |
2424 ms |
18528 KB |
Output is correct |
68 |
Correct |
2449 ms |
18508 KB |
Output is correct |
69 |
Correct |
2515 ms |
18456 KB |
Output is correct |
70 |
Correct |
2485 ms |
18464 KB |
Output is correct |
71 |
Correct |
1252 ms |
18704 KB |
Output is correct |
72 |
Correct |
2566 ms |
18564 KB |
Output is correct |
73 |
Correct |
2471 ms |
18564 KB |
Output is correct |
74 |
Correct |
2459 ms |
18552 KB |
Output is correct |
75 |
Correct |
2517 ms |
18012 KB |
Output is correct |
76 |
Correct |
1145 ms |
19764 KB |
Output is correct |
77 |
Correct |
2517 ms |
18008 KB |
Output is correct |
78 |
Correct |
2754 ms |
28464 KB |
Output is correct |
79 |
Correct |
1562 ms |
30320 KB |
Output is correct |
80 |
Correct |
2423 ms |
29440 KB |
Output is correct |
81 |
Correct |
2557 ms |
29380 KB |
Output is correct |
82 |
Correct |
2930 ms |
28956 KB |
Output is correct |
83 |
Correct |
2890 ms |
28928 KB |
Output is correct |
84 |
Correct |
2740 ms |
28912 KB |
Output is correct |
85 |
Correct |
2729 ms |
28896 KB |
Output is correct |
86 |
Correct |
2704 ms |
28408 KB |
Output is correct |
87 |
Correct |
1500 ms |
30492 KB |
Output is correct |
88 |
Correct |
2625 ms |
28452 KB |
Output is correct |
89 |
Correct |
2573 ms |
28348 KB |
Output is correct |
90 |
Correct |
2571 ms |
28316 KB |
Output is correct |
91 |
Correct |
2575 ms |
27764 KB |
Output is correct |
92 |
Correct |
1288 ms |
31500 KB |
Output is correct |
93 |
Correct |
2543 ms |
28808 KB |
Output is correct |