QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#119758 | #6630. Triangle Collection | batrr# | 0 | 22ms | 5668kb | C++23 | 1.9kb | 2023-07-05 17:26:15 | 2024-07-04 00:18:37 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;
int sum(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0)
a += mod;
return a;
}
int mult(int a, int b) {
return 1ll * a * b % mod;
}
int bp(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
int inv(int x) {
return bp(x, mod - 2);
}
int n, q;
ll a[N], s;
ll b[N];
/*
1 0 1
2 1 0
3 0 0
4 2 0
5 2 1
6 3 0
*/
void solve() {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s += a[i];
}
while (q--) {
int p, x;
{
cin >> p >> x;
s += x;
a[p] += x;
}
ll ans = 0;
for (int i = 1; i <= n; i++)
b[i] = a[i];
for (int i = n, j = n; i >= 1; i--) {
while (b[i] >= 2) {
j = min(j, i + i - 1);
while (j > i && b[j] == 0)
j--;
if(j == i)
break;
int x = min(b[i] / 2, b[j]);
b[i] -= 2 * x;
b[j] -= x;
ans += x;
}
ans += b[j] / 3;
b[j] %= 3;
}
cout << ans << "\n";
}
}
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << endl;
solve();
}
}
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: 5668kb
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: -5
Wrong Answer
time: 1ms
memory: 5664kb
input:
12 1 13 79 59 21 32 13 85 40 74 15 49 56 3 31
output:
188
result:
wrong answer 1st numbers differ - expected: '189', found: '188'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 22ms
memory: 5648kb
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:
658 658 658 658 658 658 658 658 658 658 658 659 660 659 660 660 659 658 659 659 658 657 658 657 657 657 657 657 657 657 657 656 656 656 657 656 655 654 654 654 655 654 654 655 655 655 655 655 654 654 654 654 654 654 654 654 654 655 654 653 653 653 653 652 652 651 652 651 651 651 651 651 650 650 650 ...
result:
wrong answer 1st numbers differ - expected: '660', found: '658'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 22ms
memory: 5640kb
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:
660 660 659 659 659 659 659 659 659 660 660 660 660 660 660 660 660 660 660 661 661 661 660 660 659 659 658 658 658 658 659 659 659 659 659 659 658 658 658 658 657 658 657 657 657 657 657 656 656 656 657 656 656 656 656 656 656 656 656 656 656 657 656 657 657 658 657 657 658 658 658 658 658 657 657 ...
result:
wrong answer 1st numbers differ - expected: '666', found: '660'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%