QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533874 | #7622. Yet Another Coffee | longyin | WA | 8ms | 41264kb | C++20 | 2.8kb | 2024-08-26 15:48:27 | 2024-08-26 15:48:28 |
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 = min(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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 41152kb
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 -3317 -3231 -3143 -2883 -2579 -2273 -1949 -6527 -6496 -6448 -6374 -6258 -6092 -5922 -5743 -5563 -5368 -5167 -4934 -4691 -4428 -4156 -3875 -3591 -3272 -2946 -3219 -2987 -2572 -2140 -1707 -1238 -768 -274 243 1...
result:
ok 70 numbers
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 41264kb
input:
2 5 2 1 2 3 4 5 3 1 4 2 7 3 4 3 1 10 3 8 6 4 9 3 8 4 5
output:
-2 0 3 7 12 -21 -18 -15 -9 -1 14 31
result:
wrong answer 9th numbers differ - expected: '-11', found: '-9'