답안 #576089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576089 2022-06-12T09:54:54 Z SSRS 벽 (IOI14_wall) C++14
100 / 100
751 ms 59300 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = 100000;
struct monoid{
  int mn, mx;
  monoid(): mn(0), mx(INF){
  }
  monoid(int mn, int mx): mn(mn), mx(mx){
  }
};
monoid f(monoid A, monoid B){
  if (B.mx < A.mn){
    B.mn = A.mn;
    B.mx = A.mn;
  } else if (B.mn > A.mx){
    B.mn = A.mx;
    B.mx = A.mx;
  } else {
    B.mn = max(B.mn, A.mn);
    B.mx = min(B.mx, A.mx);
  }
  return B;
}
struct dual_segment_tree{
  int N;
  vector<monoid> ST;
  dual_segment_tree(int N2){
    N = 1;
    while (N < N2){
      N *= 2;
    }
    ST = vector<monoid>(N * 2 - 1);
    for (int i = 0; i < N2; i++){
      ST[N - 1 + i] = monoid(0, 0);
    }
  }
  void eval(int i){
    if (i < N - 1){
      ST[i * 2 + 1] = f(ST[i], ST[i * 2 + 1]);
      ST[i * 2 + 2] = f(ST[i], ST[i * 2 + 2]);
      ST[i] = monoid();
    }
  }
  void range_chmax(int L, int R, int x, int i, int l, int r){
    eval(i);
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      ST[i] = f(monoid(x, INF), ST[i]);
    } else {
      int m = (l + r) / 2;
      range_chmax(L, R, x, i * 2 + 1, l, m);
      range_chmax(L, R, x, i * 2 + 2, m, r);
    }
  }
  void range_chmax(int L, int R, int x){
    range_chmax(L, R, x, 0, 0, N);
  }
  void range_chmin(int L, int R, int x, int i, int l, int r){
    eval(i);
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      ST[i] = f(monoid(0, x), ST[i]);
    } else {
      int m = (l + r) / 2;
      range_chmin(L, R, x, i * 2 + 1, l, m);
      range_chmin(L, R, x, i * 2 + 2, m, r);
    }
  }
  void range_chmin(int L, int R, int x){
    range_chmin(L, R, x, 0, 0, N);
  }
  int operator [](int i){
    i += N - 1;
    monoid ans = ST[i];
    while (i > 0){
      i = (i - 1) / 2;
      ans = f(ST[i], ans);
    }
    assert(ans.mn == ans.mx);
    return ans.mn;
  }
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
  dual_segment_tree ST(n);
  for (int i = 0; i < k; i++){
    right[i]++;
    if (op[i] == 1){
      ST.range_chmax(left[i], right[i], height[i]);
    }
    if (op[i] == 2){
      ST.range_chmin(left[i], right[i], height[i]);
    }
  }
  for (int i = 0; i < n; i++){
    finalHeight[i] = ST[i];
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 7 ms 624 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 5 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 130 ms 8044 KB Output is correct
3 Correct 181 ms 4168 KB Output is correct
4 Correct 438 ms 10572 KB Output is correct
5 Correct 294 ms 10572 KB Output is correct
6 Correct 275 ms 10468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 7 ms 596 KB Output is correct
5 Correct 6 ms 596 KB Output is correct
6 Correct 5 ms 596 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 131 ms 8088 KB Output is correct
9 Correct 170 ms 4124 KB Output is correct
10 Correct 452 ms 10620 KB Output is correct
11 Correct 295 ms 20656 KB Output is correct
12 Correct 288 ms 19352 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 134 ms 13968 KB Output is correct
15 Correct 37 ms 1884 KB Output is correct
16 Correct 624 ms 20172 KB Output is correct
17 Correct 288 ms 19596 KB Output is correct
18 Correct 305 ms 19660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 6 ms 596 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 7 ms 596 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 124 ms 8040 KB Output is correct
9 Correct 167 ms 4116 KB Output is correct
10 Correct 444 ms 10572 KB Output is correct
11 Correct 294 ms 20808 KB Output is correct
12 Correct 289 ms 19164 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 133 ms 13872 KB Output is correct
15 Correct 35 ms 1876 KB Output is correct
16 Correct 631 ms 20176 KB Output is correct
17 Correct 299 ms 19540 KB Output is correct
18 Correct 289 ms 19600 KB Output is correct
19 Correct 734 ms 59228 KB Output is correct
20 Correct 741 ms 59172 KB Output is correct
21 Correct 728 ms 59228 KB Output is correct
22 Correct 730 ms 59116 KB Output is correct
23 Correct 745 ms 59212 KB Output is correct
24 Correct 750 ms 59276 KB Output is correct
25 Correct 729 ms 59204 KB Output is correct
26 Correct 751 ms 59200 KB Output is correct
27 Correct 729 ms 59300 KB Output is correct
28 Correct 743 ms 59212 KB Output is correct
29 Correct 730 ms 59164 KB Output is correct
30 Correct 713 ms 59212 KB Output is correct