제출 #1099509

#제출 시각아이디문제언어결과실행 시간메모리
1099509rahidilbayramli벽 (IOI14_wall)C++17
100 / 100
979 ms69504 KiB
#include "wall.h" #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll int #define ld long double #define vl vector<ll> #define vi vector<int> #define pii pair<int, int> #define pll pair<int, int> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back #define p_b pop_back #define f first #define s second using namespace std; using namespace __gnu_pbds; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll sz = 2e6+5; ll a[sz]; pll segtree[4*sz]; void build(ll v, ll l, ll r) { if(l == r) segtree[v] = {0, 0}; else { ll mid = (l + r) / 2; build(2*v, l, mid); build(2*v+1, mid+1, r); segtree[v] = {-1, 0}; } } void push1(ll v, ll l, ll r) { if(l != r) { if(segtree[v].f >= segtree[2*v].s) segtree[2*v] = {segtree[v].f, segtree[v].f}; else if(segtree[v].s <= segtree[2*v].f) segtree[2*v] = {segtree[v].s, segtree[v].s}; else segtree[2*v] = {max(segtree[v].f, segtree[2*v].f), min(segtree[v].s, segtree[2*v].s)}; if(segtree[v].f >= segtree[2*v+1].s) segtree[2*v+1] = {segtree[v].f, segtree[v].f}; else if(segtree[v].s <= segtree[2*v+1].f) segtree[2*v+1] = {segtree[v].s, segtree[v].s}; else segtree[2*v+1] = {max(segtree[v].f, segtree[2*v+1].f), min(segtree[v].s, segtree[2*v+1].s)}; segtree[v] = {INT_MIN, INT_MAX}; } } void update1(ll v, ll l, ll r, ll tl, ll tr, ll val) { push1(v, l, r); if(l > r || l > tr || r < tl) return; if(tl <= l && r <= tr) { if(l == r){ segtree[v] = {max(val, segtree[v].f), max(val, segtree[v].f)}; return; } segtree[v] = {val, INT_MAX}; push1(v, l, r); return; } ll mid = (l + r) / 2; update1(2*v, l, mid, tl, tr, val); update1(2*v+1, mid+1, r, tl, tr, val); } void update2(ll v, ll l, ll r, ll tl, ll tr, ll val) { push1(v, l, r); if(l > r || l > tr || r < tl) return; if(tl <= l && r <= tr) { if(l == r){ segtree[v] = {min(val, segtree[v].f), min(val, segtree[v].f)}; return; } segtree[v] = {INT_MIN, val}; push1(v, l, r); return; } ll mid = (l + r) / 2; update2(2*v, l, mid, tl, tr, val); update2(2*v+1, mid+1, r, tl, tr, val); } pll findres(ll v, ll l, ll r, ll tl, ll tr) { if(l > r || l > tr || r < tl) return {INT_MIN, INT_MAX}; push1(v, l, r); if(tl <= l && r <= tr) return segtree[v]; ll mid = (l + r) / 2; pll lans = findres(2*v, l, mid, tl, tr); pll rans = findres(2*v+1, mid+1, r, tl, tr); return {max(lans.f, rans.f), 0}; } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){ build(1, 1, n); for(int i = 0; i < k; i++) { if(op[i] == 1) update1(1, 1, n, left[i]+1, right[i]+1, height[i]); else update2(1, 1, n, left[i]+1, right[i]+1, height[i]); } for(int i = 0; i < n; i++) finalHeight[i] = findres(1, 1, n, i+1, i+1).f; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...