답안 #560338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560338 2022-05-11T10:04:39 Z SSRS Pyramid Base (IOI08_pyramid_base) C++14
70 / 100
5000 ms 111528 KB
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000;
struct lazy_segment_tree{
  int N;
  vector<long long> ST, lazy;
  lazy_segment_tree(int N2){
    N = 1;
    while (N < N2){
      N *= 2;
    }
    ST = vector<long long>(N * 2 - 1, INF);
    for (int i = 0; i < N2; i++){
      ST[N - 1 + i] = 0;
    }
    for (int i = N - 2; i >= 0; i--){
      ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
    lazy = vector<long long>(N * 2 - 1, 0);
  }
  void eval(int i){
    if (i < N - 1){
      lazy[i * 2 + 1] += lazy[i];
      lazy[i * 2 + 2] += lazy[i];
    }
    ST[i] += lazy[i];
    lazy[i] = 0;
  }
  void range_add(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){
      lazy[i] += x;
      eval(i);
    } else {
      int m = (l + r) / 2;
      range_add(L, R, x, i * 2 + 1, l, m);
      range_add(L, R, x, i * 2 + 2, m, r);
      ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  void range_add(int L, int R, int x){
    range_add(L, R, x, 0, 0, N);
  }
  long long all(){
    eval(0);
    return ST[0];
  }
};
int main(){
  ios::sync_with_stdio(false);
  int M, N;
  cin >> M >> N;
  int B;
  cin >> B;
  int P;
  cin >> P;
  vector<int> X1(P), Y1(P), X2(P), Y2(P), C(P);
  for (int i = 0; i < P; i++){
    cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i] >> C[i];
    X1[i]--;
    Y1[i]--;
  }
  int tv = 0, fv = min(M, N) + 1;
  while (fv - tv > 1){
    int mid = (tv + fv) / 2;
    vector<vector<int>> add(N - mid + 2), sub(N - mid + 2);
    for (int i = 0; i < P; i++){
      add[max(Y1[i] - mid + 1, 0)].push_back(i);
      sub[min(Y2[i], N - mid + 1)].push_back(i);
    }
    lazy_segment_tree ST(M - mid + 1);
    bool ok = false;
    for (int i = 0; i < N - mid + 1; i++){
      for (int j : add[i]){
        ST.range_add(max(X1[j] - mid + 1, 0), min(X2[j], M - mid + 1), C[j]);
      }
      for (int j : sub[i]){
        ST.range_add(max(X1[j] - mid + 1, 0), min(X2[j], M - mid + 1), -C[j]);
      }
      if (ST.all() <= B){
        ok = true;
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 40268 KB Output is correct
2 Correct 735 ms 87376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 649 ms 80256 KB Output is correct
2 Correct 316 ms 40276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 980 KB Output is correct
2 Correct 79 ms 1692 KB Output is correct
3 Correct 69 ms 1804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 8944 KB Output is correct
2 Correct 473 ms 11700 KB Output is correct
3 Correct 361 ms 11556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 41304 KB Output is correct
2 Correct 362 ms 33976 KB Output is correct
3 Correct 225 ms 48972 KB Output is correct
4 Correct 1636 ms 80840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1281 ms 70156 KB Output is correct
2 Correct 1794 ms 85892 KB Output is correct
3 Correct 548 ms 41292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 897 ms 41872 KB Output is correct
2 Correct 2277 ms 86832 KB Output is correct
3 Correct 2279 ms 86080 KB Output is correct
4 Correct 2207 ms 86424 KB Output is correct
5 Correct 2600 ms 88516 KB Output is correct
6 Correct 308 ms 41356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5063 ms 99240 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5050 ms 101368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5073 ms 111528 KB Time limit exceeded
2 Halted 0 ms 0 KB -