QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#533863 | #7622. Yet Another Coffee | longyin | WA | 4ms | 40848kb | C++20 | 2.8kb | 2024-08-26 15:40:36 | 2024-08-26 15:40:37 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
#define lc k << 1
#define rc k << 1 | 1
struct SegmentTree {
int l, r, idx;
ll mn, lazy;
};
SegmentTree tree[N * 4];
int a[N], r[N], w[N];
void pushup(int k) {
if (tree[lc].mn < tree[rc].mn) {
tree[k].mn = tree[lc].mn;
tree[k].idx = tree[lc].idx;
}
else {
tree[k].mn = tree[rc].mn;
tree[k].idx = tree[rc].idx;
}
}
void pushdown(int k, ll lazy) {
if (lazy == 0)
return;
int l = tree[k].l;
int r = tree[k].r;
int mid = (l + r) / 2;
tree[lc].lazy += lazy;
tree[rc].lazy += lazy;
tree[lc].mn += lazy;
tree[rc].mn += lazy;
tree[k].lazy = 0;
}
void build(int k, int l, int r) {
tree[k].l = l;
tree[k].r = r;
if (l == r) {
tree[k].mn = a[l];
tree[k].idx = l;
return;
}
int mid = (l + r) / 2;
build(lc, l, mid);
build(rc, mid + 1, r);
pushup(k);
}
void update(int k, int l, int r, int w) {
if (tree[k].l > r || tree[k].r < l)
return;
if (tree[k].l >= l && tree[k].r <= r) {
tree[k].mn += w;
tree[k].lazy += w;
return;
}
pushdown(k, tree[k].lazy);
update(lc, l, r, w);
update(rc, l, r, w);
pushup(k);
}
pair<int, int> query(int k, int l, int r) {
if (tree[k].l > r || tree[k].r < l)
return {INF, 0};
if (tree[k].l >= l && tree[k].r <= r)
return {tree[k].mn, tree[k].idx};
pushdown(k, tree[k].lazy);
auto p = query(lc, l, r);
auto q = query(rc, l, r);
if (p.first < q.first)
return p;
else
return q;
}
pair<int, int> tmp[N];
void solve() {
memset(tree, 0, sizeof tree);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
cin >> r[i] >> w[i];
tmp[i] = {r[i], w[i]};
}
sort(tmp + 1, tmp + m + 1);
build(1, 1, n);
for (int i = 1; i <= m; i++) {
update(1, 1, r[i], -w[i]);
}
int ans = 0;
for (int i = 1, cur = m; i <= n; i++) {
auto [mn, idx] = query(1, 1, n);
update(1, idx, idx, INF);
for (int j = cur; tmp[j].first >= idx; j--) {
update(1, 1, tmp[j].first, tmp[j].second);
}
cur = idx - 1;
ans += mn;
cout << ans << " ";
}
cout << endl;
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 40848kb
input:
5 10 14 17 37 59 65 53 73 68 177 160 111 10 177 5 193 2 30 3 63 2 339 3 263 5 178 2 190 9 23 10 328 10 200 9 8 3 391 6 230 12 9 152 306 86 88 324 59 18 14 42 260 304 55 3 50 2 170 1 252 7 811 1 713 7 215 10 201 4 926 8 319 19 20 182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...
output:
-2596 -2559 -2506 -2447 -2382 -2314 -2241 -2130 -1970 -1793 -3505 -3491 -3473 -3431 -3376 -3116 -2812 -1727 939 3843 7437 11299 -6527 -6496 -6448 -6374 -6258 -6092 -5913 -5632 -5313 -4366 -1381 2376 6611 11018 16053 22292 29121 36528 44236 -3219 -2987 -2572 -2102 -1095 639 3665 8091 13632 19725 ...
result:
wrong answer 16th numbers differ - expected: '-3317', found: '-3116'