Submission #227983

# Submission time Handle Problem Language Result Execution time Memory
227983 2020-04-29T12:27:57 Z quocnguyen1012 Wall (IOI14_wall) C++14
100 / 100
1290 ms 100472 KB
#ifndef LOCAL
#include "wall.h"
#endif // LOCAL

#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array
#define lc id << 1
#define rc id << 1 | 1

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e6 + 5, mod = 1e9 + 7, inf = 1e9;;

int N;
int mx[4 * maxn],mn[4 * maxn];
int lzmin[4 * maxn], lzmax[4 * maxn];
int res[maxn];

void build(int id, int l, int r)
{
  lzmin[id] = inf;
  lzmax[id] = -inf;
  if(l == r) return;
  int mid = (l + r) / 2;
  build(lc, l, mid); build(rc, mid + 1, r);
}

void push(int id, int l, int r)
{
  mn[id] = min(mn[id], lzmin[id]);
  mn[id] = max(mn[id], lzmax[id]);
  mx[id] = min(mx[id], lzmin[id]);
  mx[id] = max(mx[id], lzmax[id]);
  if(l != r){
    lzmin[lc] = min(lzmin[lc], lzmin[id]);
    lzmin[rc] = min(lzmin[rc], lzmin[id]);
    lzmin[lc] = max(lzmin[lc], lzmax[id]);
    lzmin[rc] = max(lzmin[rc], lzmax[id]);

    lzmax[rc] = min(lzmax[rc], lzmin[id]);
    lzmax[lc] = min(lzmax[lc], lzmin[id]);
    lzmax[rc] = max(lzmax[rc], lzmax[id]);
    lzmax[lc] = max(lzmax[lc], lzmax[id]);

    lzmax[id] = -inf; lzmin[id] = inf;
  }
}

void modify(int L, int R, int val, int type, int id = 1, int l = 1, int r = N)
{
  push(id, l, r);
  if(R < l || r < L) return;
  if(L <= l && r <= R){
    if(type == 1){
      lzmin[id] = max(lzmin[id], val);
      lzmax[id] = max(lzmax[id], val);
    }
    else if(type == 2){
      lzmin[id] = min(lzmin[id], val);
      lzmax[id] = min(lzmax[id], val);
    }
    push(id, l, r);
    return;
  }
  int mid = (l + r) / 2;
  modify(L, R, val, type, lc, l, mid); modify(L, R, val, type, rc, mid + 1, r);
  mx[id] = max(mx[lc], mx[rc]);
  mn[id] = min(mn[lc], mn[rc]);
}

void comp(int id, int l, int r)
{
  push(id, l, r);
  if(l == r){
    assert(mx[id] == mn[id]);
    res[l] = mx[id];
    return;
  }
  int mid = (l + r) / 2;
  comp(lc, l, mid); comp(rc, mid + 1, r);
}

void buildWall(int _N, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
  N = _N;
  build(1, 1, N);
  for(int i = 0; i < k; ++i){
    modify(left[i] + 1, right[i] + 1, height[i], op[i]);
  }
  comp(1, 1, N);
  for(int i = 1; i <= N; ++i)
    finalHeight[i - 1] = res[i];
}
#ifdef LOCAL
signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  int tc; cin >> N >> tc;
  build(1, 1, N);
  while(tc--){
    int le, ri, op, h;
    cin >> op >> le >> ri >> h;
    modify(le + 1, ri + 1, h, op);
  }
  comp(1, 1, N);
  for(int i = 1; i <= N; ++i)
    cout << res[i] << ' ';
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 548 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 12 ms 1152 KB Output is correct
5 Correct 12 ms 1152 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 179 ms 8808 KB Output is correct
3 Correct 302 ms 5332 KB Output is correct
4 Correct 885 ms 13868 KB Output is correct
5 Correct 520 ms 14392 KB Output is correct
6 Correct 485 ms 14328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 13 ms 1280 KB Output is correct
5 Correct 12 ms 1152 KB Output is correct
6 Correct 13 ms 1152 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 176 ms 8696 KB Output is correct
9 Correct 308 ms 5420 KB Output is correct
10 Correct 889 ms 13816 KB Output is correct
11 Correct 509 ms 14328 KB Output is correct
12 Correct 492 ms 14328 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 181 ms 8696 KB Output is correct
15 Correct 52 ms 2680 KB Output is correct
16 Correct 904 ms 14176 KB Output is correct
17 Correct 515 ms 14200 KB Output is correct
18 Correct 516 ms 14200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 13 ms 1152 KB Output is correct
5 Correct 12 ms 1152 KB Output is correct
6 Correct 12 ms 1280 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 176 ms 8696 KB Output is correct
9 Correct 294 ms 5568 KB Output is correct
10 Correct 852 ms 13948 KB Output is correct
11 Correct 502 ms 14456 KB Output is correct
12 Correct 518 ms 14328 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 178 ms 8824 KB Output is correct
15 Correct 50 ms 2784 KB Output is correct
16 Correct 904 ms 14200 KB Output is correct
17 Correct 502 ms 14144 KB Output is correct
18 Correct 523 ms 14072 KB Output is correct
19 Correct 1264 ms 100344 KB Output is correct
20 Correct 1219 ms 97784 KB Output is correct
21 Correct 1290 ms 100344 KB Output is correct
22 Correct 1281 ms 97784 KB Output is correct
23 Correct 1230 ms 97656 KB Output is correct
24 Correct 1256 ms 97528 KB Output is correct
25 Correct 1276 ms 97852 KB Output is correct
26 Correct 1251 ms 100472 KB Output is correct
27 Correct 1289 ms 99960 KB Output is correct
28 Correct 1274 ms 97652 KB Output is correct
29 Correct 1252 ms 97400 KB Output is correct
30 Correct 1267 ms 97656 KB Output is correct