CodeforcesSep 26, 2025

Alice and Hairdresser

Hazrat Ali

Codeforces

To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.

Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:

  • 0 — Alice asks how much time the haircut would take if she would go to the hairdresser now.
  • 1 p d — p-th hairline grows by d centimeters.

Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.

Input

The first line contains three integers nm and l (1n,m1000001l109) — the number of hairlines, the number of requests and the favorite number of Alice.

The second line contains n integers ai (1ai109) — the initial lengths of all hairlines of Alice.

Each of the following m lines contains a request in the format described in the statement.

The request description starts with an integer ti. If ti=0, then you need to find the time the haircut would take. Otherwise, ti=1 and in this moment one hairline grows. The rest of the line than contains two more integers: pi and di (1pin1di109) — the number of the hairline and the length it grows by.

Output

For each query of type 0 print the time the haircut would take.

Example
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1

Solution
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<long long> a(n + 2);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  bool same = false;
  for (int i = 1; i <= n; i++) {
    if (!same and a[i] > l) {
      same = true;
      ans++;
    }
    if (a[i] <= l) {
      same = false;
    }
  }
  while (m--) {
    int T;
    cin >> T;
    if (T == 0) {
      cout << ans << endl;
    } else {
      long long p, d;
      cin >> p >> d;
      a[p] += d;
      bool new_one = a[p] - d <= l and a[p] > l;
      bool around_zeros = a[p - 1] <= l and a[p + 1] <= l;
      bool around_ones = a[p - 1] > l and a[p + 1] > l;
      if (new_one and around_zeros) {
        ans++;
      }
      if (new_one and around_ones) {
        ans--;
      }
    }
  }
  return 0;
}



Comments