# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
408108 | mshandilya | 벽 (IOI14_wall) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
void add(std::vector<int>& ST, std::vector<int>& lazy, int update, int rbeg, int rend, int beg, int end, int node) {
if(rbeg>rend)
return;
if(lazy[node-1]!=-1) {
ST[node-1] = lazy[node-1];
lazy[2*node-1] = lazy[node-1];
lazy[2*node] = lazy[node-1];
lazy[node-1] = -1;
}
if(rbeg==beg and rend==end) {
ST[node-1] = max(update, ST[node-1]);
if(lazy[2*node-1]==-1)
lazy[2*node-1] = max(update, ST[2*node-1]);
else
lazy[2*node-1] = max(update, lazy[2*node-1]);
if(lazy[2*node]==-1)
lazy[2*node] = max(update, ST[2*node]);
else
lazy[2*node] = max(update, lazy[2*node]);
return;
}
int mid = (beg+end)/2;
add(ST, lazy, update, rbeg, min(mid, rend), beg, mid, 2*node);
add(ST, lazy, update, max(rbeg, mid+1), rend, mid+1, end, 2*node+1);
return;
}
void remov(std::vector<int>& ST, std::vector<int>& lazy, int update, int rbeg, int rend, int beg, int end, int node) {
if(rbeg>rend)
return;
if(lazy[node-1]!=-1) {
ST[node-1] = lazy[node-1];
lazy[2*node-1] = lazy[node-1];
lazy[2*node] = lazy[node-1];
lazy[node-1] = -1;
}
if(rbeg==beg and rend==end) {
ST[node-1] = min(update, ST[node-1]);
if(lazy[2*node-1]==-1)
lazy[2*node-1] = min(update, ST[2*node-1]);
else
lazy[2*node-1] = min(update, lazy[2*node-1]);
if(lazy[2*node]==-1)
lazy[2*node] = min(update, ST[2*node]);
else
lazy[2*node] = min(update, lazy[2*node]);
return;
}
int mid = (beg+end)/2;
remov(ST, lazy, update, rbeg, min(mid, rend), beg, mid, 2*node);
remov(ST, lazy, update, max(rbeg, mid+1), rend, mid+1, end, 2*node+1);
return;
}
int retrieve(std::vector<int>& ST, std::vector<int>& lazy, int find, int beg, int end, int node) {
if(lazy[node-1]!=-1) {
ST[node-1] = lazy[node-1];
lazy[2*node-1] = lazy[node-1];
lazy[2*node] = lazy[node-1];
lazy[node-1] = -1;
}
if(beg==end)
return ST[node-1];
int mid = (beg+end)/2;
if(find<=mid)
return retrieve(ST, lazy, find, beg, mid, 2*node);
else
return retrieve(ST, lazy, find, mid+1, end, 2*node+1);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
int st_size = 1;
while(st_size<n)
st_size<<=1;
std::vector<int> ST(2*st_size-1, 0), lazy(2*st_size-1, -1);
for (int i = 0; i<k; ++i) {
if(op[i]==1)
add(ST, lazy, height[i], left[i], right[i], 0, st_size-1, 1);
else
remov(ST, lazy, height[i], left[i], right[i], 0, st_size-1, 1);
}
for(int i = 0; i<n; i++)
finalHeight[i] = retrieve(ST, lazy, i, 0, st_size-1, 1);
return;
}
int main() {
int n, k;
cin>>n>>k;
int op[k], left[k], right[k], height[k], finalHeight[n];
for(int i = 0; i<k; i++)
cin>>op[i]>>left[i]>>right[i]>>height[i];
buildWall(n, k, op, left, right, height, finalHeight);
for(int i = 0; i<n; i++)
cout<<finalHeight[i]<<" ";
cout<<endl;
return 0;
}