QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560085#8222. 投票游戏DaiRuiChen0070 52ms24536kbC++173.3kb2024-09-12 12:22:142024-09-12 12:22:15

Judging History

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

  • [2024-09-12 12:22:15]
  • 评测
  • 测评结果:0
  • 用时:52ms
  • 内存:24536kb
  • [2024-09-12 12:22:14]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=2e5+5;
mt19937 rnd(time(0));
int n,q,fa[MAXN];
vector <int> G[MAXN];
ll f[MAXN],a[MAXN],b[MAXN],bs[MAXN];
struct FHQ {
	int pri[MAXN],ls[MAXN],rs[MAXN];
	ll sum[MAXN],mn[MAXN];
	//sum of b[x], min f[x]+b[1~x-1]
	void psu(int x) {
		sum[x]=sum[ls[x]]+b[x]+sum[rs[x]];
		mn[x]=min({mn[ls[x]],sum[ls[x]]+f[x],sum[ls[x]]+b[x]+mn[rs[x]]});
	}
	void split(int p,ll k,int o,int &x,int &y) { //split by(k,o)
		if(!p) return x=y=0,void();
		if(f[p]>k||(f[p]==k&&p>o)) x=p,split(rs[p],k,o,rs[x],y),psu(x);
		else y=p,split(ls[p],k,o,x,ls[y]),psu(y);
	}
	int merge(int x,int y) {
		if(!x||!y) return x|y;
		if(pri[x]<pri[y]) return rs[x]=merge(rs[x],y),psu(x),x;
		else return ls[y]=merge(x,ls[y]),psu(y),y;
	}
	ll qry(int p,ll k) { //qry mn[p] < k
		if(!p) return k;
		if(mn[ls[p]]<k) return qry(ls[p],k);
		else if(sum[ls[p]]+f[p]<k) return k-sum[ls[p]];
		else return qry(rs[p],k-sum[ls[p]]-b[p]);
	}
}	Q;
int rt[MAXN];
void insT(int u,int v) {
	int x,y;
	Q.split(rt[u],f[v],v,x,y);
	Q.mn[v]=f[v],Q.sum[v]=b[v];
	rt[u]=Q.merge(x,Q.merge(v,y));
}
void ersT(int u,int v) {
	int x,y,z,w;
	Q.split(rt[u],f[v],v,x,y);
	Q.split(y,f[v],v-1,z,w);
	rt[u]=Q.merge(x,w);
}
struct info {
	ll k,x,y; //[<k]: x, [>=k]: y
	ll w(ll z) { return z<k?x:y; }
	friend info operator +(info u,info v) { return {u.k,v.w(u.x),v.w(u.y)}; }
};
struct Segt {
	info tr[MAXN<<2];
	void upd(int u,const info &I,int l=1,int r=n,int p=1) {
		if(l==r) return tr[p]=I,void();
		int mid=(l+r)>>1;
		u<=mid?upd(u,I,l,mid,p<<1):upd(u,I,mid+1,r,p<<1|1);
		tr[p]=tr[p<<1|1]+tr[p<<1];
	}
	info qry(int ul,int ur,int l=1,int r=n,int p=1) {
		if(ul<=l&&r<=ur) return tr[p];
		int mid=(l+r)>>1;
		if(ur<=mid) return qry(ul,ur,l,mid,p<<1);
		if(mid<ul) return qry(ul,ur,mid+1,r,p<<1|1);
		return qry(ul,ur,mid+1,r,p<<1|1)+qry(ul,ur,l,mid,p<<1);
	}
}	T;
info I[MAXN];
int siz[MAXN],hson[MAXN],top[MAXN],bot[MAXN],dfn[MAXN],dcnt;
info qI(int u) {
	if(!hson[u]) { return {0,0,a[u]}; }
	ll w=Q.qry(rt[u],a[u]+bs[u]);
	return {w,w,Q.qry(rt[u],a[u]+bs[u]-b[hson[u]])};
}
void dfs0(int u) {
	siz[u]=1;
	for(int v:G[u]) {
		dfs0(v),siz[u]+=siz[v];
		if(siz[v]>siz[hson[u]]) hson[u]=v;
	}
	for(int v:G[u]) if(v^hson[u]) insT(u,v);
	I[u]=qI(u),f[u]=I[u].w(hson[u]);
}
void dfs1(int u,int r) {
	dfn[u]=++dcnt,top[u]=r,T.upd(dfn[u],I[u]);
	if(hson[u]) dfs1(hson[u],r),bot[u]=bot[hson[u]];
	else bot[u]=u;
	for(int v:G[u]) if(v^hson[u]) dfs1(v,v),insT(u,v);
}
ll qf(int u) {
	return T.qry(dfn[top[u]],dfn[bot[u]]).w(0);
}
void upd(int x) {
	while(x) {
		I[x]=qI(x),T.upd(dfn[x],I[x]);
		x=top[x];
		if(x==1) return ;
		ersT(fa[x],x),f[x]=qf(x),insT(fa[x],x);
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin>>n>>q;
	for(int i=2;i<=n;++i) cin>>fa[i],G[fa[i]].push_back(i);
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=1;i<=n;++i) cin>>b[i],bs[fa[i]]+=b[i];
	for(int i=1;i<=n;++i) Q.pri[i]=rnd();
	dfs0(1),dfs1(1,1);
	for(int op,u,x,y;q--;) {
		cin>>op;
		if(op==1) {
			cin>>u>>x>>y;
			a[u]=x,upd(u);
			if(u>1) {
				bs[fa[u]]+=y-b[u];
				if(u!=hson[fa[u]]) ersT(fa[u],u),b[u]=y,f[u]=qf(u),insT(fa[u],u);
				else b[u]=y;
				upd(fa[u]);
			}
		} else {
			cin>>x>>y;
			cout<<"10"[f[x]>f[y]||(f[x]==f[y]&&x>y)]<<"\n";
		}
	}
	return 0;
}

詳細信息

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

input:

20 500
1 1 3 1 3 5 6 6 7 3 5 3 9 5 4 7 7 18 2
42129194 82765784 1447057 29726963 82321558 32094641 22474113 49277574 27527633 20746795 47630926 92888389 26787144 80703040 43876864 97991729 12117966 75633318 33577855 93462601
69163546 49621952 45236756 46447931 34085269 55246550 54414402 99593046 103...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Memory Limit Exceeded

Test #13:

score: 0
Memory Limit Exceeded

input:

200 200000
1 2 3 3 5 3 1 6 2 9 11 5 5 2 4 9 17 8 1 4 10 20 18 20 23 13 16 28 15 4 6 27 26 11 30 25 10 2 13 23 25 35 4 8 40 43 36 26 7 27 45 35 14 31 54 45 9 8 9 54 16 32 62 9 29 2 43 39 34 39 27 2 52 56 6 9 48 26 66 28 35 57 79 13 71 61 38 43 80 26 61 26 79 1 24 64 79 15 41 42 56 55 6 24 92 43 89 76...

output:


result:


Subtask #4:

score: 0
Memory Limit Exceeded

Test #18:

score: 0
Memory Limit Exceeded

input:

200 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:


result:


Subtask #5:

score: 0
Wrong Answer

Test #26:

score: 0
Wrong Answer
time: 52ms
memory: 24536kb

input:

200 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...

output:

1
0
1
0
1
1
1
1
0
1
1
1
0
0
0
0
0
0
1
0
0
1
1
0
1
1
1
0
1
0
0
1
0
1
1
1
0
1
0
1
1
0
0
0
1
1
1
0
1
0
0
1
0
1
1
0
1
1
0
0
1
0
0
0
0
0
0
1
0
1
1
0
1
0
1
1
1
1
1
0
0
0
0
1
0
1
0
0
1
1
1
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
1
1
0
1
0
0
0
0
0
0
0
1
0
1
1
1
0
0
0
0
0
1
1
0
1
0
0
0
1
0
0
0
0
1
1
1
0
1
1
1
0
...

result:

wrong answer 17th numbers differ - expected: '1', found: '0'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%