Submission #164264

# Submission time Handle Problem Language Result Execution time Memory
164264 2019-11-18T21:15:24 Z kostia244 Wall (IOI14_wall) C++17
Compilation error
0 ms 0 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;
}
node tree[8000100];
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[]) {
	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;
}

Compilation message

Compilation timeout while compiling wall