Submission #1042921

#TimeUsernameProblemLanguageResultExecution timeMemory
1042921vaneaWall (IOI14_wall)C++14
24 / 100
452 ms25168 KiB
#include <bits/stdc++.h> #include "wall.h" using namespace std; using ll = long long; const int mxN = 1e7; array<ll, 2> st[mxN]; array<bool, 2> vis[mxN]; int last[mxN]; void propagate(int node, int l, int r) { if(vis[node][0]) { if(l != r) { int left = node*2, right = node*2+1; if(vis[left][0]) { if(st[node][0] > st[left][0]) { last[left] = 1; st[left][0] = st[node][0]; } } else { last[left] = 1; st[left][0] = st[node][0]; } if(vis[left][1] && last[left] == 2 && st[node][0] > st[left][1]) { st[left][1] = st[node][0]; } if(vis[right][0]) { if(st[node][0] >= st[right][0]) { last[right] = 1; st[right][0] = st[node][0]; } } else { last[right] = 1; st[right][0] = st[node][0]; } if(vis[right][1] && last[right] == 2 && st[node][0] > st[right][1]) { st[right][1] = st[node][0]; } vis[left][0] = vis[right][0] = true; vis[node][0] = false; } } if(vis[node][1]) { if(l != r) { int left = node*2, right = node*2+1; if(vis[left][1]) { if(st[node][1] <= st[left][1]) { st[left][1] = st[node][1]; last[left] = 2; } } else { st[left][1] = st[node][1]; last[left] = 2; } if(last[left] == 1 && vis[left][1] && st[node][1] < st[left][0]) { st[left][0] = st[node][1]; } if(vis[right][1]) { if(st[node][1] <= st[right][1]) { st[right][1] = st[node][1]; last[right] = 2; } } else { st[right][1] = st[node][1]; last[right] = 2; } if(last[right] == 1 && vis[right][1] && st[node][1] < st[right][0]) { st[right][0] = st[node][1]; } vis[left][1] = vis[right][1] = true; vis[node][1] = false; } } } void upd(int node, int l, int r, int l1, int r1, int h, int op) { propagate(node, l, r); if(l1 <= l && r1 >= r) { if(op == 1) { if(vis[node][0]) { if(h >= st[node][0]) { last[node] = 1; st[node][0] = h; } } else { last[node] = 1; st[node][0] = h; } if(last[node] == 2 && vis[node][1] && h > st[node][1]) { st[node][1] = h; } vis[node][0] = true; } else { if(vis[node][1]) { if(h <= st[node][1]) { last[node] = 2; st[node][1] = h; } } else { last[node] = 2; st[node][1] = h; } if(last[node] == 1 && vis[node][0] && h < st[node][0]) { st[node][0] = h; } vis[node][1] = true; } propagate(node, l, r); return ; } if(l1 > r || r1 < l) return ; int mid = (l+r)/2; upd(node*2, l, mid, l1, r1, h, op); upd(node*2+1, mid+1, r, l1, r1, h, op); } int query(int node, int l, int r, int k) { propagate(node, l, r); if(l == r && l == k) { int ans = 0; if(vis[node][0] && vis[node][1]) { if(last[node] == 1) { ans = st[node][0]; } else { ans = min(st[node][0], st[node][1]); } } else if(vis[node][0]) { ans = st[node][0]; } return ans; } if(l > k || r < k) return 0; int mid = (l+r)/2; return query(node*2, l, mid, k) + query(node*2+1, mid+1, r, k); } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { for(int i = 0; i < k; i++) { upd(1, 0, n-1, left[i], right[i], height[i], op[i]); } for(int i = 0; i < n; i++) { finalHeight[i] = query(1, 0, n-1, i); //cout << finalHeight[i] << ' '; } } /* int main() { int arr1[10] = {1, 2, 2, 1, 1, 2}, arr2[10] = {1, 4, 3, 0, 2, 6}; int arr3[10] = {8, 9, 6, 5, 2, 7}, arr4[10] = {4, 1, 5, 3, 5, 0}; int arr5[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; buildWall(10, 6, arr1, arr2, arr3, arr4, arr5); }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...