Submission #289559

#TimeUsernameProblemLanguageResultExecution timeMemory
289559cheetoseWall (IOI14_wall)C++17
100 / 100
1514 ms83556 KiB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
int mntree[1<<22], mxtree[1<<22], lazy[1<<22];
void propagation(int node, int S, int E)
{
	if (lazy[node] != -1)
	{
		mntree[node] = mxtree[node] = lazy[node];
		if (S != E)
		{
			lazy[2 * node] = lazy[node];
			lazy[2 * node + 1] = lazy[node];
		}
		lazy[node] = -1;
	}
}
void upd(int node, int S, int E, int i, int j, int op, int val)
{
	propagation(node, S, E);
	if (i > E || j < S) return;
	if (j >= E && i <= S)
	{
		if((op==1 && mntree[node]>=val) || (op==2 && mxtree[node]<=val))return;
		if((op==1 && mxtree[node]<=val) || (op==2 && mntree[node]>=val)){
			lazy[node]=val;
			propagation(node,S,E);
			return;
		}
	}
	if(S==E)return;
	upd(2 * node, S, (S + E) / 2, i, j, op, val);
	upd(2 * node + 1, (S + E) / 2 + 1, E, i, j, op, val);
	mntree[node] = min(mntree[2 * node], mntree[2 * node + 1]);
	mxtree[node] = max(mxtree[2 * node], mxtree[2 * node + 1]);
}
int find(int node,int S,int E,int i,int j){
	propagation(node, S, E);
	if (i > E || j < S) return -1;
	if (j >= E && i <= S) return mxtree[node];
	return max(find(node * 2, S, (S + E) / 2, i, j), find(2 * node + 1, (S + E) / 2 + 1, E, i, j));
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	for(int i=0;i<k;i++){
		int o=op[i],l=left[i],r=right[i],x=height[i];
		upd(1,0,n-1,l,r,o,x);
	}
	for(int i=0;i<n;i++){
		finalHeight[i]=find(1,0,n-1,i,i);
	}
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...