QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401229 | #943. Dynamic Diameter | sichengzhou | Compile Error | / | / | C++14 | 4.1kb | 2024-04-28 09:23:42 | 2024-04-28 09:23:43 |
Judging History
This is the latest submission verdict.
- [2024-04-28 09:23:43]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-04-28 09:23:42]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+5,M=22;
int n,m,K,fa[N],d[N],w[N];
struct Edge{
int v,nxt;
}e[N];
int h[N],tot1;
void addEdge(int u,int v)
{
tot1++;
e[tot1].v=v;e[tot1].nxt=h[u];
h[u]=tot1;
}
struct Seg{
int l,r;
LL val,mx=-1,lz;
Seg()
{
mx=-1
val=lz=0;
}
}t[N<<2];
vector<pair<int,LL> >f[N];
void update(int p)
{
t[p].val=max(t[p<<1].val,t[p<<1|1].val);
}
void pushlz(int p,LL z)
{
t[p].val+=z;
t[p].lz+=z;
}
void pushmx(int p,LL z)
{
t[p].val=z;
t[p].mx=z;
t[p].lz=0;
}
void lzdown(int p)
{
if(t[p].l)
{
if(t[p].mx!=-1)pushmx(t[p].l,t[p].mx);
pushlz(t[p].l,t[p].lz);
}
if(t[p].r)
{
if(t[p].mx!=-1)pushmx(t[p].r,t[p].mx);
pushlz(t[p].r,t[p].lz);
}
t[p].mx=-1;t[p].lz=0;
}
LL val;
LL add(int p,int l,int r,int x,int y,LL z)
{
if(x<=l&&r<=y)
{
pushlz(p,z);
return t[p].val;
}
lzdown(p);
int mid=l+r>>1;
LL ret=0;
if(x<=mid)
{
ret=add(p<<1,l,mid,x,y,z);
}
if(mid+1<=y)
{
ret=add(p<<1|1,mid+1,r,x,y,z);
}
update(p);
return ret;
}
void change(int p,int l,int r,int x,int y,LL z)
{
if(x>y)return ;
if(x<=l&&r<=y)
{
if(l==r)
{
if(t[p].val<z)
{
pushmx(p,z);
}
return ;
}
lzdown(p);
int mid=l+r>>1;
if(t[p<<1].val<z)
{
pushmx(p<<1,z);
change(p<<1|1,mid+1,r,x,y,z);
}else{
change(p<<1,l,mid,x,y,z);
}
return ;
}
lzdown(p);
int mid=l+r>>1;
if(x<=mid)
{
change(p<<1,l,mid,x,y,z);
}
if(mid+1<=y)
{
change(p<<1|1,mid+1,r,x,y,z);
}
update(p);
}
LL query(int p,int l,int r,int x)
{
if(l==r)
{
return t[p].val;
}
lzdown(p);
int mid=l+r>>1;
if(x<=mid)
{
return query(p<<1,l,mid,x);
}else{
return query(p<<1|1,mid+1,r,x);
}
}
int sz[N],son[N],dfn[N],rnk[N],idx;
void dfs0(int u)
{
dfn[u]=++idx;rnk[idx]=u;
sz[u]=1;son[u]=0;
for(int i=h[u];i;i=e[i].nxt)
{
int v=e[i].v;
if(v==fa[u])
{
continue;
}
fa[v]=u;
dfs0(v);
sz[u]+=sz[v];
if(sz[v]>sz[son[u]])
{
son[u]=v;
}
}
}
void dfs(int u)
{
// cout<<u<<"b\n";
for(int i=h[u];i;i=e[i].nxt)
{
int v=e[i].v;
if(v==son[u])
{
continue;
}
dfs(v);
}
if(son[u])
{
dfs(son[u]);
}
for(int i=h[u];i;i=e[i].nxt)
{
int v=e[i].v;
if(v==son[u])
{
continue;
}
LL pre=0;
for(int j=0;j<f[v].size();j++)
{
add(1,1,K,f[v][j].first,K,f[v][j].second-pre);
pre=f[v][j].second;
}
}
if(w[u])
{
LL val=add(1,1,K,d[u],d[u],w[u]);
change(1,1,K,d[u]+1,K,val);
}
if(son[fa[u]]!=u)
{
for(int i=dfn[u];i<=dfn[u]+sz[u]-1;i++)
{
int v=rnk[i];
if(w[v])
{
f[u].push_back(make_pair(d[v],0));
}
}
sort(f[u].begin(),f[u].end());
vector<pair<int,LL> >::iterator it=unique(f[u].begin(),f[u].end());
f[u].resize(distance(f[u].begin(),it));
for(int i=0;i<f[u].size();i++)
{
f[u][i].second=query(1,1,K,f[u][i].first);
}
pushmx(1,0);
}
// cout<<u<<"e\n";
}
int main()
{
int x;
scanf("%d%d%d",&n,&m,&K);
for(int i=2;i<=n;i++)
{
scanf("%d",&fa[i]);
addEdge(fa[i],i);
}
for(int i=1;i<=m;i++)
{
scanf("%d",&x);
scanf("%d%d",&d[x],&w[x]);
}
dfs0(1);
dfs(1);
printf("%lld\n",f[1][f[1].size()-1].second);
return 0;
}
Details
answer.code: In constructor ‘Seg::Seg()’: answer.code:22:1: error: expected ‘;’ before ‘val’ 22 | val=lz=0; | ^~~ answer.code: In function ‘int main()’: answer.code:208:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 208 | scanf("%d%d%d",&n,&m,&K); | ~~~~~^~~~~~~~~~~~~~~~~~~ answer.code:211:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 211 | scanf("%d",&fa[i]); | ~~~~~^~~~~~~~~~~~~ answer.code:216:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 216 | scanf("%d",&x); | ~~~~~^~~~~~~~~ answer.code:217:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 217 | scanf("%d%d",&d[x],&w[x]); | ~~~~~^~~~~~~~~~~~~~~~~~~~