QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558578#8222. 投票游戏Kevin530720 186ms66040kbC++234.8kb2024-09-11 16:54:332024-09-11 16:54:33

Judging History

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

  • [2024-09-11 16:54:33]
  • 评测
  • 测评结果:20
  • 用时:186ms
  • 内存:66040kb
  • [2024-09-11 16:54:33]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
mt19937_64 rng(20210448);
int n,q;
vector<int> G[200200];
int siz[200200],son[200200],in[200200],out[200200],dfn,tp[200200],low[200200],p[200200];
void dfs(int u)
{
	siz[u]=1;
	for(auto v:G[u])
	{
		dfs(v);
		if(siz[v]>siz[son[u]])
			son[u]=v;
		siz[u]+=siz[v];
	}
}
void dfs2(int u)
{
	in[u]=++dfn;
	if(!tp[u]) tp[u]=u;
	low[tp[u]]=u;
	if(son[u])
	{
		tp[son[u]]=tp[u];
		dfs2(son[u]);
	}
	for(auto v:G[u])
		if(v!=son[u])
			dfs2(v);
	out[u]=dfn;
}
ll a[200200],b[200200],f[200200],sta[200200];
int ls[200200],rs[200200];
ll sb[200200],lim[200200];
ull prior[200200];
void pushup(int x)
{
	sb[x]=b[x]+sb[ls[x]]+sb[rs[x]];
	lim[x]=min({rs[x]?lim[rs[x]]:1ll*inf*inf,f[x]+1+sb[rs[x]],ls[x]?(lim[ls[x]]+b[x]+sb[rs[x]]):1ll*inf*inf});
}
ll query(int x,ll f)
{
	if(rs[x]&&lim[rs[x]]<=f)
		return query(rs[x],f);
	if(f>::f[x]+sb[rs[x]])
		return f-sb[rs[x]];
	if(!ls[x]) return f-sb[rs[x]]-b[x];
	return query(ls[x],f-sb[rs[x]]-b[x]);
}
int merge(int x,int y)
{
	if(!x||!y) return x+y;
	if(prior[x]>prior[y])
	{
		rs[x]=merge(rs[x],y);
		pushup(x);
		return x;
	}
	else
	{
		ls[y]=merge(x,ls[y]);
		pushup(y);
		return y;
	}
}
void split(int x,ll v,int nd,int &a,int &b)
{
	if(!x)
	{
		a=b=0;
		return ;
	}
	if(f[x]<v||(f[x]==v&&x<nd))
	{
		a=x;
		split(rs[x],v,nd,rs[a],b);
		pushup(a);
	}
	else
	{
		b=x;
		split(ls[x],v,nd,a,ls[b]);
		pushup(b);
	}
}
struct info_t
{
	ll Lim,A,B;
	info_t(){}
	info_t(ll _Lim,ll _A,ll _B):Lim(_Lim),A(_A),B(_B){}
	const inline friend info_t operator +(const info_t &a,const info_t &b)
	{
		return info_t(b.Lim,b.A>=a.Lim?a.B:a.A,b.B>=a.Lim?a.B:a.A);
	}
	inline ll get(ll x){return x>=Lim?B:A;}
};
info_t segt[200200<<2];
#define ls (x<<1)
#define rs (ls|1)
void update(int x,int l,int r,int p,info_t info)
{
	if(l==r)
	{
		segt[x]=info;
		return ;
	}
	int mid=(l+r)/2;
	if(p<=mid)
		update(ls,l,mid,p,info);
	else
		update(rs,mid+1,r,p,info);
	segt[x]=segt[ls]+segt[rs];
}
ll query(int x,int l,int r,int ql,int qr,ll v)
{
	if(l==ql&&r==qr)
		return segt[x].get(v);
	int mid=(l+r)/2;
	if(qr<=mid)
		return query(ls,l,mid,ql,qr,v);
	if(ql>mid)
		return query(rs,mid+1,r,ql,qr,v);
	return query(ls,l,mid,ql,mid,query(rs,mid+1,r,mid+1,qr,v));
}
#undef ls
#undef rs
int rt[200200];
void dfs3(int u)
{
	sta[u]=a[u];
	for(auto v:G[u])
	{
		dfs3(v);
		if(v!=son[u])
		{
			sta[u]+=b[v];
			prior[v]=rng();
			sb[v]=b[v];
			lim[v]=f[v]+1;
			int A,B;
			split(rt[u],f[v],v,A,B);
			rt[u]=merge(A,merge(v,B));
		}
	}
	if(!son[u])
	{
		f[u]=a[u];
		update(1,1,n,in[u],info_t(0,a[u],a[u]));
		return ;
	}
	ll f1=query(rt[u],sta[u]);
	ll f2=query(rt[u],sta[u]+b[son[u]]);
	update(1,1,n,in[u],info_t(f2,f2,f1));
	f[u]=(f[son[u]]>=f2?f1:f2);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=2;i<=n;i++)
	{
		cin>>p[i];
		G[p[i]].pb(i);
	}
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	dfs(1);
	dfs2(1);
	dfs3(1);
	while(q--)
	{
		int op;
		cin>>op;
		if(op==1)
		{
			int x,y,z;
			cin>>x>>y>>z;
			sta[x]-=a[x]-y;
			a[x]=y;
			if(!son[x])
			{
				f[x]=a[x];
				update(1,1,n,in[x],info_t(0,a[x],a[x]));
			}
			else
			{
				ll f1=query(rt[x],sta[x]);
				ll f2=query(rt[x],sta[x]+b[son[x]]);
				update(1,1,n,in[x],info_t(f2,f2,f1));
				f[x]=(f[son[x]]>=f2?f1:f2);
			}
			if(x!=tp[x])
			{
				b[x]=z;
				int x2=p[x];
				ll f1=query(rt[x2],sta[x2]);
				ll f2=query(rt[x2],sta[x2]+b[x]);
				update(1,1,n,in[x2],info_t(f2,f2,f1));
				f[x2]=(f[x]>=f2?f1:f2);
			}
			int xx=x;
			while(x)
			{
				int y=tp[x];
				if(p[y])
				{
					int A,B,C;
					split(rt[p[y]],f[y],y,A,B);
					split(B,f[y],y+1,B,C);
					rt[p[y]]=merge(A,C);
				}
				f[y]=query(1,1,n,in[y],in[low[y]],0);
				if(!p[y]) break;
				if(y==xx) b[y]=z;
				int A,B;
				split(rt[p[y]],f[y],y,A,B);
				rt[p[y]]=merge(A,merge(y,B));
				x=p[y];
			}
		}
		else
		{
			int c,d;
			cin>>c>>d;
			ll fc=query(1,1,n,in[c],in[low[tp[c]]],0);
			ll fd=query(1,1,n,in[d],in[low[tp[d]]],0);
			if(mp(fc,c)>mp(fd,d))
				cout<<"0\n";
			else
				cout<<"1\n";
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 17956kb

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:

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

result:

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

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: 20
Accepted

Test #26:

score: 20
Accepted
time: 49ms
memory: 11908kb

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
1
0
1
1
0
1
0
0
1
1
1
0
1
0
0
0
1
0
1
1
0
0
0
1
1
1
0
0
1
1
1
0
1
0
0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
0
0
1
0
1
0
0
1
1
1
1
1
1
1
0
0
0
1
0
0
1
0
0
1
1
1
1
1
0
1
1
0
1
0
0
0
0
0
0
0
0
0
1
0
1
1
1
1
1
0
0
0
0
1
1
1
0
1
0
1
1
1
0
0
1
1
0
1
0
0
1
0
0
0
0
1
0
1
1
1
0
1
1
1
0
...

result:

ok 100455 numbers

Test #27:

score: 20
Accepted
time: 53ms
memory: 16004kb

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:

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

result:

ok 99902 numbers

Test #28:

score: 20
Accepted
time: 64ms
memory: 16320kb

input:

2000 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 ...

output:

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

result:

ok 99882 numbers

Test #29:

score: 20
Accepted
time: 81ms
memory: 19852kb

input:

20000 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...

output:

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

result:

ok 100151 numbers

Test #30:

score: 20
Accepted
time: 186ms
memory: 66024kb

input:

200000 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 9...

output:

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

result:

ok 100291 numbers

Test #31:

score: 20
Accepted
time: 186ms
memory: 66040kb

input:

200000 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 9...

output:

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

result:

ok 100358 numbers

Test #32:

score: 20
Accepted
time: 169ms
memory: 63944kb

input:

200000 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 9...

output:

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

result:

ok 66538 numbers

Subtask #6:

score: 0
Skipped

Dependency #1:

0%