This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wall.h"
#include<bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if(sizeof...(t)) cerr << ", ";
DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL
#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"
#define fi first
#define se second
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
void setIO(string NAME = "") {
cin.tie(0)->sync_with_stdio(0);
if(sz(NAME)) {
freopen((NAME + ".inp").c_str(),"r",stdin);
freopen((NAME + ".out").c_str(),"w",stdout);
}
}
tcT> bool ckmin(T&a, const T&b) {
return b < a ? a=b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) {
return b > a ? a=b,1 : 0; }
const int MOD = 1e9 + 7;
struct Dat {
int mn, mx;
};
struct SegTree {
int N;
V<Dat> seg, lazy;
vi ans;
void init(int _N) {
N = _N;
seg.assign(N*4 + 7, {0,0});
lazy.assign(N*4 + 7, {0,0});
ans.assign(N+5, 0);
}
void proc_add(int ind, int val) {
ckmax(seg[ind].mn, val);
ckmax(seg[ind].mx, val);
ckmax(lazy[ind].mn, val);
ckmax(lazy[ind].mx, val);
}
void proc_rem(int ind, int val) {
ckmin(seg[ind].mn, val);
ckmin(seg[ind].mx, val);
ckmin(lazy[ind].mn, val);
ckmin(lazy[ind].mx, val);
}
void push(int ind) {
if(lazy[ind].mx != -MOD) {
F0R(i, 2) proc_add(ind*2 + i, lazy[ind].mx);
}
if(lazy[ind].mn != MOD) {
F0R(i, 2) proc_rem(ind*2 + i, lazy[ind].mn);
}
lazy[ind] = {MOD, -MOD};
}
void pull(int ind) {
seg[ind].mn = min(seg[ind<<1].mn, seg[ind<<1|1].mn);
seg[ind].mx = max(seg[ind<<1].mx, seg[ind<<1|1].mx);
}
void upd(int op, int l, int r, int val, int ind, int L, int R) {
if(L > r || R < l) return;
if(l <= L && R <= r) {
if(op == 1) proc_add(ind, val);
else proc_rem(ind, val);
return;
}
push(ind);
int mid = (L + R) >> 1;
upd(op, l, r, val, ind<<1, L, mid);
upd(op, l, r, val, ind<<1|1, mid+1, R);
pull(ind);
}
void upd(int op, int l, int r, int val) {
upd(op, l, r, val, 1, 1, N);
}
void calc(int ind, int L, int R) {
if(L == R) ans[L] = seg[ind].mn;
else {
push(ind);
int mid = (L + R) >> 1;
calc(ind<<1, L, mid);
calc(ind<<1|1, mid+1, R);
}
}
void calc() {
calc(1, 1, N);
}
};
SegTree st;
void buildWall(int N, int K, int op[], int left[], int right[], int height[], int finalHeight[]) {
st.init(N);
F0R(i, K) {
st.upd(op[i], left[i]+1, right[i]+1, height[i]);
}
st.calc();
FOR(i,1,N+1) finalHeight[i] = st.ans[i];
}
Compilation message (stderr)
wall.cpp: In function 'void setIO(std::string)':
wall.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen((NAME + ".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wall.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((NAME + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |