Submission #230740

# Submission time Handle Problem Language Result Execution time Memory
230740 2020-05-11T13:56:22 Z cfalas Wall (IOI14_wall) C++14
8 / 100
3000 ms 14072 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);
			lr[ind] = max(lr[ind], x);
		}
		else{
			ll[ind] = min(ll[ind], x);
			lr[ind] = min(lr[ind], x);
		}
		ans[rl] = ll[ind];
		return;
	}
	else if(l>rr || rl>r) return;

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

	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(lr, 2*ind);
		maxi(ll, 2*ind+1);
		maxi(lr, 2*ind+1);
		mini(ll, 2*ind);
		mini(lr, 2*ind);
		mini(ll, 2*ind+1);
		mini(lr, 2*ind+1);
		ll[ind] = 0;
		lr[ind] = INF;

		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 5 ms 384 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 13 ms 384 KB Output is correct
4 Correct 645 ms 1016 KB Output is correct
5 Correct 649 ms 948 KB Output is correct
6 Correct 657 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 186 ms 14048 KB Output is correct
3 Execution timed out 3043 ms 8184 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 633 ms 948 KB Output is correct
5 Correct 637 ms 1016 KB Output is correct
6 Correct 640 ms 1016 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 183 ms 14072 KB Output is correct
9 Execution timed out 3086 ms 8056 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 13 ms 384 KB Output is correct
4 Correct 633 ms 1016 KB Output is correct
5 Correct 628 ms 1016 KB Output is correct
6 Correct 630 ms 952 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 183 ms 13944 KB Output is correct
9 Execution timed out 3079 ms 8056 KB Time limit exceeded
10 Halted 0 ms 0 KB -