Submission #530780

# Submission time Handle Problem Language Result Execution time Memory
530780 2022-02-26T18:41:17 Z PoPularPlusPlus Wall (IOI14_wall) C++17
100 / 100
906 ms 59260 KB
#include <bits/stdc++.h>

using namespace std;

#include "wall.h"

struct item {
	int rem , fin;
};

struct Seg {
	int siz;
	vector<item> sum;
	
	item nutral = {INT_MAX , 0};
	
	item merge(item a , item b){
		item ans;
		ans.fin = max(a.fin , min(b.fin , a.rem));
		ans.rem = min(a.rem , b.rem);
		return ans;
	}
	
	void init(int n){
		siz = 1;
		while(siz < n)siz *= 2;
		sum.assign(siz * 2 , nutral);
	}
	
	int set(int i , int x , int lx , int rx){
		if(rx - lx == 1){
			return sum[x].fin;
		}
		sum[2 * x + 1] = merge(sum[x] , sum[2 * x + 1]);
		sum[2 * x + 2] = merge(sum[x] , sum[2 * x + 2]);
		sum[x] = nutral;
		int m = (lx + rx)/2;
		if(i < m)return set(i , 2 * x + 1 , lx , m);
		else return set(i , 2 * x + 2  , m , rx);
	}
	
	int set(int i){
		return set(i , 0 , 0 , siz);
	}
	
	void range_set(int l, int r , int op , int h , int x , int lx , int rx){
		if(rx <= l || lx >= r){
			return;
		}
		if(lx >= l && rx <= r){
			if(op == 2){
				sum[x].fin = min(sum[x].fin , h);
				sum[x].rem = min(sum[x].rem , h);
			}
			else sum[x].fin = max(sum[x].fin , h);
			return;
		}
		sum[2 * x + 1] = merge(sum[x] , sum[2 * x + 1]);
		sum[2 * x + 2] = merge(sum[x] , sum[2 * x + 2]);
		sum[x] = nutral;
		int m = (lx + rx)/2;
		range_set(l , r , op , h , 2 * x + 1 , lx , m);
		range_set(l ,r , op , h , 2 * x + 2 , m, rx);
	}
	
	void range_set(int l , int r , int op , int h){
		range_set(l , r , op , h , 0 , 0 , siz);
	}
};

void buildWall(int n, int k, int op[], int left[], int right[], int hei[], int finalHeight[]){
  Seg st;
  st.init(n);
  for(int i = 0; i < k; i++){
	  st.range_set(left[i] , right[i]+1 , op[i] , hei[i]);
  }
  for(int i = 0; i < n; i++)finalHeight[i] = st.set(i);
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 2 ms 428 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 6 ms 748 KB Output is correct
5 Correct 5 ms 716 KB Output is correct
6 Correct 6 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 128 ms 13808 KB Output is correct
3 Correct 145 ms 7840 KB Output is correct
4 Correct 419 ms 20164 KB Output is correct
5 Correct 279 ms 20716 KB Output is correct
6 Correct 264 ms 19148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 408 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 6 ms 748 KB Output is correct
5 Correct 7 ms 688 KB Output is correct
6 Correct 5 ms 716 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 126 ms 13876 KB Output is correct
9 Correct 182 ms 7868 KB Output is correct
10 Correct 389 ms 20172 KB Output is correct
11 Correct 272 ms 20648 KB Output is correct
12 Correct 253 ms 19116 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 145 ms 13924 KB Output is correct
15 Correct 26 ms 1876 KB Output is correct
16 Correct 401 ms 20168 KB Output is correct
17 Correct 252 ms 19500 KB Output is correct
18 Correct 274 ms 19696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 6 ms 716 KB Output is correct
5 Correct 6 ms 716 KB Output is correct
6 Correct 5 ms 716 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 146 ms 13924 KB Output is correct
9 Correct 144 ms 7856 KB Output is correct
10 Correct 411 ms 20168 KB Output is correct
11 Correct 270 ms 20712 KB Output is correct
12 Correct 258 ms 19152 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 130 ms 13904 KB Output is correct
15 Correct 26 ms 1868 KB Output is correct
16 Correct 386 ms 20164 KB Output is correct
17 Correct 258 ms 19496 KB Output is correct
18 Correct 273 ms 19592 KB Output is correct
19 Correct 842 ms 59164 KB Output is correct
20 Correct 831 ms 59200 KB Output is correct
21 Correct 883 ms 59208 KB Output is correct
22 Correct 840 ms 59208 KB Output is correct
23 Correct 906 ms 59244 KB Output is correct
24 Correct 837 ms 59200 KB Output is correct
25 Correct 836 ms 59128 KB Output is correct
26 Correct 833 ms 59260 KB Output is correct
27 Correct 828 ms 59120 KB Output is correct
28 Correct 861 ms 59196 KB Output is correct
29 Correct 824 ms 59200 KB Output is correct
30 Correct 845 ms 59220 KB Output is correct