Submission #1119017

# Submission time Handle Problem Language Result Execution time Memory
1119017 2024-11-26T13:35:34 Z vjudge1 Wall (IOI14_wall) C++17
100 / 100
2005 ms 44612 KB
#pragma GCC optimize("O3,unroll-loops")
 
#include <bits/stdc++.h>
 
#define                pii  pair<int, int>
#define                 fi  first
#define                 se  second
#define                 ld  long double
#define                 vi  vector<int>
#define                vii  vector<vector<int>>
#define             all(v)  (v).begin(), (v).end()
#define       rep(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i)
#define       per(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i)
 
using namespace std;
 
const int MOD = 1e9 + 7;
 
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
 
int mul(int a, int b) {
  (a *= b) %= MOD;
  return a;
}
 
int ceil(int x, int y) {
  return (x + y - 1) / y;
}
 
int bin_pow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = res * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return res;
}
 
template<class T> bool minimize(T& a, T b) {
  if (a > b) return a = b, true;
  return false;
}
 
template<class T> bool maximize(T& a, T b) {
  if (a < b) return a = b, true;
  return false;
}
 
const int maxn = 2e6 + 5;
const int SIZE = 1415;
 
int n, q;
int a[maxn + 5];
int left_bound[SIZE + 5], right_bound[SIZE + 5];
int moonx[SIZE + 5], moony[SIZE + 5];
 
void updatefull(int t, int x, int h) {
  if (t == 1) {
    moony[x] = max(moony[x], h);
    moonx[x] = max(moonx[x], h);
  } else {
    moonx[x] = min(moonx[x], h);
    moony[x] = min(moony[x], h);
  }
}
 
void updatemanual(int t, int x, int l, int r, int h) {
  for (int i = left_bound[x]; i <= right_bound[x]; ++i) {
    a[i] = min(a[i], moonx[x]);
    a[i] = max(a[i], moony[x]);
  }
  for (int i = l; i <= r; ++i) {
    if (t == 1) {
      a[i] = max(a[i], h);
    } else {
      a[i] = min(a[i], h);
    }
  }
  moonx[x] = (moony[x] = a[left_bound[x]]);
  for (int i = left_bound[x]; i <= right_bound[x]; ++i) {
    moonx[x] = max(a[i], moonx[x]);
    moony[x] = min(a[i], moony[x]);
  }
}
 
void buildWall(int N, int K, int op[], int left[], int right[], int height[], int finalHeight[]) {
  n = N, q = K;
  for (int i = 1; i <= n; ++i) {
    int x = ceil(i, SIZE);
    left_bound[x] = n + 1;
  }
  for (int i = 1; i <= n; ++i) {
    int x = ceil(i, SIZE);
    left_bound[x] = min(left_bound[x], i);
    right_bound[x] = i;
  }
  for (int _ = 0; _ < q; ++_) {
    int t, l, r, h;
    t = op[_];
    l = left[_] + 1;
    r = right[_] + 1;
    h = height[_];
    int block_l = ceil(l, SIZE);
    int block_r = ceil(r, SIZE);
    for (int i = block_l + 1; i <= block_r - 1; ++i)
      updatefull(t, i, h);
    if (block_l == block_r) { 
      updatemanual(t, block_l, l, r, h);
    } else {
      updatemanual(t, block_l, l, right_bound[block_l], h);
      updatemanual(t, block_r, left_bound[block_r], r, h);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int x = ceil(i, SIZE);
    if (moonx[x] != -1 && a[i] > moonx[x]) a[i] = moonx[x];
    if (moony[x] != -1 && a[i] < moony[x]) a[i] = moony[x];
    finalHeight[i - 1] = a[i];
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 17 ms 696 KB Output is correct
5 Correct 17 ms 712 KB Output is correct
6 Correct 13 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 120 ms 14076 KB Output is correct
3 Correct 634 ms 7652 KB Output is correct
4 Correct 1659 ms 18764 KB Output is correct
5 Correct 885 ms 19876 KB Output is correct
6 Correct 841 ms 18252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 15 ms 716 KB Output is correct
5 Correct 13 ms 716 KB Output is correct
6 Correct 16 ms 700 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 138 ms 13900 KB Output is correct
9 Correct 660 ms 7628 KB Output is correct
10 Correct 1630 ms 18824 KB Output is correct
11 Correct 897 ms 19888 KB Output is correct
12 Correct 914 ms 18320 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 126 ms 14088 KB Output is correct
15 Correct 102 ms 1580 KB Output is correct
16 Correct 1675 ms 19012 KB Output is correct
17 Correct 912 ms 18504 KB Output is correct
18 Correct 859 ms 18412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 17 ms 596 KB Output is correct
5 Correct 17 ms 596 KB Output is correct
6 Correct 17 ms 704 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 120 ms 14016 KB Output is correct
9 Correct 656 ms 7628 KB Output is correct
10 Correct 1636 ms 18712 KB Output is correct
11 Correct 909 ms 19772 KB Output is correct
12 Correct 893 ms 18324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 164 ms 14072 KB Output is correct
15 Correct 96 ms 1612 KB Output is correct
16 Correct 1710 ms 19084 KB Output is correct
17 Correct 836 ms 18508 KB Output is correct
18 Correct 930 ms 18508 KB Output is correct
19 Correct 1932 ms 44612 KB Output is correct
20 Correct 1941 ms 40296 KB Output is correct
21 Correct 1940 ms 44588 KB Output is correct
22 Correct 1858 ms 40016 KB Output is correct
23 Correct 2001 ms 40216 KB Output is correct
24 Correct 2001 ms 40192 KB Output is correct
25 Correct 1865 ms 40056 KB Output is correct
26 Correct 2003 ms 44456 KB Output is correct
27 Correct 2005 ms 44544 KB Output is correct
28 Correct 1900 ms 39988 KB Output is correct
29 Correct 1889 ms 40012 KB Output is correct
30 Correct 1927 ms 40036 KB Output is correct