Submission #294709

# Submission time Handle Problem Language Result Execution time Memory
294709 2020-09-09T08:43:07 Z mieszko11b Wall (IOI14_wall) C++14
0 / 100
253 ms 13944 KB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second

using ii = pair<int, int>;

const int inf = 1e9;
const ii EMPTY = {-inf, inf};

ii merge(ii first, ii second) {
	if(second.first != -inf) {
		ii p = {max(second.X, first.X), first.Y};
		p.Y = max(p.X, p.Y);
		//~ cout << first.X << "," << first.Y << "   " << second.X << "," << second.Y << "   " << p.X << "," << p.Y << endl;
		return p;
	} else {
		ii p = {first.X, min(first.Y, second.Y)};
		p.X = min(p.X, p.Y);
		//~ cout << first.X << "," << first.Y << "   " << second.X << "," << second.Y << "   " << p.X << "," << p.Y << endl;
		return p;
	}
}

int doop(int x, ii op) {
	return min(max(x, op.X), op.Y);
}

struct SegmentTree {
	int lv;
	vector<ii> lazy;
	
	void init(int n) {
		lv = 2;
		while(lv < n)
			lv *= 2;
		lazy.resize(2 * lv + 2, EMPTY);
	}
	
	void push(int w, int l, int r) {
		if(l != r) {
			lazy[2 * w] = merge(lazy[2 * w], lazy[w]);
			lazy[2 * w + 1] = merge(lazy[2 * w + 1], lazy[w]);
			lazy[w] = EMPTY;
		}
	}
	
	void insert(int a, int b, int w, int l, int r, ii op) {
		push(w, l, r);
		if(l > r || l > b || r < a)
			return ;
			
		if(a <= l && r <= b) {
			lazy[w] = merge(lazy[w], op);
			push(w, l, r);
			return ;
		}
		
		insert(a, b, 2 * w, l, (l + r) / 2, op);
		insert(a, b, 2 * w + 1, (l + r) / 2 + 1, r, op);
	}
	
	void insert(int a, int b, ii op) {
		insert(a, b, 1, 0, lv - 1, op);
	}
	
	void push_all(int w, int l, int r) {
		push(w, l, r);
		if(l != r) {
			push_all(2 * w, l, (l + r) / 2);
			push_all(2 * w + 1, (l + r) / 2 + 1, r);
		}
	}
	
	vector<int> calc() {
		vector<int> res;
		res.resize(lv);
		push_all(1, 0, lv - 1);
		
			
		//~ for(int i = 0 ; i < 2 * lv ; i++)
			//~ cout << i << " " << lazy[i].X << " " << lazy[i].Y << endl;
		//~ cout << endl;
		
		for(int i = 0 ; i < lv ; i++)
			res[i] = lazy[lv + i].X;
		return res;
	}
};

SegmentTree ST;

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	ST.init(n);
	for(int i = 0 ; i < k ; i++) {
		if(op[i] == 1)
			ST.insert(left[i], right[i], {height[i], inf});
		else
			ST.insert(left[i], right[i], {-inf, height[i]});
			
		//~ for(int i = 0 ; i < 2 * ST.lv ; i++)
			//~ cout << i << " " << ST.lazy[i].X << " " << ST.lazy[i].Y << endl;
		//~ cout << endl;
	}
	
	vector<int> res = ST.calc();
	for(int i = 0 ; i < n ; i++)
		finalHeight[i] = max(0, res[i]);
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 181 ms 13944 KB Output is correct
3 Incorrect 253 ms 8160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -