Submission #597712

# Submission time Handle Problem Language Result Execution time Memory
597712 2022-07-16T15:50:36 Z 1ne Wall (IOI14_wall) C++14
100 / 100
1224 ms 87716 KB
#include "wall.h"
#include<bits/stdc++.h>
using namespace std;
struct dataa{
	long long minny = 1e9,maxxy = 0;
	void add(dataa v){
		minny = min(minny,v.minny);
		maxxy = max(maxxy,v.maxxy);
	}
};
long long S,T;
struct Segment_Tree{
	vector<dataa>tree;
	void init(long long n){
		tree.resize(2*n - 1);
	}
	dataa combine(dataa left,dataa right){
		dataa res;
		res.minny = min(left.minny,right.minny);
		res.maxxy = min(left.maxxy,right.maxxy);
		return res;
	}
	void push(long long node,long long left,long long right){
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		tree[node + 1].add(tree[node]);
		tree[z].add(tree[node]);
		tree[node + 1].minny = max(tree[node + 1].minny,tree[node].maxxy);
		tree[z].minny = max(tree[z].minny,tree[node].maxxy);
		tree[node + 1].maxxy = min(tree[node + 1].maxxy,tree[node].minny);
		tree[z].maxxy = min(tree[z].maxxy,tree[node].minny);
	}
	long long query(long long node,long long left,long long right,long long qleft,long long qright){
		if (qright<left|| qleft > right)return 1e9;
		if (qleft<=left && qright>=right){
			return min(tree[node].minny,tree[node].maxxy);
		}
		push(node,left,right);
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		return min(query(node + 1,left,mid,qleft,qright),query(z,mid + 1,right,qleft,qright));
	}
	void update(long long node,long long left,long long right,long long uleft,long long uright,long long h,long long type){
		if (left > uright || right < uleft) return;
		if (uleft <= left && right <=uright){
			if (type == 1){
				tree[node].minny = max(tree[node].minny,h);
				tree[node].maxxy = max(tree[node].maxxy,h);
			}
			else{
				tree[node].minny = min(tree[node].minny,h);
				tree[node].maxxy = min(tree[node].maxxy,h);
			}
			return;
		}
		push(node,left,right);
		tree[node].minny = 1e9;
		tree[node].maxxy = 0;
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		if (uleft<=mid){
			update(node + 1,left,mid,uleft,uright,h,type);
		}
		if (uright > mid){
			update(z,mid + 1,right,uleft,uright,h,type);
		}
		//tree[node] = combine(tree[node + 1],tree[z]);
	}
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
  Segment_Tree st;
  st.init(n);
  for (int i = 0;i<k;++i){
	st.update(0,0,n - 1,left[i],right[i],height[i],op[i]);
  }
  for (int i = 0;i<n;++i){
	finalHeight[i] = st.query(0,0,n-1,i,i);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 440 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 8 ms 724 KB Output is correct
5 Correct 8 ms 724 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 137 ms 13840 KB Output is correct
3 Correct 152 ms 7956 KB Output is correct
4 Correct 433 ms 20688 KB Output is correct
5 Correct 303 ms 20928 KB Output is correct
6 Correct 294 ms 20272 KB Output is correct
# 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 356 KB Output is correct
4 Correct 6 ms 752 KB Output is correct
5 Correct 6 ms 724 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 134 ms 13816 KB Output is correct
9 Correct 154 ms 7884 KB Output is correct
10 Correct 405 ms 20804 KB Output is correct
11 Correct 310 ms 20888 KB Output is correct
12 Correct 271 ms 20172 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 137 ms 13836 KB Output is correct
15 Correct 26 ms 1840 KB Output is correct
16 Correct 464 ms 20720 KB Output is correct
17 Correct 276 ms 20684 KB Output is correct
18 Correct 307 ms 20568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 724 KB Output is correct
5 Correct 6 ms 724 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 156 ms 13900 KB Output is correct
9 Correct 147 ms 7956 KB Output is correct
10 Correct 428 ms 20696 KB Output is correct
11 Correct 293 ms 20684 KB Output is correct
12 Correct 275 ms 20188 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 140 ms 13900 KB Output is correct
15 Correct 27 ms 1908 KB Output is correct
16 Correct 446 ms 20732 KB Output is correct
17 Correct 291 ms 20656 KB Output is correct
18 Correct 295 ms 20564 KB Output is correct
19 Correct 1206 ms 87596 KB Output is correct
20 Correct 1188 ms 87576 KB Output is correct
21 Correct 1183 ms 87636 KB Output is correct
22 Correct 1164 ms 87516 KB Output is correct
23 Correct 1224 ms 87580 KB Output is correct
24 Correct 1147 ms 87584 KB Output is correct
25 Correct 1157 ms 87684 KB Output is correct
26 Correct 1156 ms 87596 KB Output is correct
27 Correct 1177 ms 87636 KB Output is correct
28 Correct 1203 ms 87716 KB Output is correct
29 Correct 1170 ms 87652 KB Output is correct
30 Correct 1194 ms 87620 KB Output is correct