Submission #713403

#TimeUsernameProblemLanguageResultExecution timeMemory
713403uroskReconstruction Project (JOI22_reconstruction)C++14
100 / 100
1797 ms34404 KiB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
//using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 505
#define maxm 100005
struct edg{
    ll x,y,w;
};
ll n,m,q;
ll dsu[maxn];
ll root(ll x){
    while(x!=dsu[x]){
        dsu[x] = dsu[dsu[x]];
        x = dsu[x];
    }
    return x;
}
ll get(ll x,ll y){return root(x)==root(y);}
void upd(ll x,ll y){
    x = root(x);
    y = root(y);
    dsu[x] = y;
}
bool cmp(edg a,edg b){return a.w<b.w;}
bool cmp2(edg a,edg b){return a.x<b.x;}
edg e[maxm];
vector<edg> v;
void tc(){
    cin >> n >> m;
    for(ll i = 1;i<=m;i++){
        cin >> e[i].x >> e[i].y >> e[i].w;
    }
    sort(e+1,e+1+m,cmp);
    for(ll i = 1;i<=m;i++){
        iota(dsu+1,dsu+1+n,1);
        ll l = -1,r = -1;
        for(ll j = i+1;j<=m;j++){
            upd(e[j].x,e[j].y);
            if(get(e[i].x,e[i].y)){r = j;break;}
        }
        iota(dsu+1,dsu+1+n,1);
        for(ll j = i-1;j>=1;j--){
            upd(e[j].x,e[j].y);
            if(get(e[i].x,e[i].y)){l = j;break;}
        }
        ll lx,rx;
        if(r!=-1) rx = e[i].w + (e[r].w-e[i].w+1)/2;
        else rx = llinf;
        if(l!=-1) lx = e[l].w + (e[i].w-e[l].w+1)/2;
        else lx = -1;
        v.pb({lx,-1,e[i].w});
        v.pb({e[i].w,2,-2*e[i].w});
        v.pb({rx,-1,e[i].w});
    }
    sort(all(v),cmp2);
    ll j = 0;
    cin >> q;
    ll a = 0,b = 0;
    ///a*x+b
    for(ll i = 1;i<=q;i++){
        ll x; cin >> x;
        while(j<v.size()&&v[j].x<=x){
            a+=v[j].y;
            b+=v[j].w;
            j++;
        }
        cout<<a*x+b<<endl;
    }

}
int main(){
	daj_mi_malo_vremena
    int t; t = 1;
    while(t--){
        tc();
    }
	return 0;
}
/**
5 10
1 2 8
1 3 13
1 4 5
1 5 11
1 5 3
2 3 7
2 4 15
3 4 6
3 5 6
4 5 2
6
3
6
8
10
13
17
**/

Compilation message (stderr)

reconstruction.cpp: In function 'void tc()':
reconstruction.cpp:105:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edg>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |         while(j<v.size()&&v[j].x<=x){
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...