Submission #342017

# Submission time Handle Problem Language Result Execution time Memory
342017 2021-01-01T04:04:18 Z MilosMilutinovic Wall (IOI14_wall) C++14
100 / 100
987 ms 94112 KB
/**
 *  author: milos
 *  created: 01.01.2021 04:18:07
**/
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 5e6 + 5;

struct segtree{
  int mn[N], mx[N], a[N];
  void build(int c, int x, int y) {
    if (mn[c] == 1e9) {
      return;  
    }
    mn[c] = 1e9, mx[c] = 0, a[c] = 0;
    if (x >= y) {
      return;
    }
    int mid = x + y >> 1;
    build(c * 2 + 1, x, mid);
    build(c * 2 + 2, mid + 1, y);
  }
  void push(int c, int x, int y) {
    a[c] = max(a[c], mx[c]);
    a[c] = min(a[c], mn[c]);
    if (x != y) {
      mx[2 * c + 1] = max(mx[c * 2 + 1], mx[c]);
      mx[2 * c + 1] = min(mx[c * 2 + 1], mn[c]);
      mn[2 * c + 1] = max(mn[c * 2 + 1], mx[c]);
      mn[2 * c + 1] = min(mn[c * 2 + 1], mn[c]);
      mx[2 * c + 2] = max(mx[c * 2 + 2], mx[c]);
      mx[2 * c + 2] = min(mx[c * 2 + 2], mn[c]);
      mn[2 * c + 2] = max(mn[c * 2 + 2], mx[c]);
      mn[2 * c + 2] = min(mn[c * 2 + 2], mn[c]); 
    }
    mn[c] = 1e9, mx[c] = 0;
  }
  void add(int c, int x, int y, int l, int r, int val) {
    push(c, x, y);
    if (x > y || x > r || y < l) {
      return;
    }
    if (x >= l && y <= r) {
      mx[c] = val;
      return;
    }
    int mid = x + y >> 1;
    add(c * 2 + 1, x, mid, l, r, val);
    add(c * 2 + 2, mid + 1, y, l, r, val);
  }
  void del(int c, int x, int y, int l, int r, int val) {
    push(c, x, y);
    if (x > y || x > r || y < l) {
      return;
    }
    if (x >= l && y <= r) {
      mn[c] = val;
      return;
    }
    int mid = x + y >> 1;
    del(c * 2 + 1, x, mid, l, r, val);
    del(c * 2 + 2, mid + 1, y, l, r, val);
  }           
} st;

vector<int> ans;

void Solve(int c, int l, int r) {
  if (l > r) {
    return;
  }
  st.push(c, l, r);
  if (l == r) {
    ans.push_back(st.a[c]);
    return;
  }  
  int mid = l + r >> 1;
  Solve(c * 2 + 1, l, mid);
  Solve(c * 2 + 2, mid + 1, r);
}

void buildWall(int n, int q, int* op, int* left, int* right, int* height, int* finalHeight) {
  st.build(0, 0, n - 1);
  for (int i = 0; i < q; i++) {
    if (op[i] == 1) {
      st.add(0, 0, n - 1, left[i], right[i], height[i]); 
    } else {
      st.del(0, 0, n - 1, left[i], right[i], height[i]); 
    }
  }
  Solve(0, 0, n - 1);
  for (int i = 0; i < n; i++) {
    finalHeight[i] = ans[i];
  }
}

Compilation message

wall.cpp: In member function 'void segtree::build(int, int, int)':
wall.cpp:22:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |     int mid = x + y >> 1;
      |               ~~^~~
wall.cpp: In member function 'void segtree::add(int, int, int, int, int, int)':
wall.cpp:50:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |     int mid = x + y >> 1;
      |               ~~^~~
wall.cpp: In member function 'void segtree::del(int, int, int, int, int, int)':
wall.cpp:63:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   63 |     int mid = x + y >> 1;
      |               ~~^~~
wall.cpp: In function 'void Solve(int, int, int)':
wall.cpp:80:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |   int mid = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 8 ms 1004 KB Output is correct
5 Correct 6 ms 1004 KB Output is correct
6 Correct 6 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 159 ms 8220 KB Output is correct
3 Correct 222 ms 4744 KB Output is correct
4 Correct 656 ms 12388 KB Output is correct
5 Correct 410 ms 12952 KB Output is correct
6 Correct 402 ms 13092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 7 ms 1004 KB Output is correct
5 Correct 7 ms 1004 KB Output is correct
6 Correct 6 ms 1004 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 160 ms 8172 KB Output is correct
9 Correct 221 ms 4844 KB Output is correct
10 Correct 652 ms 12388 KB Output is correct
11 Correct 410 ms 12900 KB Output is correct
12 Correct 405 ms 13028 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 158 ms 8172 KB Output is correct
15 Correct 36 ms 2028 KB Output is correct
16 Correct 654 ms 12644 KB Output is correct
17 Correct 407 ms 12772 KB Output is correct
18 Correct 409 ms 12644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 7 ms 1004 KB Output is correct
5 Correct 6 ms 1004 KB Output is correct
6 Correct 6 ms 1004 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 157 ms 8172 KB Output is correct
9 Correct 217 ms 4844 KB Output is correct
10 Correct 643 ms 12388 KB Output is correct
11 Correct 420 ms 12900 KB Output is correct
12 Correct 408 ms 12880 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 160 ms 8172 KB Output is correct
15 Correct 35 ms 1900 KB Output is correct
16 Correct 658 ms 12772 KB Output is correct
17 Correct 406 ms 12772 KB Output is correct
18 Correct 405 ms 12632 KB Output is correct
19 Correct 987 ms 83528 KB Output is correct
20 Correct 984 ms 91592 KB Output is correct
21 Correct 985 ms 94112 KB Output is correct
22 Correct 981 ms 91564 KB Output is correct
23 Correct 986 ms 91424 KB Output is correct
24 Correct 984 ms 91468 KB Output is correct
25 Correct 982 ms 91464 KB Output is correct
26 Correct 987 ms 94092 KB Output is correct
27 Correct 977 ms 93896 KB Output is correct
28 Correct 981 ms 91620 KB Output is correct
29 Correct 983 ms 91436 KB Output is correct
30 Correct 973 ms 91464 KB Output is correct