Submission #559895

# Submission time Handle Problem Language Result Execution time Memory
559895 2022-05-10T23:27:31 Z SSRS Pyramid Base (IOI08_pyramid_base) C++14
37 / 100
5000 ms 122892 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(){
  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(N, M) + 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 (i < N - mid){
        if (ST.all() <= B){
          ok = true;
        }
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 40252 KB Output is correct
2 Correct 697 ms 87184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 649 ms 80388 KB Output is correct
2 Correct 295 ms 40276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1108 KB Output is correct
2 Correct 76 ms 1796 KB Output is correct
3 Correct 72 ms 1932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 389 ms 9280 KB Output is correct
2 Incorrect 536 ms 12096 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 791 ms 41876 KB Output is correct
2 Incorrect 339 ms 34484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1224 ms 70736 KB Output is correct
2 Correct 1733 ms 86640 KB Output is correct
3 Incorrect 578 ms 42104 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 975 ms 42608 KB Output is correct
2 Incorrect 2148 ms 87684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5091 ms 100664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5089 ms 114636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5090 ms 122892 KB Time limit exceeded
2 Halted 0 ms 0 KB -