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 <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#ifdef _DEBUG
#define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el
#else
#define dout(x)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)
#define ins insert
#define ssize(x) (int((x).size()))
#define bs(args...) binary_search(args)
#define lb(args...) lower_bound(args)
#define ub(args...) upper_bound(args)
#define all(x) (x).begin(),(x).end()
#define mp(a, b) make_pair(a, b)
#define mt(args...) make_tuple(args)
#define pb(x) push_back(x)
#define eb(args...) emplace_back(args)
#define ff first
#define ss second
#define die exit(0)
template<typename T>
using vc = vector<T>;
template<typename T>
using uset = unordered_set<T>;
template<typename A, typename B>
using umap = unordered_map<A, B>;
template<typename T, typename Comp>
using pq = std::priority_queue<T, vc<T>, Comp>;
template<typename T>
using maxpq = pq<T, less<T>>;
template<typename T>
using minpq = pq<T, greater<T>>;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using db = double;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vc<int>;
using vll = vc<ll>;
using vpi = vc<pi>;
using vpll = vc<pll>;
using str = string;
constexpr char el = '\n';
constexpr char sp = ' ';
constexpr int inf = 0x3f3f3f3f;
constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL;
// ---------------------------------------------------------------------
static const int N = 8e6+5;
static int n, n2, q;
struct node {
int min = 0, max = inf; // min is the minimum value needed to be
};
static vc<node> tr;
static void push(int i){
if(i >= n)
return;
if(tr[i].min){
tr[2*i].min = max(tr[2*i].min, tr[i].min);
tr[2*i].max = max(tr[2*i].max, tr[i].min);
tr[2*i+1].min = max(tr[2*i+1].min, tr[i].min);
tr[2*i+1].max = max(tr[2*i+1].max, tr[i].min);
tr[i].min = 0;
}
if(tr[i].max!=inf){
tr[2*i].max = min(tr[2*i].max, tr[i].max);
tr[2*i].min = min(tr[2*i].min, tr[i].max);
tr[2*i+1].max = min(tr[2*i+1].max, tr[i].max);
tr[2*i+1].min = min(tr[2*i+1].min, tr[i].max);
tr[i].max = inf;
}
}
static void upd_min(int l, int r, int i, int il, int ir, int x){
if(ir < l || r < il)
return;
if(l <= il && ir <= r){
tr[i].min = max(tr[i].min, x);
tr[i].max = max(tr[i].max, x);
return;
}
push(i);
int im = (il+ir)/2;
upd_min(l, r, 2*i, il, im, x);
upd_min(l, r, 2*i+1, im+1, ir, x);
}
static void upd_max(int l, int r, int i, int il, int ir, int x){
if(ir < l || r < il)
return;
if(l <= il && ir <= r){
tr[i].max = min(tr[i].max, x);
tr[i].min = min(tr[i].min, x);
return;
}
push(i);
int im = (il+ir)/2;
upd_max(l, r, 2*i, il, im, x);
upd_max(l, r, 2*i+1, im+1, ir, x);
}
static int at(int i){
i += n;
int ans = 0;
while(i>0){
ans = max(ans, tr[i].min);
ans = min(ans, tr[i].max);
i /= 2;
}
return ans;
}
void buildWall(int _n, int q, int op[], int left[], int right[], int height[], int finalHeight[]){
n2 = _n;
n = 1;
while(n<n2)
n *= 2;
tr = vc<node>(2*n+5);
while(q--){
int t, l, r, h;
cin >> t >> l >> r >> h;
if(t==1)
upd_min(l, r, 1, 0, n-1, h);
else
upd_max(l, r, 1, 0, n-1, h);
}
for(int i = 0; i < n2; ++i)
finalHeight[i] = at(i);
}
//signed main() {
// ios::sync_with_stdio(0); cin.tie(0);
// cout << fixed; clog << fixed; clog << unitbuf;
//#ifdef _DEBUG
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("debug.txt", "w", stderr);
//#else
// //freopen(".in", "r", stdin);
// //freopen(".out", "w", stdout);
//#endif
//
// cin >> n2 >> q;
// for(int i = 0; i < n2; ++i)
// cout << at(i) << sp;
//}
Compilation message (stderr)
wall.cpp:63:19: warning: 'q' defined but not used [-Wunused-variable]
63 | static int n, n2, q;
| ^
# | 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... |