# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
719819 | 2023-04-06T18:21:12 Z | ovidiush11 | Wall (IOI14_wall) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "wall.h" using namespace std; #define mp make_pair #define ff first #define ss second const int inf = 1e9; const int K = 5e5; vector<pair<int,int>> a; int pos[K]; void build(int p,int l,int r) { if(l == r)pos[l] = p; else { int m = (l + r) / 2; build(p*2,l,m); build(p*2+1,m+1,r); } a[p].ff = 0; a[p].ss = inf; return ; } void change(int p) { if(p == 0)return ; int mx = min(a[p*2].ss,a[p*2+1].ss); int mn = max(a[p*2].ff,a[p*2+1].ff); if(mn > mx) { if(mn == a[p*2+1].ff)mx = mn; else mn = mx; } a[p].ff = mn; a[p].ss = mx; change(p / 2); return ; } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { queue<int> vq[n+1]; ll t = 1; while(t < k)t *= 2; a.resize(t * 2); build(1,0,k-1); for(int i = 0;i < k;i++)vq[left[i]].push(i); for(int i = 0;i < k;i++)vq[right[i]+1].push(i); for(int i = 0;i < n;i++) { while(!vq[i].empty()) { int v = vq[i].front(); vq[i].pop(); if(a[pos[v]].ff == 0 && a[pos[v]].ss == inf) { if(op[v] == 1)a[pos[v]].ff = height[v]; else a[pos[v]].ss = height[v]; } else { a[pos[v]].ff = 0; a[pos[v]].ss = inf; } change(pos[v] / 2); } finalHeight[i] = a[1].ff; } return ; }