Submission #126541

# Submission time Handle Problem Language Result Execution time Memory
126541 2019-07-08T03:38:03 Z zozder Wall (IOI14_wall) C++14
0 / 100
223 ms 32908 KB
#include "wall.h"
#include <iostream>
using namespace std;

int tree[1000000][6],o;
int ans[2000000];

/*
0	left
1	right
2	left link point
3	right link pint
4	value
5	cut_(mid)_put
*/
void add_tree(int x, int l, int r, int h, int count)
{
	count+=tree[x][4];
	int cutpoint = tree[x][5];
	if(l==tree[x][0]&&r==tree[x][1])
	{
		if(count<h)
		tree[x][4]+=(h-count);
	}
	else if(tree[x][2]!=-1)
	{
		if(cutpoint<l)
		{
			add_tree(tree[x][3], l, r, h, count);
		}
		else if(l<=cutpoint&&cutpoint<r)
		{
			add_tree(tree[x][2], l, cutpoint, h, count);
			add_tree(tree[x][3], cutpoint+1, r, h, count);
		}
		else if(r<=cutpoint)
		{
			add_tree(tree[x][2], l, r, h, count);
		}
	}
	else
	{
		if(l!=tree[x][0]||r!=tree[x][1])
		{
			if(tree[x][0]<l)//xl..l...r...xr
			{
				cutpoint=l-1;
				tree[x][5]=cutpoint;
				o++;//左子樹 
				tree[x][2]=o;
				tree[o][0]=tree[x][0];
				tree[o][1]=cutpoint;
				tree[o][4]=0;
				o++;//右子樹 
				tree[x][3]=o;
				tree[o][0]=cutpoint+1;
				tree[o][1]=tree[x][1];
				tree[o][4]=0;
				add_tree(tree[x][3], l, r, h, count);
			}
			else if(tree[x][1]>r)//xll...r...xr
			{
				cutpoint=r;
				tree[x][5]=cutpoint;
				o++;//左子樹
				tree[x][2]=o;
				tree[o][0]=tree[x][0];
				tree[o][1]=cutpoint;
				tree[o][4]=0;
				add_tree(tree[x][2], l, r, h, count);
				o++;//右子樹
				tree[x][3]=o;
				tree[o][0]=cutpoint+1;
				tree[o][1]=tree[x][1];
				tree[o][4]=0;
			}
			
		}
	}
}

void down_tree(int x, int l, int r, int h, int count)
{
	count+=tree[x][4];//cout<<"x:"<<x<<"\t"<<"count:"<<count<<endl;
	int cutpoint = tree[x][5];
	if(l==tree[x][0]&&r==tree[x][1])
	{
		if(count>h)
		tree[x][4]+=(h-count);
	}
	else if(tree[x][2]!=-1)
	{
		if(cutpoint<l)
		{
			down_tree(tree[x][3], l, r, h, count);
		}
		else if(l<=cutpoint&&cutpoint<r)
		{
			down_tree(tree[x][2], l, cutpoint, h, count);
			down_tree(tree[x][3], cutpoint+1, r, h, count);
		}
		else if(r<=cutpoint)
		{
			down_tree(tree[x][2], l, r, h, count);
		}
	}
	else
	{
		if(l!=tree[x][0]||r!=tree[x][1])
		{
			if(tree[x][0]<l)//xl..l...r...xr
			{
				cutpoint=l-1;
				tree[x][5]=cutpoint;
				o++;//左子樹 
				tree[x][2]=o;
				tree[o][0]=tree[x][0];
				tree[o][1]=cutpoint;
				tree[o][4]=0;
				o++;//右子樹 
				tree[x][3]=o;
				tree[o][0]=cutpoint+1;
				tree[o][1]=tree[x][1];
				tree[o][4]=0;
				down_tree(tree[x][3], l, r, h, count);
			}
			else if(tree[x][1]>r)//xll...r...xr
			{
				cutpoint=r;
				tree[x][5]=cutpoint;
				o++;//左子樹
				tree[x][2]=o;
				tree[o][0]=tree[x][0];
				tree[o][1]=cutpoint;
				tree[o][4]=0;
				down_tree(tree[x][2], l, r, h, count);
				o++;//右子樹
				tree[x][3]=o;
				tree[o][0]=cutpoint+1;
				tree[o][1]=tree[x][1];
				tree[o][4]=0;
			}
		}
	}
}

void pop_tree(int x,int count)
{
	count+=tree[x][4];//cout<<"count:"<<count<<endl;
	if(tree[x][2]!=-1)
	{
		pop_tree(tree[x][2], count);
		pop_tree(tree[x][3], count);
	}
	else
	{
		for(int i=tree[x][0];i<=tree[x][1];i++)ans[i]=count;
	}
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
	for(int i=0;i<999999;i++)
	{
		tree[i][0]=-1;
		tree[i][1]=-1;
		tree[i][2]=-1;
		tree[i][3]=-1;
		tree[i][4]=0;
		tree[i][5]=-1;
	}
	
	tree[1][0]=0;
	tree[1][1]=n-1;
	tree[1][2]=-1;
	tree[1][3]=-1;
	tree[1][4]=0;
	tree[1][5]=-1;
	o=1;
	
	for(int i=0;i<k;i++)
	{
		//1up 2down
		if(op[i]==1)add_tree(1,left[i],right[i],height[i],0);
		else down_tree(1,left[i],right[i],height[i],0);
	}
	
	pop_tree(1,0);
	
	for(int i=0;i<n;i++)finalHeight[i]=ans[i];
/*	
	for(int i=1;i<=o;i++)cout<<i<<"\t";cout<<endl;
	for(int i=1;i<=o;i++)cout<<tree[i][0]<<"\t";cout<<endl;
	for(int i=1;i<=o;i++)cout<<tree[i][1]<<"\t";cout<<endl;
	for(int i=1;i<=o;i++)cout<<tree[i][2]<<"\t";cout<<endl;
	for(int i=1;i<=o;i++)cout<<tree[i][3]<<"\t";cout<<endl;
	for(int i=1;i<=o;i++)cout<<tree[i][4]<<"\t";cout<<endl;
	for(int i=1;i<=o;i++)cout<<tree[i][5]<<"\t";cout<<endl;
*/	
	
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 24 ms 23928 KB Output is correct
3 Incorrect 24 ms 23800 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 186 ms 32908 KB Output is correct
3 Incorrect 223 ms 28768 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23804 KB Output is correct
2 Correct 24 ms 23928 KB Output is correct
3 Incorrect 27 ms 23928 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23776 KB Output is correct
2 Correct 23 ms 23928 KB Output is correct
3 Incorrect 23 ms 23800 KB Output isn't correct
4 Halted 0 ms 0 KB -