답안 #385363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385363 2021-04-04T06:05:56 Z alireza_kaviani 벽 (IOI14_wall) C++11
100 / 100
1139 ms 140396 KB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;

typedef pair<int, int> pii;

#define X			first
#define Y			second
#define lc			id << 1
#define rc			lc | 1

const int MAXN = 2e6 + 10;
const int MOD = 1e9 + 7;

int N , ans[MAXN] , mx[MAXN << 2] , mn[MAXN << 2];
pii lz[MAXN << 2];

void apply(int id , pii val){
	mx[id] = max(mx[id] , val.X); mx[id] = min(mx[id] , val.Y);
	mn[id] = max(mn[id] , val.X); mn[id] = min(mn[id] , val.Y);
	if(val.X >= lz[id].Y)	lz[id] = {val.X , val.X};
	else	lz[id].X = max(lz[id].X , val.X);
	lz[id].Y = min(lz[id].Y , val.Y);
}

void minimize(int ql , int qr , int x , int id = 1 , int l = 0 , int r = N){
	if(qr <= l || r <= ql)	return;
	if(ql <= l && r <= qr){
		apply(id , {0 , x});
		return;
	}
	apply(lc , lz[id]);
	apply(rc , lz[id]); lz[id] = {0 , MOD};
	int mid = l + r >> 1;
	minimize(ql , qr , x , lc , l , mid);
	minimize(ql , qr , x , rc , mid , r);
	mn[id] = min(mn[lc] , mn[rc]);
	mx[id] = max(mx[lc] , mx[rc]);
}

void maximize(int ql , int qr , int x , int id = 1 , int l = 0 , int r = N){
	if(qr <= l || r <= ql)	return;
	if(ql <= l && r <= qr){
		apply(id , {x , MOD});
		return;
	}
	apply(lc , lz[id]);
	apply(rc , lz[id]); lz[id] = {0 , MOD};
	int mid = l + r >> 1;
	maximize(ql , qr , x , lc , l , mid);
	maximize(ql , qr , x , rc , mid , r);
	mn[id] = min(mn[lc] , mn[rc]);
	mx[id] = max(mx[lc] , mx[rc]);
}

void solve(int id = 1 , int l = 0 , int r = N){
	if(r - l == 1){
//		cout << mx[id] << ' ' << mn[id] << endl;
		ans[l] = mx[id];
		return;
	}
	apply(lc , lz[id]);
	apply(rc , lz[id]);
	int mid = l + r >> 1;
	solve(lc , l , mid);
	solve(rc , mid , r);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	fill(lz , lz + MAXN * 4 , pii(0 , MOD)); N = n;
	for(int i = 0 ; i < k ; i++){
		if(op[i] == 1){
			maximize(left[i] , right[i] + 1 , height[i]);
		}
		if(op[i] == 2){
			minimize(left[i] , right[i] + 1 , height[i]);
		}
	}
	solve();
	for(int i = 0 ; i < n ; i++)	finalHeight[i] = ans[i];
	return;
}

Compilation message

wall.cpp: In function 'void minimize(int, int, int, int, int, int)':
wall.cpp:34:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |  int mid = l + r >> 1;
      |            ~~^~~
wall.cpp: In function 'void maximize(int, int, int, int, int, int)':
wall.cpp:49:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |  int mid = l + r >> 1;
      |            ~~^~~
wall.cpp: In function 'void solve(int, int, int)':
wall.cpp:64:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |  int mid = l + r >> 1;
      |            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 62956 KB Output is correct
2 Correct 42 ms 63084 KB Output is correct
3 Correct 42 ms 63084 KB Output is correct
4 Correct 47 ms 63596 KB Output is correct
5 Correct 54 ms 63596 KB Output is correct
6 Correct 46 ms 63596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 62956 KB Output is correct
2 Correct 201 ms 76604 KB Output is correct
3 Correct 275 ms 70988 KB Output is correct
4 Correct 771 ms 83472 KB Output is correct
5 Correct 471 ms 84660 KB Output is correct
6 Correct 458 ms 82924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 62956 KB Output is correct
2 Correct 40 ms 63104 KB Output is correct
3 Correct 40 ms 63084 KB Output is correct
4 Correct 48 ms 63596 KB Output is correct
5 Correct 50 ms 63596 KB Output is correct
6 Correct 44 ms 63596 KB Output is correct
7 Correct 38 ms 62956 KB Output is correct
8 Correct 206 ms 76652 KB Output is correct
9 Correct 272 ms 70764 KB Output is correct
10 Correct 765 ms 83436 KB Output is correct
11 Correct 455 ms 84588 KB Output is correct
12 Correct 455 ms 82980 KB Output is correct
13 Correct 43 ms 62956 KB Output is correct
14 Correct 204 ms 76780 KB Output is correct
15 Correct 76 ms 64748 KB Output is correct
16 Correct 835 ms 83692 KB Output is correct
17 Correct 464 ms 83180 KB Output is correct
18 Correct 460 ms 83180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 62956 KB Output is correct
2 Correct 38 ms 63084 KB Output is correct
3 Correct 40 ms 63084 KB Output is correct
4 Correct 44 ms 63596 KB Output is correct
5 Correct 42 ms 63616 KB Output is correct
6 Correct 43 ms 63596 KB Output is correct
7 Correct 40 ms 62956 KB Output is correct
8 Correct 198 ms 76652 KB Output is correct
9 Correct 266 ms 70784 KB Output is correct
10 Correct 785 ms 83516 KB Output is correct
11 Correct 471 ms 84588 KB Output is correct
12 Correct 474 ms 82924 KB Output is correct
13 Correct 35 ms 62956 KB Output is correct
14 Correct 197 ms 76652 KB Output is correct
15 Correct 75 ms 64748 KB Output is correct
16 Correct 857 ms 83728 KB Output is correct
17 Correct 464 ms 83180 KB Output is correct
18 Correct 463 ms 83180 KB Output is correct
19 Correct 1092 ms 140052 KB Output is correct
20 Correct 1087 ms 137708 KB Output is correct
21 Correct 1090 ms 140280 KB Output is correct
22 Correct 1076 ms 137580 KB Output is correct
23 Correct 1079 ms 137708 KB Output is correct
24 Correct 1084 ms 137620 KB Output is correct
25 Correct 1100 ms 137576 KB Output is correct
26 Correct 1139 ms 140296 KB Output is correct
27 Correct 1092 ms 140396 KB Output is correct
28 Correct 1119 ms 137708 KB Output is correct
29 Correct 1091 ms 137544 KB Output is correct
30 Correct 1102 ms 137712 KB Output is correct