Submission #59220

# Submission time Handle Problem Language Result Execution time Memory
59220 2018-07-21T08:28:00 Z ruhanhabib39 Wall (IOI14_wall) C++17
8 / 100
3000 ms 21272 KB
#include "wall.h"
#include <algorithm>
#include <cstdio>
#include <cassert>

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(rng.pos_left == -1) return *this;
         if(r < rng.l) {
            rng.pos_left = 1;
            return Range{rng.l, rng.l};
         }
         if(rng.r < l) {
            rng.pos_left = 0;
            return Range{rng.r, rng.r};
         }
         auto res = Range{std::max(l, rng.l), std::min(r, rng.r)};
         res.pos_left = pos_left;
         return res;
      }
   };

   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, Range prop = Range{0, INF, -1}) {
      //fprintf(stderr, "before prop tree[%d,%d] = {[%d,%d], %d}\n", b, e, tree[cn].l, tree[cn].r, tree[cn].pos_left);
      tree[cn] = tree[cn].inters(prop);
      //fprintf(stderr, "after prop tree[%d,%d] = {[%d,%d], %d}\n", b, e, tree[cn].l, tree[cn].r, tree[cn].pos_left);

      if(r < b || l > e) return;
      int m = (b + e) / 2;
      //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);
         if(b == e || tree[cn].pos_left == -1) {
            tree[cn] = tree[cn].inters(rng);
         } else {
            upd(2*cn, b, m, b, m, tree[cn]);
            upd(2*cn+1, m+1, e, m+1, e, tree[cn]);
            tree[cn] = rng;
         }
         //fprintf(stderr, "after tree[%d,%d] = {[%d,%d],%d}\n", b, e, tree[cn].l, tree[cn].r, tree[cn].pos_left);
         return;
      }
      prop = tree[cn];
      upd(2*cn, b, m, l, r, rng, prop);
      upd(2*cn+1, m+1, e, l, r, rng, prop);
      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);
         for(int i = b; i <= e; i++) {
            if(res_range.pos_left == 1 || res_range.pos_left == -1) finalHeight[i] = res_range.l;
            else finalHeight[i] = res_range.r;
         }
         //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;
      rng = tree[cn].inters(rng);
      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);
   //tree[0] = Range{0, 0, 1};
   for(int i = 0; i < k; i++) {
      Range rng;
      if(op[i] == 1) rng = Range{height[i], INF, 1};
      else rng = Range{0, height[i], 0};
      upd(1, 0, n-1, left[i], right[i], rng);
   }
   get_res(1, 0, n-1, Range{0, INF, -1}, finalHeight);
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 6 ms 616 KB Output is correct
4 Correct 125 ms 1220 KB Output is correct
5 Correct 450 ms 1352 KB Output is correct
6 Correct 459 ms 1416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1416 KB Output is correct
2 Correct 272 ms 11352 KB Output is correct
3 Execution timed out 3072 ms 11352 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11352 KB Output is correct
2 Correct 5 ms 11352 KB Output is correct
3 Correct 6 ms 11352 KB Output is correct
4 Correct 135 ms 11352 KB Output is correct
5 Correct 522 ms 11352 KB Output is correct
6 Correct 419 ms 11352 KB Output is correct
7 Correct 3 ms 11352 KB Output is correct
8 Correct 256 ms 17428 KB Output is correct
9 Execution timed out 3033 ms 17536 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 17536 KB Output is correct
2 Correct 6 ms 17536 KB Output is correct
3 Correct 5 ms 17536 KB Output is correct
4 Correct 162 ms 17536 KB Output is correct
5 Correct 547 ms 17536 KB Output is correct
6 Correct 634 ms 17536 KB Output is correct
7 Correct 2 ms 17536 KB Output is correct
8 Correct 190 ms 21272 KB Output is correct
9 Execution timed out 3041 ms 21272 KB Time limit exceeded
10 Halted 0 ms 0 KB -