#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define pdd pair<double,double>
#define mp make_pair
#define AmirMakaM ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//#define int long long
// solve it
const ull SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 mrand(SEED);
ull rnd(ull x = ~(0ull)) {return mrand() % x;}
const ll MOD = 998244353;
const ll INF = 1e16+20;
const int inf = 1e9 + 7;
const ll N = 2e6+1;
const ll M = 2e3+1;
const double pi = 2*acos(0.0);
const int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};
pii t[4*N];
void build(int v, int tl, int tr) {
t[v] = {0,inf};
if(tl == tr) {
t[v] = {0,0};
return;
}
int tm = (tl+tr)>>1;
build(v+v,tl,tm);
build(v+v+1,tm+1,tr);
}
void push(int v, int x, int y) {
t[v].f = max(t[v].f,x);
t[v].f = min(t[v].f,y);
t[v].s = min(t[v].s,x);
t[v].s = max(t[v].s,y);
}
void upd(int v, int tl, int tr, int l, int r, int x, int type) {
if(r < tl || tr < l) {
return;
} else if(l <= tl && tr <= r) {
if(type == 1) {
t[v].f = max(t[v].f,x);
t[v].s = max(t[v].s,x);
} else {
t[v].f = min(t[v].f,x);
t[v].s = min(t[v].s,x);
}
return;
}
int tm = (tl+tr)>>1;
if(t[v] != mp(0,inf)) {
push(v+v,t[v].f,t[v].s);
push(v+v+1,t[v].f,t[v].s);
t[v] = {0,inf};
}
upd(v+v,tl,tm,l,r,x,type);
upd(v+v+1,tm+1,tr,l,r,x,type);
}
int get(int v, int tl, int tr, int pos) {
if(tl == tr) {
return t[v].f;
}
int tm = (tl+tr)>>1;
if(t[v] != mp(0,inf)) {
push(v+v,t[v].f,t[v].s);
push(v+v+1,t[v].f,t[v].s);
t[v] = {0,inf};
}
if(pos <= tm) return get(v+v,tl,tm,pos);
else return get(v+v+1,tm+1,tr,pos);
}
void buildWall(int n, int k, int type[], int l[], int r[],int h[], int ans[]) {
build(1,1,n);
for(int i=0; i<k; i++) {
upd(1,1,n,l[i]+1,r[i]+1,h[i],type[i]);
}
for(int i=1; i<=n; i++) {
ans[i-1] = get(1,1,n,i);
}
}
/*
int main() {
AmirMakaM;
srand(SEED);
//freopen("bulk.in", "r", stdin);
//freopen("bulk.out", "w", stdout);
int ttt = 1;
cin >> ttt;
while(ttt--) {
solve();
}
return 0;
int n, k;
cin >> n >> k;
int type[k], l[k], r[k], h[k], ans[n];
for(int i=0; i<k; i++) cin >> type[i] >> l[i] >> r[i] >> h[i];
buildWall(n,k,type,l,r,h,ans);
}
*/
# | 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... |