이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const ll maxn = 4000010;
const ll INF = INT_MAX/4;
const int mod = 1e9+7;
ll ans[maxn];
struct node {
ll s, m, e;
ll maxv= INF, minv=0;
node *l, *r;
node (int _s, int _e) {
s = _s; e = _e; m = (s+e)/2;
if (s != e) {
l = new node(s,m);
r = new node(m+1,e);
}
}
void calc(ll type, ll x) {
if (type == 0) { //minimise
maxv = min(maxv, x);
minv = min(minv, x);
} else {
minv = max(minv, x);
maxv = max(maxv, x);
}
}
void push() {
// assert(s != e);
if (minv != 0 and s != e) {
l -> setmin(s, m, minv);
r -> setmin(m+1, e, minv);
minv = 0;
}
if (maxv != INF and s != e) {
l -> setmax(s, m, maxv);
r -> setmax(m+1, e, maxv);
maxv = INF;
}
}
void setmax(ll x, ll y, ll nv) {
if (s == x and e == y) {
calc(0, nv);
} else {
push();
if (x > m) r -> setmax(x,y, nv);
else if (y <= m) l -> setmax(x,y,nv);
else l -> setmax(x,m,nv), r -> setmax(m+1,y,nv);
}
}
void setmin(ll x, ll y, ll nv) {
if (s == x and e == y) {
calc(1, nv);
} else {
push();
if (x > m) r -> setmin(x,y, nv);
else if (y <= m) l -> setmin(x,y,nv);
else l -> setmin(x,m,nv), r -> setmin(m+1,y,nv);
}
}
void rmq() {
// cout << s << " " << e << " " << minv << " " << maxv << "\n";
if (s == e) ans[s] = minv;
else {
push();
l -> rmq();
r -> rmq();
}
}
}*root;
void buildWall(int n, int Q, int op[], int left[], int right[], int height[], int finalHeight[]){
root = new node(0,n-1);
for (int q = 0; q < Q; q++) {
int t = op[q];
int l = left[q];
int r = right[q];
int h = height[q];
if (t == 1) { //adding -> set min
root -> setmin(l,r,h);
} else {
root -> setmax(l,r,h);
}
// root -> rmq();
// for (int i = 0; i< n;i++) cout <<ans[i] << " ";
// cout << "\n";
}
root -> rmq();
for (int i =0;i<n;i++) {
finalHeight[i] = ans[i];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |