QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#595905#8923. За связь без перебоевANIG0 6ms8228kbC++142.2kb2024-09-28 14:44:342024-09-28 14:44:34

Judging History

This is the latest submission verdict.

  • [2024-09-28 14:44:34]
  • Judged
  • Verdict: 0
  • Time: 6ms
  • Memory: 8228kb
  • [2024-09-28 14:44:34]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5,T=350,M=N/T+5;
int n,m,son[N][2],idx,dfn[N],em[N],eds[N],dy[N],siz[N],bh[N],st[N],ed[N],smk[N],smz[N],g1[M][N],g2[M][N],mk[N];
void dfs(int x){
	siz[x]=1;
	dfn[x]=++idx;
	if(son[x][0])dfs(son[x][0]),siz[x]+=siz[son[x][0]];
	em[x]=idx;
	if(son[x][1])dfs(son[x][1]),siz[x]+=siz[son[x][1]];
	eds[x]=idx;
}
void add(int x,int sm){
	smk[bh[x]]+=sm;
	smz[x]+=sm;
}
void add(int l,int r,int sm){
	add(l,sm);
	add(r+1,-sm);
}
int gets(int x){
	int res=0;
	for(int i=1;i<bh[x];i++)res+=smk[i];
	for(int i=st[bh[x]];i<=x;i++)res+=smz[i];
	return res;
}
int solve(int x){
	int res=1+gets(dfn[x]);
	int k=dy[x];
	if(mk[bh[x]]!=2)k=mk[bh[x]];
	if(k==0)res+=siz[son[x][0]];
	if(k==1)res+=siz[son[x][0]]+siz[son[x][1]];
	for(int i=1;i<=bh[n];i++){
		if(mk[i]==2)continue;
		if(mk[i]==-1)res+=g1[i][dfn[x]];
		if(mk[i]==0)res+=g2[i][dfn[x]];
	}
	return res;
}
void upt(int x,int op){
	if(dy[x]==-1)add(dfn[x]+1,eds[x],op);
	if(dy[x]==0)add(em[x]+1,eds[x],op);
}
void Sets(int l,int r,int x){
	int y=bh[l];
	if(mk[y]!=2){
		for(int i=st[y];i<=ed[y];i++)dy[i]=mk[y];
		for(int i=l;i<=r;i++)dy[i]=x;
		for(int i=st[y];i<=ed[y];i++)upt(i,1);
		mk[y]=2;
	}else{
		for(int i=l;i<=r;i++){
			upt(i,-1);
			dy[i]=x;
			upt(i,1);
		}
	}
}
void sets(int l,int r,int x){
	if(bh[l]==bh[r]){
		Sets(l,r,x);
		return;
	}
	int ll=bh[l]+1,rr=bh[r]-1;
	Sets(l,st[ll]-1,x);
	Sets(ed[rr]+1,r,x);
	for(int i=ll;i<=rr;i++){
		if(mk[i]==2)for(int j=st[i];j<=ed[i];j++)upt(j,-1);
		mk[i]=x;
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>son[i][0]>>son[i][1];
		dy[i]=-1;
		bh[i]=(i-1)/T+1;
	}
	for(int i=1;i<=bh[n];i++)mk[i]=2,st[i]=ed[i-1]+1,ed[i]=min(i*T,n);
	dfs(1);
	for(int i=1;i<=n;i++){
		upt(i,1);
		add(em[i]+1,eds[i],siz[son[i][0]]);
		g1[bh[i]][dfn[i]+1]++;
		g1[bh[i]][eds[i]+1]--;
		g2[bh[i]][em[i]+1]++;
		g2[bh[i]][eds[i]+1]--;
	}
	for(int i=1;i<=bh[n];i++){
		for(int j=1;j<=n;j++)g1[i][j]+=g1[i][j-1],g2[i][j]+=g2[i][j-1];
	}
	while(m--){
		int op,l,r,x;
		cin>>op;
		if(op==1){
			cin>>l>>r>>x;
			sets(l,r,x);
		}else{
			cin>>x;
			cout<<solve(x)<<"\n";
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7716kb

input:

1 0
0

output:


result:

wrong output format Unexpected end of file - token expected

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #39:

score: 0
Wrong Answer
time: 6ms
memory: 8196kb

input:

1000000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:


result:

wrong output format Unexpected end of file - token expected

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 0
Wrong Answer
time: 6ms
memory: 8228kb

input:

1000000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:


result:

wrong output format Unexpected end of file - token expected

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Memory Limit Exceeded

Test #74:

score: 0
Memory Limit Exceeded

input:

1000000 0
50003 50006 50006 50003 50005 50010 50006 50007 50002 50000 50005 50003 50002 50005 50000 50008 50010 50008 50007 50000 50003 50001 50008 50005 50002 50005 50006 50001 50002 50009 50006 50007 50010 50008 50000 50005 50006 50006 50003 50001 50000 50008 50000 50003 50008 50009 50006 50000 50...

output:


result:


Subtask #8:

score: 0
Skipped

Dependency #1:

0%