QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355604#8286. StacksmaxplusRE 0ms0kbC++202.5kb2024-03-16 22:47:172024-03-16 22:47:18

Judging History

你现在查看的是最新测评结果

  • [2024-03-16 22:47:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-03-16 22:47:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5, S = 1 << 18;

// cnt, kill, sum, lsum
array<int64_t, 4> t[S];

int64_t que(int i, int L, int R, int64_t cnt) {
  if (cnt <= 0) return 0;
  if (cnt >= t[i][0]) return t[i][2];
  if (R == L + 1) return t[i][2] / t[i][0] * cnt;
  int M = (L + R) / 2;
  if (cnt <= t[2 * i + 1][0] + t[2 * i + 2][1]) return que(2 * i + 1, L, M, cnt);
  else return t[i][3] + que(2 * i + 2, M, R, cnt - t[2 * i + 1][0] + t[2 * i + 2][1]);
}

void upd(int i, int L, int R, int j, int64_t cnt, int64_t sum, int64_t kill) {
  if (R == L + 1) return void(t[i] = {cnt, kill, sum});
  int M = (L + R) / 2;
  if (j < M) upd(2 * i + 1, L, M, j, cnt, sum, kill);
  else       upd(2 * i + 2, M, R, j, cnt, sum, kill);
  auto q = que(2 * i + 1, L, M, t[2 * i + 1][0] + t[2 * i + 2][1]);
  t[i] = {max(t[2 * i + 1][0] + t[2 * i + 2][1], {}) + t[2 * i + 2][0], t[2 * i + 1][1] + min(t[2 * i + 1][0] + t[2 * i + 2][1], {}), q + t[2 * i + 2][2], q};
}

int64_t getkill(int i, int L, int R, int r) {
  if (L >= r) return 0;
  if (R <= r) return t[i][1];
  int M = (L + R) / 2;
  return t[2 * i + 1][1] + min(getkill(2 * i + 2, M, R, r) + t[2 * i + 1][0], {});
}

int64_t getsum(int i, int L, int R, int r, int64_t cnt) {
  if (L >= r) return 0;
  if (R <= r) return que(i, L, R, cnt);
  int M = (L + R) / 2;
  if (r <= M) return getsum(2 * i + 1, L, M, r, cnt);
  int64_t lcnt = min(cnt, max(t[2 * i + 1][0] + getkill(2 * i + 2, M, R, r), {}));
  int64_t ans = que(2 * i + 1, L, M, lcnt);
  return ans + getsum(2 * i + 2, M, R, r, cnt - lcnt);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m; cin >> n >> m;
  vector<vector<array<int64_t, 4>>> ops(n + 1);
  vector<vector<array<int64_t, 3>>> qs(n);
  vector<int64_t> ans(m, -1);
  for (int i = 0; i < m; ++i) {
    int t; cin >> t;
    if (t == 1) {
      int l, r, x, y; cin >> l >> r >> x >> y; --l;
      ops[l].push_back({i, 0, x, x * y});
      ops[r].push_back({i});
    } else if (t == 2) {
      int l, r, w; cin >> l >> r >> w; --l;
      ops[l].push_back({i, -w});
      ops[r].push_back({i});
    } else {
      int k, p, q; cin >> k >> p >> q; --k;
      qs[k].push_back({i, p, q});
    }
  }
  for (int i = 0; i < n; ++i) {
    for (auto [i, k, c, s]: ops[i]) upd(0, 0, m, i, c, s, k);
    for (auto [i, p, q]: qs[i]) ans[i] = getsum(0, 0, m, i, q) - getsum(0, 0, m, i, p - 1);
  }
  for (int i = 0; i < m; ++i) if (~ans[i]) cout << ans[i] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4907 4910
2 763 3330 1
3 307 1 1
1 2262 3430 22699 89397
1 1915 4000 51541 67587
2 212 2990 9763
2 1086 2162 1
2 1813 4496 16760
1 51 2796 68005 99390
1 1267 1519 74236 66178
3 1768 23808 54314
2 900 4122 27758
3 3287 17350 28989
2 3277 4024 3633
2 444 4866 1
2 353 4219 1061
1 987 3141 99906 17320
2...

output:


result: