Submission #799695

# Submission time Handle Problem Language Result Execution time Memory
799695 2023-07-31T20:30:31 Z IvanJ Wall (IOI14_wall) C++17
100 / 100
1388 ms 102408 KB
#include "wall.h"
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

struct Seg {
	int pot;
	vector<ii> T, L;
	void init(int n) {
		pot = 1;
		while(pot < n) pot <<= 1;
		T = vector<ii>(pot << 1, {0, 1e5});
		L = vector<ii>(pot << 1, {0, 1e5});
	}
	
	ii merge(ii f, ii g) {
		ii ret;
		if(g.x >= f.y) return {f.y, f.y};
		if(g.y <= f.x) return {f.x, f.x};
		return {max(g.x, f.x), min(g.y, f.y)};
	}
	
	void prop(int x) {
		T[x] = merge(L[x], T[x]);
		if(x < pot) L[x * 2] = merge(L[x], L[x * 2]);
		if(x < pot) L[x * 2 + 1] = merge(L[x], L[x * 2 + 1]);
		L[x] = {0, 1e5};
	}
	
	void update(int x, int lo, int hi, int a, int b, ii f) {
		prop(x);
		if(hi < a || b < lo) return;
		if(a <= lo && hi <= b) {
			L[x] = merge(f, L[x]);
			prop(x);
			return;
		}
		int mid = (lo + hi) / 2;
		update(x * 2, lo, mid, a, b, f);
		update(x * 2 + 1, mid + 1, hi, a, b, f);
	}
	
	void add(int lo, int hi, ii f) {update(1, 0, pot - 1, lo, hi, f);}
	
	int get(int x) {return T[x + pot].x;}
} S;

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	S.init(n);
	for(int i = 0;i < k;i++) {
		if(op[i] == 1) 
			S.add(left[i], right[i], {height[i], 1e5});
		if(op[i] == 2) 
			S.add(left[i], right[i], {0, height[i]});
	}
	for(int i = 0;i < n;i++) 
		S.add(i, i, {0, 1e5});
	for(int i = 0;i < n;i++) 
		finalHeight[i] = S.get(i);
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 9 ms 1028 KB Output is correct
5 Correct 7 ms 1008 KB Output is correct
6 Correct 8 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 104 ms 13900 KB Output is correct
3 Correct 175 ms 8420 KB Output is correct
4 Correct 508 ms 22416 KB Output is correct
5 Correct 304 ms 23500 KB Output is correct
6 Correct 296 ms 21856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 10 ms 980 KB Output is correct
5 Correct 10 ms 1104 KB Output is correct
6 Correct 7 ms 1032 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 102 ms 13816 KB Output is correct
9 Correct 168 ms 8432 KB Output is correct
10 Correct 511 ms 22328 KB Output is correct
11 Correct 302 ms 23440 KB Output is correct
12 Correct 292 ms 21856 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 108 ms 13892 KB Output is correct
15 Correct 41 ms 2528 KB Output is correct
16 Correct 709 ms 22704 KB Output is correct
17 Correct 311 ms 22040 KB Output is correct
18 Correct 316 ms 22080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 312 KB Output is correct
4 Correct 9 ms 980 KB Output is correct
5 Correct 7 ms 980 KB Output is correct
6 Correct 7 ms 980 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 108 ms 13916 KB Output is correct
9 Correct 183 ms 8524 KB Output is correct
10 Correct 508 ms 22356 KB Output is correct
11 Correct 298 ms 23532 KB Output is correct
12 Correct 291 ms 21856 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 108 ms 13844 KB Output is correct
15 Correct 41 ms 2520 KB Output is correct
16 Correct 703 ms 22612 KB Output is correct
17 Correct 312 ms 22084 KB Output is correct
18 Correct 312 ms 22040 KB Output is correct
19 Correct 1386 ms 102252 KB Output is correct
20 Correct 1356 ms 99980 KB Output is correct
21 Correct 1341 ms 102280 KB Output is correct
22 Correct 1332 ms 99752 KB Output is correct
23 Correct 1353 ms 99844 KB Output is correct
24 Correct 1351 ms 99756 KB Output is correct
25 Correct 1351 ms 99728 KB Output is correct
26 Correct 1344 ms 102408 KB Output is correct
27 Correct 1342 ms 102284 KB Output is correct
28 Correct 1347 ms 99716 KB Output is correct
29 Correct 1388 ms 99828 KB Output is correct
30 Correct 1363 ms 99848 KB Output is correct