답안 #298726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298726 2020-09-13T20:50:59 Z aymanrs 벽 (IOI14_wall) C++14
8 / 100
3000 ms 8312 KB
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#define L(i) i*2+1
#define R(i) i*2+2
using namespace std;
typedef pair<int, int> pii;
pii *tree, *lazy;
pii update(int i, int l, int r, int a, int b, const pii& op){
	if(lazy[i].first != -1){
		tree[i].first = min(max(tree[i].first, lazy[i].first), lazy[i].second);
		tree[i].second = max(min(tree[i].second, lazy[i].second), lazy[i].first);
		if(l != r) {
			lazy[L(i)] = lazy[R(i)] = {tree[i].first, tree[i].second};
		}
		lazy[i] = {-1, -1};
	}
	if(l > b || r < a) return tree[i];
	if(a <= l && r <= b){
		if(op.first == 1){
			tree[i].first = max(tree[i].first, op.second);
			if(tree[i].first > tree[i].second){
				tree[i].second = tree[i].first;
			}
		} else {
			tree[i].second = min(tree[i].second, op.second);
			if(tree[i].first > tree[i].second){
				tree[i].first = tree[i].second;
			}
		}
		if(l != r) lazy[L(i)] = lazy[R(i)] = tree[i];
	}
	if(l != r){
		int mid = (l+r)/2;
		pii left = update(L(i), l, mid, a, b, op), right = update(R(i), mid+1, r, a, b, op);
		tree[i] = {min(left.first, right.first), max(left.second, right.second)};
	}
	return tree[i];
}

void get(int i, int l, int r, int finalHeight[]){
	if(lazy[i].first != -1){
		tree[i].first = min(max(tree[i].first, lazy[i].first), lazy[i].second);
		tree[i].second = max(min(tree[i].second, lazy[i].second), lazy[i].first);
		if(l != r) {
			lazy[L(i)] = lazy[R(i)] = {tree[i].first, tree[i].second};
		}
		lazy[i] = {-1, -1};
	}
	if(l == r){
		finalHeight[l] = tree[i].first;
	} else {
		int mid = (l+r)/2;
		get(L(i), l, mid, finalHeight);
		get(R(i), mid+1, r, finalHeight);
	}
}
void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){
	tree = new pii[4 * n + 10];
	lazy = new pii[4 * n + 10];
	for(int i = 0;i < 4*n+10;i++) {
		lazy[i] = {-1, -1};
		tree[i] = {0, 0};
	}
	for(int i = 0;i < k;i++){
		update(0, 0, n-1, left[i], right[i], {op[i], height[i]});
	}
	get(0, 0, n-1, finalHeight);
	delete[] tree;
	delete[] lazy;
}

Compilation message

wall.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 794 ms 1144 KB Output is correct
5 Correct 793 ms 1144 KB Output is correct
6 Correct 798 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 187 ms 8152 KB Output is correct
3 Execution timed out 3024 ms 4856 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 786 ms 1144 KB Output is correct
5 Correct 799 ms 1148 KB Output is correct
6 Correct 801 ms 1144 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 183 ms 8312 KB Output is correct
9 Execution timed out 3031 ms 4728 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 789 ms 1144 KB Output is correct
5 Correct 792 ms 1144 KB Output is correct
6 Correct 796 ms 1156 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 183 ms 8184 KB Output is correct
9 Execution timed out 3049 ms 4728 KB Time limit exceeded
10 Halted 0 ms 0 KB -