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 <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include "wall.h"
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline T range(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
inline void setin(string s) {
freopen(s.c_str(), "r", stdin);
}
inline void setout(string s) {
freopen(s.c_str(), "w", stdout);
}
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 2e6 + 15;
struct segment_tree {
int mn[N << 2], mx[N << 2], add[N << 2];
segment_tree() {
memset(mn, 0, sizeof(mx));
memset(mx, 0, sizeof(mx));
memset(add, -1, sizeof(add));
}
inline void upd(int v, int x) {
mn[v] = mx[v] = add[v] = x;
}
inline void push(int v) {
if(v < (N << 1) && add[v] != -1) {
upd(v << 1, add[v]);
upd(v << 1 | 1, add[v]);
add[v] = -1;
}
}
void max_equal(int v, int tl, int tr, int l, int r, int h) {
if(tl > r || tr < l || mn[v] >= h)
return;
push(v);
if(tl >= l && tr <= r && mx[v] <= h)
upd(v, h);
else {
int mid = tl + tr >> 1;
max_equal(v << 1, tl, mid, l, r, h);
max_equal(v << 1 | 1, mid + 1, tr, l, r, h);
mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
}
void min_equal(int v, int tl, int tr, int l, int r, int h) {
if(tl > r || tr < l || mx[v] <= h)
return;
push(v);
if(tl >= l && tr <= r && mn[v] >= h)
upd(v, h);
else {
int mid = tl + tr >> 1;
min_equal(v << 1, tl, mid, l, r, h);
min_equal(v << 1 | 1, mid + 1, tr, l, r, h);
mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
}
void output(int v, int tl, int tr, int finalHeight[]) {
if(tl == tr)
finalHeight[tl] = mn[v];
else {
push(v);
int mid = tl + tr >> 1;
output(v << 1, tl, mid, finalHeight);
output(v << 1 | 1, mid + 1, tr, finalHeight);
}
}
} t;
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for(int i = 0; i < k; ++i) {
if(op[i] == 1)
t.max_equal(1, 0, n - 1, left[i], right[i], height[i]);
else
t.min_equal(1, 0, n - 1, left[i], right[i], height[i]);
}
t.output(1, 0, n - 1, finalHeight);
}
Compilation message (stderr)
wall.cpp: In member function 'void segment_tree::max_equal(int, int, int, int, int, int)':
wall.cpp:91:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
wall.cpp: In member function 'void segment_tree::min_equal(int, int, int, int, int, int)':
wall.cpp:105:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
wall.cpp: In member function 'void segment_tree::output(int, int, int, int*)':
wall.cpp:117:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
# | 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... |