QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411069#6322. Forestrygrass8cowCompile Error//C++171.4kb2024-05-14 21:23:092024-05-14 21:26:21

Judging History

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

  • [2024-05-14 21:26:21]
  • 管理员手动重测该提交记录
  • [2024-05-14 21:23:09]
  • 提交

answer

bool cmp(int x,int y){return a[x]<a[y];}
const int mod=998244353;
vector<int>g[300100];
int cn,su[10010000][2],ls[10010000],rs[6010000],tg[10010000],p2[301000];
void ag(int x,int z){
	if(!x)return;
	tg[x]=1ll*tg[x]*z%mod;
	for(int i=0;i<2;i++)su[x][i]=1ll*su[x][i]*z%mod;
}
void pd(int x){ag(ls[x],tg[x]),ag(rs[x],tg[x]),tg[x]=1;}
int merge(int x,int y,int fx,int fy){
	if(!x||!y){
		if(!x)swap(x,y),swap(fx,fy);
		ag(x,fx);return x;
	}
	pd(x),pd(y);
	ls[x]=merge(ls[x],ls[y],(fx+su[rs[y]][0])%mod,(fy+su[rs[x]][0])%mod);
	rs[x]=merge(rs[x],rs[y],fx,fy);
	for(int i=0;i<2;i++)
	su[x][i]=(su[ls[x]][i]+su[rs[x]][i])%mod;
	return x;
}
void up(int &o,int l,int r,int x,int z){
	o=++cn,tg[o]=1,su[o][0]=1,su[o][1]=z;
	if(l==r)return;int mid=(l+r)>>1;
	if(x<=mid)up(ls[o],l,mid,x,z);
	else up(rs[o],mid+1,r,x,z);
}
#define pb push_back
int T[300100],ans,sz[301000];
void dfs(int x,int f){
	up(T[x],1,n,rk[x],a[x]),sz[x]=1;
	for(int v:g[x])if(v!=f)dfs(v,x),sz[x]+=sz[v],T[x]=merge(T[x],T[v],su[T[v]][0],0);
	(ans+=1ll*((x==1)?p2[n-sz[x]]:p2[n-1-sz[x]])*su[T[x]][1]%mod)%=mod;
}
int main(){
	p2[0]=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),ip[i]=i,p2[i]=2*p2[i-1]%mod;
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
	sort(ip+1,ip+n+1,cmp);
	for(int i=1;i<=n;i++)rk[ip[i]]=i;
	dfs(1,0);
	return printf("%d",(ans+mod)%mod),0;
}

Details

answer.code: In function ‘bool cmp(int, int)’:
answer.code:1:30: error: ‘a’ was not declared in this scope
    1 | bool cmp(int x,int y){return a[x]<a[y];}
      |                              ^
answer.code: At global scope:
answer.code:3:1: error: ‘vector’ does not name a type
    3 | vector<int>g[300100];
      | ^~~~~~
answer.code: In function ‘int merge(int, int, int, int)’:
answer.code:13:23: error: ‘swap’ was not declared in this scope
   13 |                 if(!x)swap(x,y),swap(fx,fy);
      |                       ^~~~
answer.code: In function ‘void dfs(int, int)’:
answer.code:32:19: error: ‘n’ was not declared in this scope
   32 |         up(T[x],1,n,rk[x],a[x]),sz[x]=1;
      |                   ^
answer.code:32:21: error: ‘rk’ was not declared in this scope; did you mean ‘rs’?
   32 |         up(T[x],1,n,rk[x],a[x]),sz[x]=1;
      |                     ^~
      |                     rs
answer.code:32:27: error: ‘a’ was not declared in this scope
   32 |         up(T[x],1,n,rk[x],a[x]),sz[x]=1;
      |                           ^
answer.code:33:19: error: ‘g’ was not declared in this scope
   33 |         for(int v:g[x])if(v!=f)dfs(v,x),sz[x]+=sz[v],T[x]=merge(T[x],T[v],su[T[v]][0],0);
      |                   ^
answer.code: In function ‘int main()’:
answer.code:38:21: error: ‘n’ was not declared in this scope; did you mean ‘cn’?
   38 |         scanf("%d",&n);
      |                     ^
      |                     cn
answer.code:38:9: error: ‘scanf’ was not declared in this scope
   38 |         scanf("%d",&n);
      |         ^~~~~
answer.code:39:42: error: ‘a’ was not declared in this scope
   39 |         for(int i=1;i<=n;i++)scanf("%d",&a[i]),ip[i]=i,p2[i]=2*p2[i-1]%mod;
      |                                          ^
answer.code:39:48: error: ‘ip’ was not declared in this scope; did you mean ‘i’?
   39 |         for(int i=1;i<=n;i++)scanf("%d",&a[i]),ip[i]=i,p2[i]=2*p2[i-1]%mod;
      |                                                ^~
      |                                                i
answer.code:40:53: error: ‘g’ was not declared in this scope
   40 |         for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
      |                                                     ^
answer.code:41:14: error: ‘ip’ was not declared in this scope; did you mean ‘up’?
   41 |         sort(ip+1,ip+n+1,cmp);
      |              ^~
      |              up
answer.code:41:9: error: ‘sort’ was not declared in this scope; did you mean ‘short’?
   41 |         sort(ip+1,ip+n+1,cmp);
      |         ^~~~
      |         short
answer.code:42:30: error: ‘rk’ was not declared in this scope; did you mean ‘rs’?
   42 |         for(int i=1;i<=n;i++)rk[ip[i]]=i;
      |                              ^~
      |                              rs
answer.code:44:16: error: ‘printf’ was not declared in this scope
   44 |         return printf("%d",(ans+mod)%mod),0;
      |                ^~~~~~
answer.code:1:1: note: ‘printf’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’?
  +++ |+#include <cstdio>
    1 | bool cmp(int x,int y){return a[x]<a[y];}