답안 #1086509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086509 2024-09-10T20:49:13 Z EkinOnal 벽 (IOI14_wall) C++17
0 / 100
2 ms 5152 KB
//#pragma GCC optimize("O3,unroll-loops,Ofast")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include "wall.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
 
#define MAX 200005
#define pb push_back
#define mp make_pair 
#define int long long
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>> 
const int mod = 1e9+7;
const int INF = 1e18;
// myMap.begin()->first :  key
// myMap.begin()->second : value
 
int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;b>>=1;ans%=mod;a%=mod;}return (ans+mod)%mod;}
int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int sum(int a,int b){return ((a%mod)+(b%mod))%mod;}

// typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
// typedef 
// tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;

int n,d;
vi arr(MAX);

struct segItem{
	int val,lazymin,lazymax;
};

struct SegTree{
//	segItem tree[MAX*4];
	int mn[MAX],mx[MAX];

	SegTree(){
		memset(mn,-1,sizeof(mn));
		memset(mx,-1,sizeof(mx));
	}

	void push(int v){
		if(mn[v]!=-1){
			if(mn[v*2]==-1) mn[v*2]=mn[v];
			else mn[v*2]=max(mn[v*2],mn[v]);

			if(mn[v*2+1]==-1) mn[v*2+1]=mn[v];
			else mn[v*2+1]=max(mn[v*2+1],mn[v]);

			if(mx[v*2]!=-1) mx[v*2]=max(mx[v*2],mn[v]);
			if(mx[v*2+1]!=-1) mx[v*2+1]=max(mx[v*2+1],mn[v]);

		}
		if(mx[v]!=-1){
			if(mx[v*2]==-1) mx[v*2]=mx[v];
			else mx[v*2]=min(mx[v*2],mx[v]);

			if(mx[v*2+1]==-1) mx[v*2+1]=mx[v];
			else mx[v*2+1]=min(mx[v*2+1],mx[v]);

			if(mn[v*2]!=-1) mn[v*2]=min(mn[v*2],mx[v]);
			if(mn[v*2+1]!=-1) mn[v*2+1]=min(mn[v*2+1],mx[v]);
		}
		mn[v]=mx[v]=-1;
	}

	// void updatemax(int v,int tl,int tr,int l ,int r,int val){
	// 	push(v); 
	// 	if(tl>tr || tl>r || tr<l) return;
	// 	if(tl>=l && tr<=r){
	// 		if(mx[v]==-1) mx[v]=val;
	// 		else mx[v]=min(mx[v],val);
	// 		if(mn[v]!=-1) mn[v]=min(mn[v],val); 
	// 		return;
	// 	}
	// 	int mid=(tl+tr)>>1;
	// 	updatemax(v*2,tl,mid,l,r,val); updatemax(v*2+1,mid+1,tr,l,r,val);
	// }

	void updatemax(int v,int tl,int tr,int l ,int r,int val){
		if(tl>tr || tl>r || tr<l) return;
		if(tl>=l && tr<=r){
			if(mx[v]==-1) mx[v]=val;
			else mx[v]=min(mx[v],val);
			if(mn[v]!=-1) mn[v]=min(mn[v],val); 
			return;
		}
		push(v);
		int mid=(tl+tr)>>1;
		updatemax(v*2,tl,mid,l,r,val); updatemax(v*2+1,mid+1,tr,l,r,val);
	}

	void updatemin(int v,int tl,int tr,int l ,int r,int val){
		if(tl>tr || tl>r || tr<l) return;
		if(tl>=l && tr<=r){
			if(mn[v]==-1) mn[v]=val;
			else mn[v]=max(mn[v],val);
			if(mx[v]!=-1) mx[v]=max(mx[v],val); 
			return;
		}
		push(v); 
		int mid=(tl+tr)>>1;
		updatemin(v*2,tl,mid,l,r,val); updatemin(v*2+1,mid+1,tr,l,r,val);
	}

	void query(int v,int tl,int tr){
		if(tl==tr) {arr[tl]=max(mn[v],0LL);return;}
		int mid=(tl+tr)>>1;
		push(v);
		query(v*2,tl,mid); query(v*2+1,mid+1,tr);
	}

};

SegTree segtree;

// void solve(int n,int k,){
// 	// int n,k; cin>>n>>k;
// 	// vi op(k+5),left(k+5),right(k+5),height(k+5);
// 	// for(int i=1;i<=k;i++) cin>>op[i]>>left[i]>>right[i]>>height[i];

// 	for(int i=1;i<=k;i++){
// 		if(op[i]==1) segtree.updatemin(1,1,n,left[i]+1,right[i]+1,height[i]);
// 		else segtree.updatemax(1,1,n,left[i]+1,right[i]+1,height[i]);
// 	}
// 	segtree.query(1,1,n);
// 	for(int i=1;i<=n;i++) cout<<arr[i]<<endl;

// 	return;
// }

void buildWall(int32_t N, int32_t k, int32_t op[], int32_t left[], int32_t right[], int32_t height[], int32_t finalHeight[]){
    n = N;
 
   for(int i=0;i<k;i++){
		if(op[i]==1) segtree.updatemin(1,1,n,left[i]+1,right[i]+1,height[i]);
		else segtree.updatemax(1,1,n,left[i]+1,right[i]+1,height[i]);
	}
 
    segtree.query(1,1,n);
    for(int i=1;i<=n;i++) cout<<arr[i]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -