Submission #250007

# Submission time Handle Problem Language Result Execution time Memory
250007 2020-07-16T16:30:03 Z cfalas Wall (IOI14_wall) C++14
0 / 100
170 ms 13944 KB
#include "wall.h"
#include<bits/stdc++.h>
using namespace std;
#define ADD 1
#define REMOVE 2
#define MID ((l+r)/2)
typedef pair<int, int> ii;

#define INF 9999999
int seg[10000000];
int ll[10000000];
int lr[10000000];
ii lp[10000000];
int ans[1000000];
#define F first
#define S second
int n;
int TIME;

#define maxi(a,v) a[v] = max(a[v], ll[ind]);
#define mini(a,v) a[v] = min(a[v], lr[ind]);

void update(int rl, int rr, int k, int x, int l=0, int r=n-1, int ind=1){
	//cout<<l<<" "<<r<<" "<<ind<<endl;
	if(rl<=l && r<=rr){
		if(k==1){
			ll[ind] = max(ll[ind], x);
		}
		else{
			ll[ind] = min(ll[ind], x);
		}
		ans[rl] = ll[ind];
		return;
	}
	else if(l>rr || rl>r) return;

	maxi(ll, 2*ind);
	maxi(ll, 2*ind+1);
	mini(ll, 2*ind);
	mini(ll, 2*ind+1);
	ll[ind] = 0;

	update(rl, rr, k, x, l, MID, ind*2);
	update(rl, rr, k, x, MID+1, r, ind*2+1);
}


void query(int l=0, int r=n-1, int ind=1){
	if(l==r){
		ans[l] = ll[ind];
	}
	else{
		maxi(ll, 2*ind);
		maxi(ll, 2*ind+1);
		mini(ll, 2*ind);
		mini(ll, 2*ind+1);
		ll[ind] = 0;

		query(l, MID, ind*2);
		query(MID+1, r, ind*2+1);
	}
}

void buildWall(int N, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	n = N;
	for(int i=0;i<=5 * n;i++) lr[i] = INF;
	for(int i=0;i<k;i++){
		TIME++;
		//cout<<op[i]<<" "<<left[i]<<" "<<right[i]<<" "<<height[i]<<endl;
		update(left[i], right[i], op[i], height[i]);
		//for(int j=1;j<=30;j++){ if(ll[j]==0) cout<<"- "; else cout<<ll[j]<<" ";}
		//cout<<endl;
		//for(int j=1;j<=30;j++){ if(lr[j]==INF) cout<<"- "; else cout<<lr[j]<<" ";}
		//cout<<endl;
		//query();
		/*
		for(int j=1;j<=30;j++){ if(ll[j]==0) cout<<"- "; else cout<<ll[j]<<" ";}
		cout<<endl;
		for(int j=1;j<=30;j++){ if(lr[j]==INF) cout<<"- "; else cout<<lr[j]<<" ";}
		cout<<endl;
		*/
		//cout<<"CURR: ";
		//for(int i=0;i<N;i++) cout<<ans[i]<<" ";
		//cout<<"\n--------------------\n";
		//cout<<endl;
	}
	query();
	for(int i=0;i<N;i++) finalHeight[i] = ans[i];

}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 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 0 ms 384 KB Output is correct
2 Correct 170 ms 13944 KB Output is correct
3 Incorrect 170 ms 8312 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 4 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 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -