Submission #58884

# Submission time Handle Problem Language Result Execution time Memory
58884 2018-07-19T18:12:38 Z ruhanhabib39 Wall (IOI14_wall) C++17
0 / 100
3000 ms 14496 KB
#include "wall.h"
#include <algorithm>
#include <cstdio>

namespace {
   const int MAXN = 2e6;
   const int INF = 1e9;

   struct Range {
      int l, r;
      int pos_left;
      bool operator==(Range rng) const {
         return l == rng.l && r == rng.r;
      }
      bool operator!=(Range rng) const {
         return !(*this == rng);
      }
      Range inters(Range rng) const {
         if(pos_left == -1) return rng;
         if(r < rng.l) {
            rng.pos_left = 1;
            return rng;
         }
         if(rng.r < l) {
            rng.pos_left = 0;
            return rng;
         }
         return Range{std::max(l, rng.l), std::min(r, rng.r), pos_left};
      }
   };

   Range tree[4 * MAXN + 10];
   
   void init(int cn, int b, int e) {
      tree[cn] = {0, 0, 1};
      if(b == e) return;
      int m = (b + e) / 2;
      init(2*cn, b, m);
      init(2*cn+1, m+1, e);
   }

   void upd(int cn, int b, int e, int l, int r, Range rng) {
      if(r < b || l > e) return;
      int m = (b + e) / 2;
      if(b != e && tree[cn].pos_left != -1) {
         upd(2*cn, b, m, b, m, tree[cn]);
         upd(2*cn+1, m+1, e, m+1, e, tree[cn]);
      }
      //fprintf(stderr, "upd([%d,%d],[%d,%d],[%d,%d]\n", b, e, l, r, rng.l, rng.r);
      if(l <= b && e <= r) {
         //fprintf(stderr, "before tree[%d,%d] = {[%d,%d],%d}\n", b, e, tree[cn].l, tree[cn].r, tree[cn].pos_left);
         tree[cn] = tree[cn].inters(rng);
         //fprintf(stderr, "after tree[%d,%d] = {[%d,%d],%d}\n", b, e, tree[cn].l, tree[cn].r, tree[cn].pos_left);
         return;
      }
      upd(2*cn, b, m, l, r, rng);
      upd(2*cn+1, m+1, e, l, r, rng);
      tree[cn] = Range{0, INF, -1};
   }

   void get_res(int cn, int b, int e, Range rng, int finalHeight[]) {
      if(b == e) {
         Range res_range = tree[cn].inters(rng);
         if(res_range.pos_left == 1) finalHeight[b] = res_range.l;
         else finalHeight[b] = res_range.r;
         if(finalHeight[b] == INF) finalHeight[b] = 0;
         //fprintf(stderr, "pos_left[%d] = %d, val = %d, range = [%d, %d]\n", b, rng.pos_left, finalHeight[b], res_range.l, res_range.r);
         return;
      }
      int m = (b + e) / 2;
      get_res(2*cn, b, m, tree[cn].inters(rng), finalHeight);
      get_res(2*cn+1, m+1, e, tree[cn].inters(rng), finalHeight);
   }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
   init(1, 0, n-1);
   for(int i = 0; i < k; i++) {
      if(op[i] == 1) upd(1, 0, n-1, left[i], right[i], Range{height[i], INF, 1});
      else upd(1, 0, n-1, left[i], right[i], Range{0, height[i], 0});
   }
   get_res(1, 0, n-1, Range{0, INF, -1}, finalHeight);
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 4 ms 612 KB Output is correct
3 Incorrect 13 ms 612 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 217 ms 14172 KB Output is correct
3 Execution timed out 3036 ms 14496 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14496 KB Output is correct
2 Correct 4 ms 14496 KB Output is correct
3 Incorrect 8 ms 14496 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14496 KB Output is correct
2 Correct 6 ms 14496 KB Output is correct
3 Incorrect 9 ms 14496 KB Output isn't correct
4 Halted 0 ms 0 KB -