QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#297364 | #6630. Triangle Collection | A_programmer | 0 | 2ms | 3628kb | C++17 | 1.9kb | 2024-01-04 12:28:14 | 2024-01-04 12:28:14 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int n;
ll c[maxn], pre[maxn], pre2[maxn], pre3[maxn], suf[maxn];
#define ls k << 1
#define rs k << 1 | 1
struct segtree
{
struct segnode
{
int l, r;
ll mx, lz;
}t[maxn << 2];
inline void pushup(int k) { t[k].mx = max(t[ls].mx, t[rs].mx); }
inline void upd(int k, ll d) { t[k].mx += d; t[k].lz += d; }
inline void pushdown(int k)
{
if (t[k].lz)
{
upd(ls, t[k].lz);
upd(rs, t[k].lz);
t[k].lz = 0;
}
}
void build(int k, int l, int r)
{
t[k].l = l, t[k].r = r;
if (l == r)
{
t[k].mx = pre[l] - pre2[min(n, 2 * l - 1)];
return;
}
int mid = (l + r) >> 1;
build(ls, l, mid);
build(rs, mid + 1, r);
pushup(k);
}
void update(int k, int l, int r, ll d)
{
if (l <= t[k].l && t[k].r <= r)
{
upd(k, d);
return;
}
pushdown(k);
int mid = (t[k].l + t[k].r) >> 1;
if (l <= mid) update(ls, l, r, d);
if (r > mid) update(rs, l, r, d);
pushup(k);
}
ll query(int k, int l, int r)
{
if (l <= t[k].l && t[k].r <= r) return t[k].mx;
pushdown(k);
int mid = (t[k].l + t[k].r) >> 1; ll ans = 0;
if (l <= mid) ans = max(ans, query(ls, l, r));
if (r > mid) ans = max(ans, query(rs, l, r));
return ans;
}
}T;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> c[i];
pre[i] = pre[i - 1] + c[i] / 2;
pre2[i] = pre2[i - 1] + (c[i] & 1);
}
T.build(1, 1, n);
ll sum = pre[n];
while (q--)
{
int x, d;
cin >> x >> d;
sum -= c[x] / 2;
T.update(1, x, n, -c[x] / 2);
T.update(1, (x + 1) / 2, n, (c[x] & 1));
c[x] += d;
sum += c[x] / 2;
T.update(1, x, n, c[x] / 2);
T.update(1, (x + 1) / 2, n, -(c[x] & 1));
cout << sum - T.t[1].mx / 3 << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3476kb
input:
1 23 1485 1 -12 1 -30 1 -20 1 6 1 24 1 5 1 31 1 14 1 -34 1 -22 1 -45 1 37 1 46 1 9 1 22 1 -9 1 9 1 -46 1 -47 1 39 1 36 1 -36 1 50
output:
491 481 475 477 485 486 497 501 490 483 468 480 495 498 506 503 506 490 475 488 500 488 504
result:
wrong answer 3rd numbers differ - expected: '474', found: '475'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 0ms
memory: 3620kb
input:
1999 2000 1 1 1 1 0 2 0 2 1 0 2 1 2 2 2 1 2 0 0 1 2 2 0 1 0 1 0 2 0 0 2 1 1 1 1 0 1 2 1 2 1 1 1 1 1 0 2 2 0 2 1 1 2 0 0 2 0 0 2 1 2 0 0 1 1 2 0 2 2 2 1 2 0 2 1 2 0 1 2 2 2 1 1 2 1 1 1 1 0 0 1 1 0 1 2 1 0 0 2 0 2 2 2 0 1 1 2 0 0 1 0 0 2 1 2 1 2 0 1 1 2 2 0 0 1 2 2 1 2 1 2 2 2 0 0 1 1 2 1 1 2 2 2 2 2 ...
output:
660 660 660 661 661 661 661 660 660 660 660 661 662 662 663 663 662 661 662 662 661 660 661 660 660 660 661 661 661 661 662 661 661 660 661 660 659 658 658 659 659 658 659 660 660 660 660 660 660 659 659 659 659 659 659 659 659 660 659 658 658 658 658 657 657 657 658 657 656 657 657 657 656 656 655 ...
result:
wrong answer 615th numbers differ - expected: '660', found: '661'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 2ms
memory: 3628kb
input:
2000 1999 0 1 0 3 0 1 0 0 0 0 0 0 0 2 0 0 0 0 3 1 1 0 2 0 0 3 0 0 0 0 0 4 0 0 1 0 1 0 0 0 0 1 2 1 0 0 0 0 7 0 1 3 1 0 1 1 0 3 2 1 0 1 1 3 3 1 0 2 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 2 3 0 1 0 3 3 0 0 0 0 1 0 1 2 0 0 2 2 0 1 2 1 2 0 0 0 1 1 0 1 2 0 0 0 0 2 0 5 0 0 0 0 0 1 0 0 2 0 1 2 0 1 0 0 0 2 0 ...
output:
667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 667 666 667 667 667 667 667 667 667 666 667 667 667 667 666 666 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 666 666 667 667 667 667 666 667 667 667 667 667 666 666 ...
result:
wrong answer 1st numbers differ - expected: '666', found: '667'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%