QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535660#9165. Petrol stationsfucious_yin#Compile Error//C++143.4kb2024-08-28 12:23:582024-08-28 12:23:59

Judging History

你现在查看的是最新测评结果

  • [2024-08-28 12:23:59]
  • 评测
  • [2024-08-28 12:23:58]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define F(i,x,y) for(int i=(x);i<=(y);i++)
#define DF(i,x,y) for(int i=(x);i>=(y);i--)
#define ms(x,y) memset(x,y,sizeof(x))
#define SZ(x) (int)x.size()-1
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> pii;
template<typename T> void chkmax(T &x,T y){ x=max(x,y);}
template<typename T> void chkmin(T &x,T y){ x=min(x,y);}
template<typename T> void read(T &FF){
    FF=0;int RR=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') RR=-1;
    for(;isdigit(ch);ch=getchar()) FF=(FF<<1)+(FF<<3)+ch-48;
    FF*=RR;
}
const int N=70010;
int n,k;LL ans[N];
vector<pii> G[N];
bool vis[N];
int siz[N];
void dfs1(int u,int fa){
    siz[u]=1;
    for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa) dfs1(v,u),siz[u]+=siz[v];
}
LL dep[N];
int pas[N],len,fa[N],MUL;
LL s1[N],s2[N];
void dfs2(int u){
    s1[u]=s2[u]=0;
    pas[++len]=u;
    for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) fa[v]=u,dep[v]=dep[u]+w,dfs2(v);
    if(dep[u]>k){
        int lo=0,hi=len;
        while(lo<hi-1){
            int mid=(lo+hi)>>1;
            if(dep[u]-dep[pas[mid]]<=k) hi=mid;
            else lo=mid;
        }
        s1[pas[hi]]+=s1[u]+1;
    }
    ans[u]+=s1[u]*MUL;
    len--;
}
typedef pair<int,LL> pil;
#define fi first
#define se second
pil ovo[N];int cnt;
void ins(int u){
    if(dep[u]<=k) ovo[++cnt]={dep[u],s1[u]+1};
    for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) ins(v);
}
void dfs3(int u,int coef){
    int hi=lower_bound(ovo+1,ovo+cnt+1,pil{k-dep[fa[u]]+1,0})-ovo-1;
    int lo=lower_bound(ovo+1,ovo+cnt+1,pil{k-dep[u]+1,0})-ovo;
    if(lo<=hi) s2[u]+=(ovo[hi].se-ovo[lo-1].se)*coef;
    for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) dfs3(v,coef);
}
LL prs[N];
void dfs4(int u){
    pas[++len]=u;
    int tl,tr;
    int lo=0,hi=len;
    while(lo<hi-1){
        int mid=(lo+hi)>>1;
        if(dep[fa[u]]-dep[fa[pas[mid]]]<=k) hi=mid;
        else lo=mid;
    }
    tl=hi;
    lo=0,hi=len+1;
    while(lo<hi-1){
        int mid=(lo+hi)>>1;
        if(dep[u]-dep[fa[pas[mid]]]>k) lo=mid;
        else hi=mid;
    }
    tr=lo;
    if(tl<=tr) s2[u]+=prs[pas[tr]]-prs[pas[tl-1]];
    ans[fa[u]]+=s2[u]*siz[u];
    prs[u]=prs[fa[u]]+s2[u];
    for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) dfs4(v);
    len--;
}
void solve(int rt){
    dfs1(rt,0);int tot=siz[rt];
    while(true){
        bool fl=0;
        for(auto [u,w]:G[rt]) if(!vis[u]&&siz[u]<siz[rt]&&siz[u]>tot/2){ rt=u,fl=1;break;}
        if(!fl) break;
    }
    dfs1(rt,0);
    dep[rt]=s1[rt]=s2[rt]=fa[rt]=0;
    for(auto [u,w]:G[rt]) if(!vis[u]) dep[u]=w,fa[u]=rt,MUL=tot-siz[u],dfs2(u);
    cnt=0,ins(rt);
    sort(ovo+1,ovo+cnt+1);
    F(i,1,cnt) ovo[i].se+=ovo[i-1].se;
    for(auto [u,w]:G[rt]) if(!vis[u]) dfs3(u,1);
    for(auto [u,w]:G[rt]) if(!vis[u]){
        cnt=0,ins(u);
        sort(ovo+1,ovo+cnt+1);
        F(i,1,cnt) ovo[i].se+=ovo[i-1].se;
        dfs3(u,-1);
    }
    prs[rt]=0;
    for(auto [u,w]:G[rt]) if(!vis[u]) dfs4(u);
    vis[rt]=1;
    for(auto [u,w]:G[rt]) if(!vis[u]) solve(u);
}
int main(){
    read(n),read(k);
    F(i,1,n-1){
        int x,y,z;read(x),read(y),read(z);x++,y++;
        G[x].pb({y,z}),G[y].pb({x,z});
    }
    solve(1);
    F(i,1,n) printf("%lld\n",ans[i]);
    return 0;
}

详细

answer.code: In function ‘void dfs1(long long int, long long int)’:
answer.code:28:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   28 |     for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa) dfs1(v,u),siz[u]+=siz[v];
      |              ^
answer.code: In function ‘void dfs2(long long int)’:
answer.code:36:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   36 |     for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) fa[v]=u,dep[v]=dep[u]+w,dfs2(v);
      |              ^
answer.code: In function ‘void ins(long long int)’:
answer.code:55:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   55 |     for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) ins(v);
      |              ^
answer.code: In function ‘void dfs3(long long int, long long int)’:
answer.code:61:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   61 |     for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) dfs3(v,coef);
      |              ^
answer.code: In function ‘void dfs4(long long int)’:
answer.code:84:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   84 |     for(auto [v,w]:G[u]) if(!vis[v]&&v!=fa[u]) dfs4(v);
      |              ^
answer.code: In function ‘void solve(long long int)’:
answer.code:91:18: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   91 |         for(auto [u,w]:G[rt]) if(!vis[u]&&siz[u]<siz[rt]&&siz[u]>tot/2){ rt=u,fl=1;break;}
      |                  ^
answer.code:96:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   96 |     for(auto [u,w]:G[rt]) if(!vis[u]) dep[u]=w,fa[u]=rt,MUL=tot-siz[u],dfs2(u);
      |              ^
answer.code:100:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  100 |     for(auto [u,w]:G[rt]) if(!vis[u]) dfs3(u,1);
      |              ^
answer.code:101:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  101 |     for(auto [u,w]:G[rt]) if(!vis[u]){
      |              ^
answer.code:108:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  108 |     for(auto [u,w]:G[rt]) if(!vis[u]) dfs4(u);
      |              ^
answer.code:110:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  110 |     for(auto [u,w]:G[rt]) if(!vis[u]) solve(u);
      |              ^
At global scope:
cc1plus: error: ‘::main’ must return ‘int’