Submission #581437

#TimeUsernameProblemLanguageResultExecution timeMemory
581437alirezasamimi100Wall (IOI14_wall)C++17
100 / 100
701 ms156120 KiB
#include "wall.h" #include <bits/stdc++.h> #define pb push_back #define lc v << 1 #define rc v << 1 | 1 using namespace std; const int N = 2e6 + 10, inf = 1.05e9; int n, k, fl[N], fr[N]; vector<int> L[N], R[N]; void build(int v, int l, int r){ fl[v] = 0; fr[v] = inf; if(r - l > 1){ int m = (l + r) >> 1; build(lc, l, m); build(rc, m, r); } } void upd(int v, int l, int r, int p, int lh, int rh){ if(r - l == 1){ fl[v] = lh; fr[v] = rh; return; } int m = (l + r) >> 1; if(p < m) upd(lc, l, m, p, lh, rh); else upd(rc, m, r, p, lh, rh); fl[v] = fl[lc]; if(fl[rc] > fl[v]) fl[v] = fl[rc]; if(fr[rc] < fl[v]) fl[v] = fr[rc]; fr[v] = fr[lc]; if(fr[rc] < fr[v]) fr[v] = fr[rc]; if(fl[rc] > fr[v]) fr[v] = fl[rc]; } void buildWall(int wtn, int wtk, int op[], int left[], int right[], int height[], int finalHeight[]){ n = wtn; k = wtk; int LH[k],RH[k]; for(int i = 0; i < k; i++){ L[left[i]].pb(i); R[right[i]].pb(i); if(op[i] == 1){ LH[i] = height[i]; RH[i] = inf; }else{ LH[i] = 0; RH[i] = height[i]; } } build(1, 0, k); for(int i = 0; i < n; i++){ for(int j : L[i]) upd(1, 0, k, j, LH[j], RH[j]); finalHeight[i] = fl[1]; for(int j : R[i]) upd(1, 0, k, j, 0, inf); } return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...