Submission #560356

# Submission time Handle Problem Language Result Execution time Memory
560356 2022-05-11T10:18:24 Z SSRS Pyramid Base (IOI08_pyramid_base) C++14
0 / 100
5000 ms 111832 KB
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000;
struct segment_tree{
  int N;
  vector<long long> sum, left;
  segment_tree(int N2){
    N = 1;
    while (N < N2){
      N *= 2;
    }
    sum = vector<long long>(N * 2 - 1, INF);
    left = vector<long long>(N * 2 - 1, INF);
    for (int i = 0; i < N2; i++){
      sum[N - 1 + i] = 0;
      left[N - 1 + i] = 0;
    }
    for (int i = N - 2; i >= 0; i--){
      sum[i] = sum[i * 2 + 1] + sum[i * 2 + 2];
      left[i] = 0;
    }
  }
  void add(int i, long long x){
    i += N - 1;
    sum[i] += x;
    left[i] = sum[i];
    while (i > 0){
      i = (i - 1) / 2;
      sum[i] = sum[i * 2 + 1] + sum[i * 2 + 2];
      left[i] = max(left[i * 2 + 1], sum[i * 2 + 1] + max(left[i * 2 + 2], (long long) 0));
    }
  }
  long long get(){
    return left[0];
  }
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  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);
    }
    segment_tree ST(M - mid + 1);
    bool ok = false;
    for (int i = 0; i < N - mid + 1; i++){
      for (int j : add[i]){
        ST.add(max(X1[j] - mid + 1, 0), C[j]);
        if (X2[j] < M - mid + 1){
          ST.add(X2[j], -C[j]);
        }
      }
      for (int j : sub[i]){
        ST.add(max(X1[j] - mid + 1, 0), -C[j]);
        if (X2[j] < M - mid + 1){
          ST.add(X2[j], C[j]);
        }
      }
      if (ST.get() <= B){
        ok = true;
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 10820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 693 ms 87192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 645 ms 86884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 1820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 260 ms 11688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1208 ms 85464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1421 ms 88692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1489 ms 82476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5097 ms 99376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5070 ms 102000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5031 ms 111832 KB Time limit exceeded
2 Halted 0 ms 0 KB -