QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355623#8286. StacksmaxplusWA 2ms4888kbC++202.6kb2024-03-16 23:36:592024-03-16 23:37:00

Judging History

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

  • [2024-03-16 23:37:00]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4888kb
  • [2024-03-16 23:36:59]
  • 提交

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 kill, int64_t sum) {
  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, kill, sum);
  else       upd(2 * i + 2, M, R, j, cnt, kill, sum);
  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;
  if (r <= M) return getkill(2 * i + 1, L, M, r);
  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) {
      int64_t 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) {
      int64_t l, r, w; cin >> l >> r >> w; --l;
      ops[l].push_back({i, -w});
      ops[r].push_back({i});
    } else {
      int64_t 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, k, s);
    }
    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
Wrong Answer
time: 2ms
memory: 4888kb

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:

0
3032090730
903396180
471569175
200648623
0
831792801
0
50793012
0
0
0
0
762429740
321140700
871619914
536311874
5361094892
0
1792521566
6640460369
2415375780
249435711
225987900
4347970203
1091232958
140071334
0
118545795
265158078
5646099271
0
1232466642
4992966775
7968862819
3943711826
0
0
42549...

result:

wrong answer 6th numbers differ - expected: '98486697', found: '0'