Alice and Hairdresser

Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...

To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most ll centimeters after haircut, where ll is her favorite number. Suppose, that the Alice's head is a straight line on which nn hairlines grow. Let's number them from 11 to nn. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length ll, given that all hairlines on that segment had length strictly greater than ll. 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:

  • 00 — Alice asks how much time the haircut would take if she would go to the hairdresser now.
  • 1pdd — pp-th hairline grows by dd centimeters.

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

Input

The first line contains three integers nn, mm and ll (1n,m1000001≤n,m≤100000, 1l1091≤l≤109) — the number of hairlines, the number of requests and the favorite number of Alice.

The second line contains nn integers aiai (1ai1091≤ai≤109) — the initial lengths of all hairlines of Alice.

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

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

Output

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

Example
input
Copy
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
output
Copy
1
2
2
1
Note

Consider the first example:

  • Initially lengths of hairlines are equal to 1,2,3,41,2,3,4 and only 44-th hairline is longer l=3l=3, and hairdresser can cut it in 11 second.
  • Then Alice's second hairline grows, the lengths of hairlines are now equal to 1,5,3,41,5,3,4
  • Now haircut takes two seonds: two swings are required: for the 44-th hairline and for the 22-nd.
  • Then Alice's first hairline grows, the lengths of hairlines are now equal to 4,5,3,44,5,3,4
  • The haircut still takes two seconds: with one swing hairdresser can cut 44-th hairline and with one more swing cut the segment from 11-st to 22-nd hairline.
  • Then Alice's third hairline grows, the lengths of hairlines are now equal to 4,5,4,44,5,4,4
  • Now haircut takes only one second: with one swing it is possible to cut the segment from 11-st hairline to the 44-th.

模拟:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
//#include <xfunctional>
#define ll long long
#define mod 998244353
using namespace std;
int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
const long long inf = 0x7f7f7f7f7f7f7f7f;
const int INT = 0x3f3f3f3f;

int main()
{
    int n, m, l, ans = 0;
    cin >> n >> m >> l;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] > l && (i + 1 > n || a[i + 1] <= l) && (i - 1<1 || a[i - 1] <= l))
            ans++;
    }
    while (m--)
    {
        int t;
        cin >> t;
        if (t)
        {
            int p, d;
            cin >> p >> d;
            if (a[p] <= l)
            {
                a[p] += d;
                if (a[p] > l && (p + 1 > n || a[p + 1] <= l) && (p - 1 < 1 || a[p - 1] <= l))
                {
                    ans++;
                }
                if (a[p] > l && p + 1 <= n && a[p + 1] > l && p - 1 >= 1 && a[p - 1] > l)
                    ans--;
            }
        }
        else
        {
            cout << ans << endl;
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/dealer/p/12373309.html