답안 #1072520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072520 2024-08-23T21:09:28 Z MilosMilutinovic Pyramid Base (IOI08_pyramid_base) C++14
86 / 100
5000 ms 220296 KB
#include <bits/stdc++.h>

using namespace std;

#define y1 fuaihcoia

const int N = (int) (4e5);

int n, m, b, k;
int x1[N], y1[N], x2[N], y2[N], c[N];

void Solve0() {
  vector<vector<vector<int>>> qs(n, vector<vector<int>>(2));
  for (int i = 0; i < k; i++) {
    qs[x2[i]][0].push_back(i);
    qs[x1[i]][1].push_back(i);
  }
  vector<array<int, 6>> st(4 * m);
  auto Push = [&](int x) {
    if (x * 2 + 1 >= 4 * m) {
      return;
    }
    st[x * 2][0] += st[x][1];
    st[x * 2][1] += st[x][1];
    st[x * 2 + 1][0] += st[x][1];
    st[x * 2 + 1][1] += st[x][1];
    st[x][1] = 0;
  };
  function<void(int, int, int)> Build = [&](int x, int l, int r) {
    int d = r - l + 1; 
    st[x] = {0, 0, d, d, d, d}; 
    if (l == r) {
      return;
    }
    int mid = (l + r) >> 1;
    Build(x * 2, l, mid);
    Build(x * 2 + 1, mid + 1, r);
  };
  function<void(int, int, int, int, int, int)> Modify = [&](int x, int l, int r, int ll, int rr, int v) {
    if (ll <= l && r <= rr) {
      st[x][0] += v;
      st[x][1] += v;
      Push(x);
      return;
    }
    Push(x);
    int mid = (l + r) >> 1;
    if (rr <= mid) {
      Modify(x * 2, l, mid, ll, rr, v);
    } else if (ll > mid) {
      Modify(x * 2 + 1, mid + 1, r, ll, rr, v);
    } else {
      Modify(x * 2, l, mid, ll, rr, v);
      Modify(x * 2 + 1, mid + 1, r, ll, rr, v);
    }
    st[x][0] = min(st[x * 2][0], st[x * 2 + 1][0]);
    st[x][2] = max({(st[x * 2][0] == st[x][0] ? st[x * 2][2] : 0), (st[x * 2 + 1][0] == st[x][0] ? st[x * 2 + 1][2] : 0), (st[x * 2][0] == st[x][0] ? st[x * 2][4] : 0) + (st[x * 2 + 1][0] == st[x][0] ? st[x * 2 + 1][3] : 0)}); 
    st[x][3] = (st[x * 2][0] == st[x][0] ? st[x * 2][3] : 0) + (st[x * 2][0] == st[x][0] && st[x * 2 + 1][0] == st[x][0] && st[x * 2][3] == st[x * 2][5] ? st[x * 2 + 1][3] : 0);
    st[x][4] = (st[x * 2 + 1][0] == st[x][0] ? st[x * 2 + 1][4] : 0) + (st[x * 2][0] == st[x][0] && st[x * 2 + 1][0] == st[x][0] && st[x * 2 + 1][4] == st[x * 2 + 1][5] ? st[x * 2][4] : 0);
  };
  Build(1, 0, m - 1);
  int ptr = n - 1;
  int res = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j : qs[i][0]) {
      Modify(1, 0, m - 1, y1[j], y2[j], 1);
    }
    while (ptr - i + 1 > (st[1][0] == 0 ? st[1][2] : 0)) {
      for (int j : qs[ptr][1]) {
        Modify(1, 0, m - 1, y1[j], y2[j], -1);
      }
      ptr -= 1;
    }
    res = max(res, ptr - i + 1);
  }
  cout << res << '\n';
}

void Solve1() {
  auto Check = [&](int d) {
    vector<vector<vector<int>>> qs(n + 1, vector<vector<int>>(2));
    for (int i = 0; i < k; i++) {
      qs[x1[i]][0].push_back(i);
      qs[min(n, x2[i] + d)][1].push_back(i);
    }
    vector<long long> mn(4 * m);
    vector<long long> lzy(4 * m);
    auto Push = [&](int x) {
      if (x * 2 + 1 >= 4 * m) {
        return;
      }
      mn[x * 2] += lzy[x];
      lzy[x * 2] += lzy[x];
      mn[x * 2 + 1] += lzy[x];
      lzy[x * 2 + 1] += lzy[x];
      lzy[x] = 0;
    };
    function<void(int, int, int, int, int, int)> Modify = [&](int x, int l, int r, int ll, int rr, long long v) {
      if (ll <= l && r <= rr) {
        mn[x] += v;
        lzy[x] += v;
        Push(x);
        return;
      }
      Push(x);
      int mid = (l + r) >> 1;
      if (rr <= mid) {
        Modify(x * 2, l, mid, ll, rr, v);
      } else if (ll > mid) {
        Modify(x * 2 + 1, mid + 1, r, ll, rr, v);
      } else {
        Modify(x * 2, l, mid, ll, rr, v);
        Modify(x * 2 + 1, mid + 1, r, ll, rr, v);
      }
      mn[x] = min(mn[x * 2], mn[x * 2 + 1]);
    };
    function<long long(int, int, int, int, int)> Query = [&](int x, int l, int r, int ll, int rr) {
      if (ll <= l && r <= rr) {
        return mn[x];
      }
      Push(x);
      int mid = (l + r) >> 1;
      long long res;
      if (rr <= mid) {
        res = Query(x * 2, l, mid, ll, rr);
      } else if (ll > mid) {
        res = Query(x * 2 + 1, mid + 1, r, ll, rr);
      } else {
        res = min(Query(x * 2, l, mid, ll, rr), Query(x * 2 + 1, mid + 1, r, ll, rr));
      }
      mn[x] = min(mn[x * 2], mn[x * 2 + 1]);
      return res;
    };
    for (int i = 0; i < n; i++) {
      for (int j : qs[i][0]) {
        Modify(1, 0, m - 1, max(0, y1[j] - d + 1), y2[j], c[j]);
      }
      for (int j : qs[i][1]) {
        Modify(1, 0, m - 1, max(0, y1[j] - d + 1), y2[j], -c[j]);
      }
      if (i + 1 >= d && Query(1, 0, m - 1, 0, m - d) <= b) {
        return true;
      }
    }
    return false;
  };
  int low = 1, high = min(n, m), res = 0;
  while (low <= high) {
    int mid = (low + high) >> 1;
    if (Check(mid)) {
      res = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  cout << res << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> b >> k;
  for (int i = 0; i < k; i++) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i] >> c[i];
    --x1[i]; --y1[i];
    --x2[i]; --y2[i];
  }
  if (b == 0) {
    Solve0();
  } else {
    Solve1();
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 182404 KB Output is correct
2 Correct 124 ms 184656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 182672 KB Output is correct
2 Correct 135 ms 182604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 6648 KB Output is correct
2 Correct 89 ms 4720 KB Output is correct
3 Correct 74 ms 6704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 468 ms 21812 KB Output is correct
2 Correct 863 ms 18828 KB Output is correct
3 Correct 710 ms 23596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2747 ms 184312 KB Output is correct
2 Correct 482 ms 90764 KB Output is correct
3 Correct 376 ms 68140 KB Output is correct
4 Correct 4235 ms 184552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3733 ms 184808 KB Output is correct
2 Execution timed out 5077 ms 184836 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3319 ms 185020 KB Output is correct
2 Execution timed out 5080 ms 185500 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 693 ms 202756 KB Output is correct
2 Correct 338 ms 112448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 852 ms 211828 KB Output is correct
2 Correct 819 ms 207436 KB Output is correct
3 Correct 560 ms 121772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 906 ms 220296 KB Output is correct
2 Correct 1260 ms 217520 KB Output is correct
3 Correct 1285 ms 217164 KB Output is correct
4 Correct 1060 ms 214852 KB Output is correct
5 Correct 788 ms 209340 KB Output is correct