This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 2e5 + 5;
const int oo = 1e9, mod = 1e9 + 7;
int n, m, k, a[N];
int nodes[4 * N], lazy[4 * N];
vector<int> arr;
void push_down(int c) {
nodes[c << 1] += lazy[c];
nodes[c << 1 | 1] += lazy[c];
lazy[c << 1] += lazy[c];
lazy[c << 1 | 1] += lazy[c];
lazy[c] = 0;
}
void update(int c, int cl, int cr, int l, int r, int val) {
if (l <= cl and cr <= r) {
nodes[c] += val;
lazy[c] += val;
return;
}
push_down(c);
int mid = cl + cr >> 1;
if (l <= mid) update(c << 1, cl, mid, l, r, val);
if (r > mid) update(c << 1 | 1, mid + 1, cr, l, r, val);
nodes[c] = min(nodes[c << 1], nodes[c << 1 | 1]);
}
void process() {
cin >> n >> m;
int cnt1 = 0, cnt2 = 0;
foru(i, 1, n) {
cin >> a[i];
if (a[i] % 2 == 1) update(1, 1, n, 1, i, -1);
update(1, 1, n, 1, min(n, 2 * i - 1), a[i] / 2);
cnt1 += a[i] % 2;
cnt2 += a[i] / 2;
}
while (m--) {
int x, y;
cin >> x >> y;
cnt1 -= a[x] % 2, cnt2 -= a[x] / 2;
if (a[x] % 2 == 1) update(1, 1, n, 1, x, 1);
update(1, 1, n, 1, min(n, 2 * x - 1), - a[x] / 2);
a[x] += y;
cnt1 += a[x] % 2, cnt2 += a[x] / 2;
if (a[x] % 2 == 1) update(1, 1, n, 1, x, -1);
update(1, 1, n, 1, min(n, 2 * x - 1), a[x] / 2);
int tmp = -nodes[1];
tmp = max(0ll, tmp);
int ans = cnt1 - tmp;
ans += (2 * cnt2 - 2 * ans) / 3;
cout << ans << "\n";
}
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
// dont stop
Compilation message (stderr)
Main.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int mid = cl + cr >> 1;
| ~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |