# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1149367 | rayan_bd | Wall (IOI14_wall) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define fi first
#define se second
const int mxN = 2e5 + 500;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
struct seg_tree{
struct Node{
ll mn=0,mx=INF;
} seg[mxN*4];
Node dummy,new_node;
void apply(ll node,Node v){
seg[node].mn = max(seg[node].mn, v.mn);
seg[node].mx = max(seg[node].mx, seg[node].mn);
seg[node].mx = min(seg[node].mx, v.mx);
seg[node].mn = min(seg[node].mn, seg[node].mx);
}
void push(ll node){
apply(node*2+1,seg[node]);
apply(node*2+2,seg[node]);
seg[node]=dummy;
}
void update(ll node,ll start,ll end,ll l,ll r,Node nd){
if(start>r||end<l) return;
if(start>=l&&end<=r){
apply(node,nd);
return;
}
ll mid=start+(end-start)/2;
push(node);
update(node*2+1,start,mid,l,r,nd);
update(node*2+2,mid+1,end,l,r,nd);
}
ll qry(ll node,ll start,ll end,ll idx){
if(start==end) return seg[node].mn;
ll mid=start+(end-start)/2;
push(node);
if(idx<=mid) return qry(node*2+1,start,mid,idx);
else return qry(node*2+2,mid+1,end,idx);
}
} tr;
void buildWall(ll n,ll k,vector<ll> op,vector<ll> left,vector<ll> right,vector<ll> height,vector<ll> &finalHeight){
for(ll i=0;i<k;++i){
if(op[i]==1){
tr.new_node.mn=height[i];
tr.new_node.mx=INF;
tr.update(0,0,n-1,left[i],right[i],tr.new_node);
}else{
tr.new_node.mn=0;
tr.new_node.mx=height[i];
tr.update(0,0,n-1,left[i],right[i],tr.new_node);
}
}
for(ll i=0;i<n;++i){
finalHeight[i]=tr.qry(0,0,n-1,i);
}
}