Submission #722229

# Submission time Handle Problem Language Result Execution time Memory
722229 2023-04-11T15:21:37 Z joelgun14 Wall (IOI14_wall) C++17
0 / 100
281 ms 14124 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
const int lim = 1 << 13;
struct segment_tree {
  int lazymax[2 * lim], lazymin[2 * lim], a[2 * lim];
  segment_tree() {
    memset(a, 0, sizeof(a));
    fill(lazymin, lazymin + 2 * lim, 1e9);
    memset(lazymax, 0, sizeof(lazymax));
  }
  void propagate(int nd, int cl, int cr) {
    if(cl == cr) {
      a[nd] = max(lazymax[nd], a[nd]);
      a[nd] = min(lazymin[nd], a[nd]);
    }
    else {
      lazymax[2 * nd] = min(lazymin[nd], max(lazymax[2 * nd], lazymax[nd]));
      lazymin[2 * nd] = max(min(lazymin[2 * nd], lazymin[nd]), lazymax[nd]);
      lazymax[2 * nd + 1] = min(lazymin[nd], max(lazymax[2 * nd + 1], lazymax[nd]));
      lazymin[2 * nd + 1] = max(min(lazymin[2 * nd + 1], lazymin[nd]), lazymax[nd]);
    }
    lazymax[nd] = 0, lazymin[nd] = 1e9;
  }
  void update_max(int nd, int cl, int cr, int l, int r, int val) {
    propagate(nd, cl, cr);
    if(cl >= l && cr <= r) {
      lazymax[nd] = max(lazymax[nd], val);
      lazymin[nd] = max(lazymin[nd], val);
      propagate(nd, cl, cr);
    }
    else if(cl > r || cr < l) {
      return;
    }
    else {
      int mid = (cl + cr) / 2;
      update_max(2 * nd, cl, mid, l, r, val);
      update_max(2 * nd + 1, mid + 1, cr, l, r, val);
    }
  }
  void update_min(int nd, int cl, int cr, int l, int r, int val) {
    propagate(nd, cl, cr);
    if(cl >= l && cr <= r) {
      lazymax[nd] = min(lazymax[nd], val);
      lazymin[nd] = min(lazymin[nd], val);
      propagate(nd, cl, cr);
    }
    else if(cl > r || cr < l) {
      return;
    }
    else {
      int mid = (cl + cr) / 2;
      update_min(2 * nd, cl, mid, l, r, val);
      update_min(2 * nd + 1, mid + 1, cr, l, r, val);
    }
  }
  int query(int nd, int cl, int cr, int idx) {
    propagate(nd, cl, cr);
    if(cl == cr) {
      return a[nd];
    }
    else {
      int mid = (cl + cr) / 2;
      if(idx <= mid)
        return query(2 * nd, cl, mid, idx);
      else
        return query(2 * nd + 1, mid + 1, cr, idx);
    }
  }
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
  segment_tree seg;
  //cout << "SUCCEED 1 " << endl;
  for(int i = 0; i < k; ++i) {
    //cout << i << endl;
    if(op[i] == 1) {
      // max
      seg.update_max(1, 0, lim - 1, left[i], right[i], height[i]);
    }
    else {
      seg.update_min(1, 0, lim - 1, left[i], right[i], height[i]);
    }
  }
  for(int i = 0; i < n; ++i)
    finalHeight[i] = seg.query(1, 0, lim - 1, i);
  return;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 4 ms 568 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Incorrect 11 ms 684 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 281 ms 14124 KB Output is correct
3 Incorrect 129 ms 7576 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 428 KB Output is correct
2 Correct 6 ms 564 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Incorrect 7 ms 724 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Incorrect 7 ms 632 KB Output isn't correct
5 Halted 0 ms 0 KB -