Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const short LOVE = 1411;
- const int N = 1e5;
- typedef long long ll;
- int n;
- ll t[2*N];
- void update(int l, int r, ll x) {
- for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
- if (l&1) t[l++] += x;
- if (r&1) t[--r] += x;
- }
- }
- ll get(int i) {
- ll res = t[i += n];
- while (i >>= 1) res += t[i];
- return res;
- }
- int main(){
- //freopen("Test.INP", "r", stdin);
- //freopen("Test.OUT", "w", stdout);
- cin.tie(NULL)->sync_with_stdio(false);
- int k; cin >> n >> k;
- for (int i = 0; i < n; ++i) cin >> t[n + i];
- int ans = 0;
- for (int i = 0; i < n - 1; ++i) ans += t[n + i] > t[n + i + 1];
- for (int i = 0; i < k; ++i) {
- int l, r; ll x; cin >> l >> r >> x;
- --l, --r;
- if (r + 1 < n) ans -= get(r) > get(r + 1);
- if (l - 1 >= 0) ans -= get(l - 1) > get(l);
- update(l, r, x);
- if (r + 1 < n) ans += get(r) > get(r + 1);
- if (l - 1 >= 0) ans += get(l - 1) > get(l);
- cout << ans << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement