Submission #126596

# Submission time Handle Problem Language Result Execution time Memory
126596 2019-07-08T07:21:05 Z zozder Wall (IOI14_wall) C++14
100 / 100
696 ms 107384 KB
#include "wall.h"
#include <iostream>
#include <cmath>
#define inf 10000000
#define maxn 4*2000000+5
using namespace std;

int ans[2000005];

struct Tree{
	int mn,mx;
}tree[maxn];

void pushdown(int p)
{
	int sl = 2*p , sr = 2*p+1;
	if(tree[p].mx!=0)//max
	{
		int t = tree[p].mx;
		tree[p].mx = 0;
		tree[sl].mx = max(tree[sl].mx, t);
		tree[sl].mn = max(tree[sl].mn, t);
		tree[sr].mx = max(tree[sr].mx, t);
		tree[sr].mn = max(tree[sr].mn, t);
	}
	if(tree[p].mn!=inf)//min
	{
		int t = tree[p].mn;
		tree[p].mn = inf;
		tree[sl].mx = min(tree[sl].mx, t);
		tree[sl].mn = min(tree[sl].mn, t);
		tree[sr].mx = min(tree[sr].mx, t);
		tree[sr].mn = min(tree[sr].mn, t);
	}
}

void update(int p, int l, int r, int x, int y, int op, int h)
{
	int sl=2*p,sr=2*p+1;
//	cout<<p<<endl;
//	cout<<x<<","<<y<<","<<l<<","<<r<<","<<op<<","<<h<<endl;
	if(x<=l&&r<=y)
	{
//		cout<<x<<","<<y<<","<<l<<","<<r<<","<<op<<","<<h<<endl;
		if(op==1)
		{
			tree[p].mx=max(tree[p].mx, h);
			tree[p].mn=max(tree[p].mn, h);
		}
		if(op==2)
		{
			tree[p].mx=min(tree[p].mx, h);
			tree[p].mn=min(tree[p].mn, h);
		}
//		cout<<p<<","<<tree[p].mx<<","<<tree[p].mn<<","<<h<<endl;
//		cout<<"-------"<<endl;
	}
	else
	{
		pushdown(p);
		if(x<=(l+r)/2)update(sl, l, (l+r)/2, x, y, op, h);
		if((l+r)/2<y)update(sr, (l+r)/2+1, r, x, y, op, h);
	}
}

void put_tree(int p, int l, int r)
{
//	cout<<"l:"<<l<<","<<"r:"<<r<<endl;
	if(l==r)ans[l]=tree[p].mx;
	else
	{
		pushdown(p);
		put_tree(2*p, l, (l+r)/2);
		put_tree(2*p+1, (l+r)/2+1, r);
	}
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
	for(int i=0;i<maxn;i++)
	{
		tree[i].mx=0;
		tree[i].mn=inf;
	}
	
	for(int i=0;i<k;i++)
	{
//		cout<<"time:"<<i+1<<",op:"<<op[i]<<endl;
		update(1,0,n-1,left[i],right[i],op[i],height[i]);
	}
	
	put_tree(1,0,n-1);
	
	for(int i=0;i<n;i++)finalHeight[i]=ans[i];
}
# Verdict Execution time Memory Grader output
1 Correct 56 ms 62968 KB Output is correct
2 Correct 69 ms 63096 KB Output is correct
3 Correct 60 ms 62968 KB Output is correct
4 Correct 61 ms 63224 KB Output is correct
5 Correct 59 ms 63352 KB Output is correct
6 Correct 59 ms 63224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 62968 KB Output is correct
2 Correct 222 ms 76536 KB Output is correct
3 Correct 238 ms 70264 KB Output is correct
4 Correct 561 ms 81416 KB Output is correct
5 Correct 343 ms 82504 KB Output is correct
6 Correct 329 ms 80888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 62948 KB Output is correct
2 Correct 56 ms 63096 KB Output is correct
3 Correct 63 ms 62944 KB Output is correct
4 Correct 60 ms 63224 KB Output is correct
5 Correct 58 ms 63200 KB Output is correct
6 Correct 59 ms 63224 KB Output is correct
7 Correct 64 ms 62968 KB Output is correct
8 Correct 235 ms 76840 KB Output is correct
9 Correct 236 ms 70264 KB Output is correct
10 Correct 563 ms 81356 KB Output is correct
11 Correct 346 ms 82580 KB Output is correct
12 Correct 328 ms 80888 KB Output is correct
13 Correct 53 ms 62968 KB Output is correct
14 Correct 229 ms 76664 KB Output is correct
15 Correct 85 ms 64248 KB Output is correct
16 Correct 631 ms 81784 KB Output is correct
17 Correct 331 ms 81216 KB Output is correct
18 Correct 330 ms 81280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 62968 KB Output is correct
2 Correct 57 ms 63100 KB Output is correct
3 Correct 61 ms 62968 KB Output is correct
4 Correct 70 ms 63224 KB Output is correct
5 Correct 68 ms 63260 KB Output is correct
6 Correct 58 ms 63224 KB Output is correct
7 Correct 54 ms 62916 KB Output is correct
8 Correct 223 ms 76664 KB Output is correct
9 Correct 237 ms 70136 KB Output is correct
10 Correct 571 ms 81528 KB Output is correct
11 Correct 342 ms 82424 KB Output is correct
12 Correct 324 ms 81064 KB Output is correct
13 Correct 65 ms 62968 KB Output is correct
14 Correct 244 ms 76664 KB Output is correct
15 Correct 88 ms 64248 KB Output is correct
16 Correct 624 ms 81912 KB Output is correct
17 Correct 337 ms 81144 KB Output is correct
18 Correct 352 ms 81272 KB Output is correct
19 Correct 696 ms 107252 KB Output is correct
20 Correct 673 ms 104840 KB Output is correct
21 Correct 686 ms 107140 KB Output is correct
22 Correct 673 ms 104696 KB Output is correct
23 Correct 674 ms 104696 KB Output is correct
24 Correct 673 ms 104696 KB Output is correct
25 Correct 670 ms 104824 KB Output is correct
26 Correct 682 ms 107384 KB Output is correct
27 Correct 683 ms 107212 KB Output is correct
28 Correct 670 ms 104616 KB Output is correct
29 Correct 674 ms 104824 KB Output is correct
30 Correct 689 ms 104792 KB Output is correct