QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#341248#8222. 投票游戏Larunatrecy0 443ms26180kbC++142.9kb2024-02-29 16:52:272024-02-29 16:52:27

Judging History

This is the latest submission verdict.

  • [2024-02-29 16:52:27]
  • Judged
  • Verdict: 0
  • Time: 443ms
  • Memory: 26180kb
  • [2024-02-29 16:52:27]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+(c^48);
	x=(f?-x:x);
}
const int N = 2e5+7;
typedef long long LL;
#define PII pair<LL,int>
#define mk(x,y) make_pair(x,y)
#define X(x) x.first
#define Y(x) x.second
struct node
{
	PII val;
	LL sum,w,mn;
	int l,r,key,siz;
	#define siz(x) tr[x].siz
	#define l(x) tr[x].l
	#define r(x) tr[x].r
	#define key(x) tr[x].key
	#define sum(x) tr[x].sum
	#define w(x) tr[x].w
	#define mn(x) tr[x].mn
	#define val(x) tr[x].val
}tr[N];
int namestk[N],top=0,idx=0;
int getname()
{
	if(top)return namestk[top--];
	return ++idx;
}
void pushup(int k)
{
	sum(k)=sum(l(k))+sum(r(k))+w(k);
	siz(k)=siz(l(k))+siz(r(k))+1;
	mn(k)=val(k).first+sum(l(k));
	if(l(k))mn(k)=min(mn(k),mn(l(k)));
	if(r(k))mn(k)=min(mn(k),sum(l(k))+w(k)+mn(r(k))); 
}
int Merge(int x,int y)
{
    if(!x||!y)return x+y;
    if(key(x)<key(y))
    {
        r(x)=Merge(r(x),y);
        pushup(x);
        return x;
    }
    l(y)=Merge(x,l(y));
    pushup(y);
    return y;
}
void Split(int k,PII v,int &x,int &y)
{
    if(!k)
    {
        x=y=0;
        return;
    }
    if(val(k)>=v)
    {
        x=k;
        Split(r(k),v,r(k),y);
    }
    else
    {
        y=k;
        Split(l(k),v,x,l(k));
    }
    pushup(k);
}
int Locate(int k,LL lim,LL pre)
{
	if(!k)return 0;
	if(l(k)&&lim>mn(l(k))+pre)return Locate(l(k),lim,pre);
	if(lim>val(k).first+sum(l(k))+pre) return sum(l(k));
	return Locate(r(k),lim,pre+sum(l(k))+w(k))+sum(l(k))+w(k);
}
int n,m,fa[N];
LL a[N],b[N];
LL dp[N];
vector<int> G[N];
int rot[N];
void ins(int x,int y)
{
	int u=getname();
	siz(u)=1;
	l(u)=r(u)=0;
	sum(u)=w(u)=b[y];
	val(u)=mk(dp[y],y);
	mn(u)=dp[y];
	key(u)=rand();	
	int A,B;
	Split(rot[x],val(u),A,B);
	rot[x]=Merge(Merge(A,u),B);
}
void del(int x,int y)
{
	PII v=mk(dp[y],y);
	int A,B,C;
	Split(rot[x],v,A,B);
	v.first++;
	Split(A,v,A,C);
	namestk[++top]=C;
	rot[x]=Merge(A,B);
}
LL S[N];
void dfs(int x)
{
	if(G[x].empty())
	{
		dp[x]=a[x];
		return;
	}
	for(int y:G[x])
	{
		dfs(y);
		ins(x,y);
	}
	LL val=Locate(rot[x],a[x]+S[x],0);
	dp[x]=a[x]+S[x]-val;
}
int main()
{
	read(n);read(m);
	for(int i=2;i<=n;i++)read(fa[i]),G[fa[i]].push_back(i);
	for(int i=1;i<=n;i++)read(a[i]);
	for(int i=1;i<=n;i++)read(b[i]),S[fa[i]]+=b[i];
	dfs(1);
	while(m--)
	{
		int op,x,A,B;
		read(op);
		if(op==1)
		{
			read(x);read(A);read(B);
			a[x]=A;b[x]=B;
			while(x)
			{
				if(fa[x])del(fa[x],x);
				LL val=Locate(rot[x],a[x]+S[x],0);
				dp[x]=a[x]+S[x]-val;
				if(fa[x])ins(fa[x],x);
				x=fa[x];
			}
		}
		else 
		{
			read(A);read(B);
			if(mk(dp[A],A)>mk(dp[B],B))printf("0\n");
			else printf("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: 20864kb

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
1
0
0
0
0
1
1
0
1
0
0
0
1
0
1
1
0
0
1
0
0
0
0
0
1
1
1
1
1
1
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
1
0
0
0
0
1
0
1
1
0
0
1
0
0
0
1
0
1
1
0
0
0
1
1
1
1
0
0
1
0
1
0
1
1
0
0
0
1
0
0
0
0
0
1
1
0
1
0
0
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 12th numbers differ - expected: '0', found: '1'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 30ms
memory: 20452kb

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:

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

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #18:

score: 25
Accepted
time: 16ms
memory: 21092kb

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:

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

result:

ok 99788 numbers

Test #19:

score: 0
Accepted
time: 72ms
memory: 19344kb

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

result:

ok 100002 numbers

Test #21:

score: 0
Accepted
time: 135ms
memory: 21532kb

input:

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

output:

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

result:

ok 99886 numbers

Test #22:

score: 0
Accepted
time: 394ms
memory: 26144kb

input:

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

output:

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

result:

ok 100006 numbers

Test #23:

score: -25
Wrong Answer
time: 443ms
memory: 26180kb

input:

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

output:

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

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #26:

score: 0
Wrong Answer
time: 271ms
memory: 19712kb

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

result:

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

Subtask #6:

score: 0
Skipped

Dependency #1:

0%