답안 #568840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568840 2022-05-26T09:06:50 Z zaneyu Reconstruction Project (JOI22_reconstruction) C++14
7 / 100
1040 ms 32100 KB
/*input
3 4
1 2 1
1 2 4
2 3 2
2 3 4
4
1
2
3
4
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=5e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<P.f<<' '<<P.s;
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":"");
    return out;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    a%=MOD;
    if(a==0) return 0;
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
struct segt{
    ll seg[4*maxn],lazy[4*maxn];
    int n;
    void resize(int _n){
        n=_n;
    } 
    inline void pushdown(int idx,int l,int r){
        if(!lazy[idx]) return;
        if(l==r){
            lazy[idx]=0;
            return;
        }
        int mid=l+r>>1;
        seg[idx<<1]+=lazy[idx]*(mid-l+1);
        seg[idx<<1|1]+=lazy[idx]*(r-mid);
        lazy[idx<<1]+=lazy[idx];
        lazy[idx<<1|1]+=lazy[idx];
        lazy[idx]=0;
    }
    inline void upd(int idx,int l,int r,int ql,int qr,ll x){
        if(ql<=l and r<=qr){
            lazy[idx]+=x;
            seg[idx]+=x*(r-l+1);
            pushdown(idx,l,r);
            return;
        }
        pushdown(idx,l,r);
        int mid=l+r>>1;
        if(qr<=mid) upd(idx<<1,l,mid,ql,qr,x);
        else if(ql>mid) upd(idx<<1|1,mid+1,r,ql,qr,x);
        else upd(idx<<1,l,mid,ql,qr,x),upd(idx<<1|1,mid+1,r,ql,qr,x);
        seg[idx]=(seg[idx<<1]+seg[idx<<1|1]);
    }
    inline ll query(int idx,int l,int r,int ql,int qr){
        pushdown(idx,l,r);
        if(ql<=l and r<=qr) return seg[idx];
        int mid=l+r>>1;
        if(qr<=mid) return query(idx<<1,l,mid,ql,qr);
        else if(ql>mid) return query(idx<<1|1,mid+1,r,ql,qr);
        return query(idx<<1,l,mid,ql,qr)+query(idx<<1|1,mid+1,r,ql,qr);
    }
    inline ll query(int l,int r){
        if(l>r) return 0;
        return query(1,0,n-1,l,r);
    }
    inline void upd(int l,int r,ll x){
        if(l>r) return;
        upd(1,0,n-1,l,r,x);
    }
}seg;
vector<pii> v[maxn];
pii mn[maxn];
int l[maxn],r[maxn];
vector<pair<int,pii>> ed;
void dfs(int u,int p){
    for(auto x:v[u]){
        if(x.f==p) continue;
        MNTO(mn[x.f],make_pair(ed[x.s].f,x.s));
        dfs(x.f,u);
    }
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,m;
    cin>>n>>m;
    REP(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        --a,--b;
        ed.pb({c,{a,b}});
    }
    sort(ALL(ed));
    vector<pair<int,pii>> turn;
    REP(asd,m){
        auto x=ed[asd];
        int a=x.s.f,b=x.s.s;
        REP(i,n) mn[i]={INF,INF};
        dfs(a,-1);
        v[a].pb({b,asd}),v[b].pb({a,asd});
        pii z=mn[b];
        if(z.f==INF){
            l[asd]=1;
            continue;
        }
        int mid=(z.f+x.f+1)/2;
        r[z.s]=mid-1;
        l[asd]=mid;
        a=ed[z.s].s.f,b=ed[z.s].s.s;
        v[a].erase(find(ALL(v[a]),make_pair(b,z.s)));
        v[b].erase(find(ALL(v[b]),make_pair(a,z.s)));
    }
    REP(i,m){
        if(!r[i]) r[i]=1e9;
        //cout<<l[i]<<' '<<r[i]<<'\n';
        turn.pb({l[i],{-1,ed[i].f}});
        turn.pb({ed[i].f,{2,-2*ed[i].f}});
        turn.pb({r[i]+1,{-1,ed[i].f}});
    }
    sort(ALL(turn));
    int q;
    cin>>q;
    ll co=0,s=0;
    int p=0;
    while(q--){
        int k;
        cin>>k;
        while(p<sz(turn) and turn[p].f<=k){
            co+=turn[p].s.f;
            s+=turn[p].s.s;
            ++p;
        }
        cout<<s+co*k<<'\n';
    }
} 

Compilation message

reconstruction.cpp: In member function 'void segt::pushdown(int, int, int)':
reconstruction.cpp:82:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |         int mid=l+r>>1;
      |                 ~^~
reconstruction.cpp: In member function 'void segt::upd(int, int, int, int, int, ll)':
reconstruction.cpp:97:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |         int mid=l+r>>1;
      |                 ~^~
reconstruction.cpp: In member function 'll segt::query(int, int, int, int, int)':
reconstruction.cpp:106:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |         int mid=l+r>>1;
      |                 ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12084 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 1014 ms 30652 KB Output is correct
5 Correct 1040 ms 30144 KB Output is correct
6 Correct 1018 ms 29980 KB Output is correct
7 Correct 346 ms 31896 KB Output is correct
8 Correct 306 ms 32100 KB Output is correct
9 Correct 287 ms 31952 KB Output is correct
10 Correct 1029 ms 30120 KB Output is correct
11 Correct 284 ms 31888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12080 KB Output isn't correct
2 Halted 0 ms 0 KB -