Submission #805369

#TimeUsernameProblemLanguageResultExecution timeMemory
805369JoenPoenManWall (IOI14_wall)C++17
8 / 100
3084 ms13900 KiB
#include "wall.h" #include <bits/stdc++.h> #define ALL(arr) begin(arr), end(arr) using namespace std; struct Tree { int v; int x, y; Tree *left = nullptr, *right = nullptr; Tree(int v, int x, int y) : v(v), x(x), y(y) {} }; void update(int a, int b, bool rem, int h, Tree *t, int lazy = -1) { if (lazy != -1) t->v = lazy; if (b < t->x || a > t->y) return; if (a <= t->x && b >= t->y && !(t->left || t->right)) { if (!rem) { t->v = max(t->v, h); } else { t->v = min(t->v, h); } return; } if (!t->left) { t->left = new Tree(0, t->x, (t->x + t->y)/2); update(a, b, rem, h, t->left, t->v); } else update(a, b, rem, h, t->left, -1); if (!t->right) { t->right = new Tree(0, (t->x + t->y)/2 + 1, t->y); update(a, b, rem, h, t->right, t->v); } else update(a, b, rem, h, t->right, -1); } void fillarr(int arr[], Tree *t) { if (t->left) { fillarr(arr, t->left); fillarr(arr, t->right); } else { for (int i = t->x; i <= t->y; i++) { arr[i] = t->v; } } } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { Tree *t = new Tree(0, 0, n-1); for (int i = 0; i < k; i++) { update(left[i], right[i], (op[i] == 1 ? false : true), height[i], t); } fillarr(finalHeight, t); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...