답안 #171230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171230 2019-12-27T20:25:15 Z CaroLinda 벽 (IOI14_wall) C++14
100 / 100
1837 ms 262144 KB
	#include "wall.h"
	#include <bits/stdc++.h>

	#define debug printf
	#define lp(i,a,b) for(int i = a ; i < b ; i++ )
	#define ff first
	#define ss second
	#define pb push_back
	#define mk make_pair
	#define ll long long
	#define sz size()
	#define pii pair<int,int>
	#define all(x) x.begin(),x.end()
	#define tiii tuple<int,int,int, int>
	#define mkt make_tuple

	const int MAXN = 2e6+10 , inf = 2e9+10 ;

	using namespace std ;

	struct Seg
	{

		struct Node
		{

			int lef , rig, mxLef , mnRig ;
			bool locked ;

			Node() 
			{
				lef = mxLef =-inf , rig = mnRig =  inf ;
				locked = false ;
			}

		} ;

		Node tree[MAXN*4] ;

		int m(int l, int r) { return (l+r)>>1 ; }

		void merge(int pos, int l, int r)
		{

			tree[pos].mxLef = tree[pos].lef ;
			tree[pos].mnRig =tree[pos].rig ;

			if( l == r ) return ;

			tree[pos].mxLef = max(tree[pos].mxLef, max( tree[pos*2].mxLef, tree[pos*2+1].mxLef ) ) ;
			tree[pos].mnRig = min( tree[pos].mnRig , min(tree[pos*2].mnRig, tree[pos*2+1].mnRig )) ;

		}

		void check(int pos, int l, int r, int curL, int curR , vector<int> &List )
		{

			if( tree[pos].locked ) return ;

			curL = max( curL, tree[pos].lef ) ;
			curR = min( curR, tree[pos].rig ) ;

			if( tree[pos].mnRig >= curL && tree[pos].mxLef <= curR && curL <= curR )
				return ;

			if( l == r ) 
			{
				List.pb(l) ;
				tree[pos].locked = true ;
				tree[pos].lef = -inf ;
				tree[pos].rig = inf ;
				return ;
			}

			check(pos*2,l,m(l,r), curL, curR , List ) ;
			check(pos*2+1,m(l,r)+1, r, curL, curR, List ) ;

			if( tree[pos*2].locked && tree[pos*2+1].locked )
			{
				tree[pos].locked = true ;
				tree[pos].lef = -inf ;
				tree[pos].rig = inf ;
			}

		}

		void upd(int pos, int l, int r, int beg, int en ,int num, int type, int curL, int curR, vector<int> &v )
		{
			if( tree[pos].locked || r < beg || l > en ) return ;

			curL = max(curL, tree[pos].lef ) ;
			curR = min( curR, tree[pos].rig ) ;
			if( l >= beg && r <= en )
			{
				if( type == 1 ) tree[pos].lef = max( tree[pos].lef, num ) ;
				else tree[pos].rig = min( tree[pos].rig, num ) ;
				merge(pos,l,r) ;
				check(pos,l,r,curL,curR, v) ;
				return ;
			}

			upd(pos*2,l,m(l,r),beg, en, num ,type, curL, curR,v) ;
			upd(pos*2+1,m(l,r)+1, r, beg, en , num , type , curL, curR,v ) ;

			merge(pos,l,r) ;

		}

		void print(int pos, int l, int r , int curL, int curR ) 
		{
			curL = max(curL, tree[pos].lef ) ;
			curR =min(curR, tree[pos].rig) ;
			if( l == r ) return (void)( printf("%d -> %d %d\n" , l , curL, curR ) ) ;
			print(pos*2,l,m(l,r), curL, curR) ;
			print(pos*2+1,m(l,r)+1, r, curL, curR ) ;

		}

	} ;

	struct secondSeg
	{

		struct Node
		{

			int lef, rig ;

			Node() { lef = -inf , rig = inf ; }

		} ;

		Node v[MAXN*4] ;

		int m(int l, int r) { return (l+r)>>1 ; }

		void upd(int pos, int l, int r, int beg, int en,int num, int type )
		{

			if( l > en || r < beg ) return ;
			if( l >= beg && r <= en )
			{
				if(type==1) v[pos].lef = max(v[pos].lef, num) ;
				else v[pos].rig = min(v[pos].rig, num) ; 
				return ;
			}

			upd(pos*2,l,m(l,r),beg,en,num,type) ;
			upd(pos*2+1,m(l,r)+1, r, beg, en , num , type ) ;

		}

		void qry(int pos, int l, int r, int &curL, int &curR , int idx )
		{
			curL = max(curL, v[pos].lef ) ;
			curR = min(curR, v[pos].rig ) ;
			if( l == r ) return ;
			if( idx <= m(l,r) ) qry(pos*2,l,m(l,r), curL, curR , idx ) ;
			else qry(pos*2+1, m(l,r)+1, r, curL, curR , idx ) ;
		}

	} ;

	int scramble[MAXN] ;
	pii idx[MAXN] ;
	Seg seg ;
	secondSeg seg2 ;

	void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
	{

		reverse(op,op+k) ;
		reverse(right, right+k) ;
		reverse(left, left+k) ;
		reverse(height, height+k) ;

		vector<int> aux ;
		lp(i,0,n) scramble[i] = inf ;

		lp(i,0,k)
		{

			aux.clear() ;
			seg.upd(1,0,n-1,left[i], right[i] , height[i] , op[i], -inf, inf, aux ) ;
			for(int j : aux ) scramble[j] = i ;
		}

		lp(i,0,n) idx[i] = mk( scramble[i] , i ) ;
		sort(idx, idx+n ) ;

		int curIdx = 0 ;

		lp(i,0,k)
		{

			seg2.upd( 1 , 0 , n-1 , left[i] , right[i] , height[i] , op[i] ) ;
			while(curIdx < n && scramble[ idx[curIdx].ss ] == i+1 )
			{

				int curL = -inf , curR = inf ;
				seg2.qry( 1 , 0 , n-1 , curL , curR , idx[curIdx].ss ) ;
				if( op[i+1] == 1 ) finalHeight[ idx[curIdx].ss ] = curR ;
				else finalHeight[ idx[curIdx].ss ] = max(0,curL) ;

				curIdx ++ ;

			}

		}

		lp(i,0,n)
			if( scramble[i] == inf )
			{
				finalHeight[i] = 0;
				int curR = inf ;
				seg2.qry( 1 , 0 , n-1   , finalHeight[i], curR, i ) ;
			}

		return ;

	}

# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 219512 KB Output is correct
2 Correct 194 ms 219512 KB Output is correct
3 Correct 193 ms 219640 KB Output is correct
4 Correct 198 ms 219872 KB Output is correct
5 Correct 200 ms 219728 KB Output is correct
6 Correct 201 ms 219888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 219464 KB Output is correct
2 Correct 370 ms 227432 KB Output is correct
3 Correct 371 ms 223332 KB Output is correct
4 Correct 1113 ms 229248 KB Output is correct
5 Correct 682 ms 229776 KB Output is correct
6 Correct 670 ms 229852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 219484 KB Output is correct
2 Correct 208 ms 219636 KB Output is correct
3 Correct 214 ms 219640 KB Output is correct
4 Correct 204 ms 219896 KB Output is correct
5 Correct 200 ms 219768 KB Output is correct
6 Correct 202 ms 219816 KB Output is correct
7 Correct 193 ms 219616 KB Output is correct
8 Correct 388 ms 227320 KB Output is correct
9 Correct 362 ms 223244 KB Output is correct
10 Correct 1109 ms 229416 KB Output is correct
11 Correct 707 ms 229808 KB Output is correct
12 Correct 720 ms 229760 KB Output is correct
13 Correct 200 ms 219540 KB Output is correct
14 Correct 382 ms 227448 KB Output is correct
15 Correct 218 ms 220412 KB Output is correct
16 Correct 679 ms 229476 KB Output is correct
17 Correct 640 ms 229488 KB Output is correct
18 Correct 639 ms 229488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 219640 KB Output is correct
2 Correct 193 ms 219640 KB Output is correct
3 Correct 194 ms 219512 KB Output is correct
4 Correct 197 ms 219836 KB Output is correct
5 Correct 201 ms 219856 KB Output is correct
6 Correct 205 ms 219776 KB Output is correct
7 Correct 194 ms 219520 KB Output is correct
8 Correct 363 ms 227320 KB Output is correct
9 Correct 364 ms 223352 KB Output is correct
10 Correct 1093 ms 229392 KB Output is correct
11 Correct 676 ms 229828 KB Output is correct
12 Correct 666 ms 229624 KB Output is correct
13 Correct 193 ms 219512 KB Output is correct
14 Correct 362 ms 227448 KB Output is correct
15 Correct 220 ms 220408 KB Output is correct
16 Correct 685 ms 229592 KB Output is correct
17 Correct 637 ms 229424 KB Output is correct
18 Correct 652 ms 229488 KB Output is correct
19 Correct 1821 ms 262144 KB Output is correct
20 Correct 1795 ms 262144 KB Output is correct
21 Correct 1793 ms 262144 KB Output is correct
22 Correct 1812 ms 262144 KB Output is correct
23 Correct 1788 ms 262144 KB Output is correct
24 Correct 1785 ms 262144 KB Output is correct
25 Correct 1819 ms 262144 KB Output is correct
26 Correct 1802 ms 262144 KB Output is correct
27 Correct 1837 ms 262144 KB Output is correct
28 Correct 1810 ms 262144 KB Output is correct
29 Correct 1815 ms 262144 KB Output is correct
30 Correct 1816 ms 262144 KB Output is correct