답안 #59065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59065 2018-07-20T11:37:54 Z ruhanhabib39 벽 (IOI14_wall) C++17
0 / 100
3000 ms 10172 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 rng;
         }
         if(rng.r < l) {
            rng.pos_left = 0;
            return rng;
         }
         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};
      if(op[i] == 1) upd(1, 0, n-1, left[i], right[i], rng);
      else upd(1, 0, n-1, left[i], right[i], rng);
   }
   get_res(1, 0, n-1, Range{0, INF, -1}, finalHeight);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 5 ms 616 KB Output is correct
3 Incorrect 6 ms 624 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 624 KB Output is correct
2 Correct 214 ms 10172 KB Output is correct
3 Execution timed out 3040 ms 10172 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10172 KB Output is correct
2 Correct 4 ms 10172 KB Output is correct
3 Incorrect 5 ms 10172 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10172 KB Output is correct
2 Correct 4 ms 10172 KB Output is correct
3 Incorrect 5 ms 10172 KB Output isn't correct
4 Halted 0 ms 0 KB -