QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#394862 | #6630. Triangle Collection | RedreamMer | 0 | 2ms | 6084kb | C++23 | 2.1kb | 2024-04-20 20:49:45 | 2024-04-20 20:49:45 |
answer
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
#define PB push_back
#define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) { rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1]; }
const int N = 2e5;
int a, b, s[N + 5], sum, w[N * 4 + 5], val[N + 5], mx[N * 4 + 5], tmp;
// int get(int n, int l, int r, int k) {
// if(k >= mx[n]) return mx[n];
// if(l == r) return k;
// int mid = (l + r) >> 1;
// if(k >= mx[rs]) return get(ls, l, mid, k - mx[rs]) + mx[rs];
// return get(rs, mid + 1, r, k);
// }
#define ls n << 1
#define rs n << 1 | 1
void add(int n, int l, int r, int k, int p) {
if(l == r) {
val[l] += p;
w[n] = max(0ll, val[l]);
mx[n] = max(0ll, -val[l]);
return;
}
int mid = (l + r) >> 1;
if(k <= mid) add(ls, l, mid, k, p);
else add(rs, mid + 1, r, k, p);
mx[n] = max(mx[rs], mx[ls] - w[rs]);
w[n] = max(0ll, w[rs] - mx[ls]) + w[ls];
}
void ins(int n, int m) {
sum += m;
if(s[n] & 1) add(1, 1, a, n, 1), ++sum;
tmp -= s[n] / 2;
add(1, 1, a, min(a, 2 * n - 1), -s[n] / 2);
s[n] += m;
if(s[n] & 1) add(1, 1, a, n, -1), --sum;
add(1, 1, a, min(a, 2 * n - 1), s[n] / 2);
tmp += s[n] / 2;
}
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> a >> b;
int x, y;
rep(i, 1, a) cin >> x, ins(i, x);
rep(i, 1, b) {
cin >> x >> y;
ins(x, y);
// cout << tmp << ' ' << w[1] << endl;
// rep(i, 1, a) cout << val[i] << " \n"[i == a];
cout << (sum + tmp - w[1]) / 3 << '\n';
}
return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 1ms
memory: 6004kb
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 474 476 484 486 496 501 489 482 467 479 495 498 505 502 505 490 474 487 499 487 504
result:
ok 23 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 6048kb
input:
12 1 13 79 59 21 32 13 85 40 74 15 49 56 3 31
output:
189
result:
ok 1 number(s): "189"
Test #3:
score: -5
Wrong Answer
time: 0ms
memory: 3964kb
input:
50 1995 3 2 3 0 3 0 5 2 2 2 3 0 4 5 4 4 3 0 1 0 5 5 3 4 3 3 1 1 4 5 5 4 1 1 3 1 4 2 1 3 4 1 5 5 0 3 0 3 4 3 49 1 48 -2 45 3 49 0 31 -4 13 0 15 -2 48 0 38 -2 8 0 48 3 12 1 22 -4 7 -5 5 -1 3 1 15 -2 37 -4 39 -1 24 -2 11 2 35 -2 17 -1 41 -2 20 5 8 0 18 0 26 -3 25 -3 49 -5 31 4 46 -2 38 0 42 3 16 -4 5 3...
output:
43 43 44 44 42 42 42 42 41 41 42 42 40 38 38 38 37 36 36 35 36 35 35 34 36 36 36 35 34 32 34 33 33 34 32 33 34 35 34 35 35 36 36 36 37 36 35 34 34 34 34 34 33 33 33 33 33 32 31 32 33 31 31 30 32 32 33 34 33 33 35 33 34 33 33 33 33 32 33 34 35 35 35 34 34 33 35 35 35 36 37 36 36 36 35 37 38 39 39 39 ...
result:
wrong answer 1st numbers differ - expected: '44', found: '43'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 1ms
memory: 4064kb
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:
547 547 547 548 548 548 548 547 547 547 547 548 548 548 549 549 548 547 548 548 548 547 547 547 547 547 547 547 547 547 548 547 547 546 547 546 545 544 544 545 545 544 545 545 545 545 545 546 546 545 545 545 545 545 545 545 545 546 545 545 545 545 545 544 544 544 544 544 543 544 544 544 543 543 542 ...
result:
wrong answer 1st numbers differ - expected: '660', found: '547'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 2ms
memory: 6084kb
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:
540 540 540 540 540 540 540 540 540 540 540 540 540 541 541 541 540 540 540 541 541 541 540 540 539 539 538 538 538 538 539 539 539 539 539 539 538 538 538 538 537 537 536 536 536 536 536 535 535 535 535 535 536 536 536 536 535 535 535 535 535 536 536 537 537 537 537 537 537 537 537 537 537 536 536 ...
result:
wrong answer 1st numbers differ - expected: '666', found: '540'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%