QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#355655 | #8286. Stacks | maxplus | WA | 6ms | 4932kb | C++20 | 2.3kb | 2024-03-17 01:13:31 | 2024-03-17 01:13:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1e5, S = 1 << 18;
array<int64_t, 4> t[S];
int64_t bal(int i) { return t[2 * i + 1][0] + t[2 * i + 2][1]; }
int64_t que(int i, int L, int R, int64_t cnt) {
if (R == L + 1) return t[i][0]? t[i][2] / t[i][0] * cnt: 0;
int M = (L + R) / 2;
if (cnt <= bal(i)) return que(2 * i + 1, L, M, cnt);
else return t[i][3] + que(2 * i + 2, M, R, cnt - max(bal(i), {}));
}
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, max(bal(i), {}));
t[i] = {max(bal(i), {}) + t[2 * i + 2][0],
min(bal(i), {}) + t[2 * i + 1][1], q + t[2 * i + 2][2], q};
}
int64_t getkill(int i, int L, int R, int r) {
if (R <= r) return t[i][1];
int M = (L + R) / 2;
if (r <= M) return getkill(2 * i + 1, L, M, r);
return min(getkill(2 * i + 2, M, R, r) + t[2 * i + 1][0], {}) + t[2 * i + 1][1];
}
int64_t getsum(int i, int L, int R, int r, int64_t cnt) {
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(getkill(2 * i + 2, M, R, r) + t[2 * i + 1][0], {}));
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<array<int64_t, 4>> ops[n + 1], qs[n];
vector<int64_t> ans(m, -1);
for (int i = 0; i < m; ++i) {
int t, r; cin >> t;
if (t == 3) {
int64_t k, p, q; cin >> k >> p >> q;
qs[--k].push_back({i, --p, q});
continue;
}
if (t == 1) {
int64_t l, x, y; cin >> l >> r >> x >> y;
ops[--l].push_back({i, 0, x, x * y});
} else {
int64_t l, w; cin >> l >> r >> w;
ops[--l].push_back({i, -w});
}
ops[r].push_back({i});
}
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);
}
for (int i = 0; i < m; ++i) if (~ans[i]) cout << ans[i] << '\n';
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 4932kb
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 98486697 647114751 123945 50793012 61782451 0 0 0 762429740 321140700 871619914 536311874 5361094892 0 1792521566 6640518748 2415375780 249435711 225987900 5250788038 1145132507 140071334 0 118545795 3086405469 5646099271 84280112 1232466642 4992966775 7968...
result:
wrong answer 306th numbers differ - expected: '14354515494', found: '319892845693988'