답안 #164268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164268 2019-11-18T21:19:56 Z kostia244 벽 (IOI14_wall) C++17
0 / 100
2 ms 256 KB
#include "wall.h"
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
struct node {
	int mn = 2e9, mx = 0, ord = 1;
	void push(int x, int a) {
		if (a == 1) { //mn
			ord = 1;
			mn = min(mn, x);
			mx = min(mx, mn);
		} else {
			ord = 0;
			mx = max(mx, x);
			mn = max(mn, mx);
		}
	}
	int eval() {
		if (ord == 0)
			return max(mn, mx);
		return min(mn, mx);
	}
};
node merge(node a, node b) {
	if (b.ord == 1) {
		a.push(b.mx, 0);
		a.push(b.mn, 1);
	} else {
		a.push(b.mn, 1);
		a.push(b.mx, 0);
	}
	return a;
}
vector<node> tree;
void push(int v, int l, int r) {
	if(l==r) return;
	tree[v<<1] = merge(tree[v<<1], tree[v]);
	tree[v<<1|1] = merge(tree[v<<1|1], tree[v]);
	tree[v] = node();
}
int get(int v, int l, int r, int i) {
	push(v, l, r);
	if (l > i || r < i)
		return 0;
	if (l == r)
		return tree[v].eval();
	int mid = (l + r) >> 1;
	return get(v << 1, l, mid, i) + get(v << 1 | 1, mid + 1, r, i);
}
void upd(int v, int l, int r, int ql, int qr, int x, int a) {
	push(v, l, r);
	if (r < ql || l > qr)
		return;
	if (ql <= l && r <= qr) {
//		cout << l << " " << r << " " << tree[v].eval() << "\n";
		tree[v].push(x, a);
//		cout << l << " " << r << " " << x << " " << a << " " << tree[v].ord << "\n";
		push(v, l, r);
		return;
	}
	int mid = (l + r) >> 1;
	upd(v << 1, l, mid, ql, qr, x, a);
	upd(v << 1 | 1, mid + 1, r, ql, qr, x, a);
}
void buildWall(int n, int k, int op[], int l[], int r[], int h[], int fh[]) {
	tree.resize(4*n + 100);
	for(int i = 0; i < k; i++) {
		upd(1, 0, n-1, l[i], r[i], h[i], (op[i]-1));
//		cout <<"======\n";
	}
	for(int i = 0; i < n; i++)
		fh[i] = get(1, 0, n-1, i);
	return;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -