Colonial Mansions Gym - 101962I (线段树+二分)

After a year of hard work, Mano finally had a month off. He decided to take his grandmother to Soteropolis during this time. As soon as they arrived at the airport, Mano bought one of these "10 things to do in Soteropolis" travel guides. His grandmother instantly felt in love with pictures of the colonial mansions of Pelourinho, a historic neighborhood in western Soteropolis.

Pelourinho is a very big neighborhood. It is full of slopes and can be very trick for an elderly lady to explore. We can simplify its structure by imagining it as a line. The colonial mansions can be imagined as equally spaced spots on these lines: that is, from the ii-th mansion (from left to right), you can go to mansions i−1i−1 and i+1i+1, if such mansions exist. These mansions are called neighbors of mansion ii. Also, the ii-th mansion is hihi meters above sea level.

Mano knows that his grandmother will have serious difficulties in this kind of terrain. Your task is to write a computer program to answer some queries and help Mano plan his trip to Pelourinho. The two types of queries are described below:

  • 1 ii HH: the height of the ii-th mansion should be set to HH;
  • 2 ii HH: how many mansions Mano and his grandmother can visit if they start their trip at mansion ii and his grandmother can handle going from a mansion uu to a neighbor mansion vv iff |hu−hv|≤H|hu−hv|≤H?

Write a program to process these queries.

Input

The first line of the input contains two integers nn and qq (1≤n≤1051≤n≤105; 1≤q≤1051≤q≤105) - the number of colonial mansions and the number of queries you are asked to process, respectively.

The second line of the input contains nn integers. The ii-th of them is hihi (0≤hi≤1090≤hi≤109) – the height above the sea level of the ii-th mansion.

The next qq lines of the input will each describe a query, which will have the format shown in the statement (1≤i≤n1≤i≤n; 0≤H≤1090≤H≤109).

Output

For each operation of type 2, print a line with an integer – the number of colonial mansions Mano and his grandmother can visit in such scenario.

The queries should be processed in the order they are given in the input file.

Examples

Input

4 3
1 2 1 3
2 2 1
1 4 1
2 3 1

Output

3
4

Input

4 5
1 10 2 11
2 3 1
2 4 1
1 3 8
2 2 3
2 1 9

Output

1
1
3
4
#include 

using namespace std;
struct node
{
    int maxx, l, r;
}s[1000005];
int a[100005];
int n;
void build(int x,int l,int r)
{
    s[x].l = l;
    s[x].r = r;
    if(l == r)
    {
        s[x].maxx = abs(a[l] - a[l-1]);
        return ;
    }
    int mid = (l+r)/2;
    build(x*2,l,mid);
    build(x*2+1,mid+1,r);
    s[x].maxx = max(s[x*2].maxx,s[x*2+1].maxx);
}

int qu(int x, int l, int r)
{
    if(s[x].l > r || s[x].r < l)return -1;
    if(s[x].l == l && s[x].r == r)
    {
        return s[x].maxx;
    }
    int mid = (s[x].l + s[x].r) / 2;
    if(mid < l)return qu(x * 2 + 1, l, r);
    else if(mid >= r)return qu(x * 2, l, r);
    else return max(qu(x * 2, l, mid), qu(x * 2 + 1, mid + 1, r));
}
void change(int x, int l, int ad)
{
    //cout< l || s[x].r < l)return;
    if(s[x].l == l && s[x].r == l)
    {
        a[l] = ad;
        s[x].maxx = abs(a[l] - a[l - 1]);
        return ;
    }
    int mid = (s[x].l + s[x].r) / 2;
    if(mid >= l)change(x * 2, l, ad);
    else change(x * 2 + 1, l, ad);
    s[x].maxx = max(s[x * 2].maxx, s[x * 2 + 1].maxx);
}
void change(int x, int l)
{
    //cout< l || s[x].r < l)return;
    if(s[x].l == l && s[x].r == l)
    {
        s[x].maxx = abs(a[l] - a[l - 1]);
        return ;
    }
    int mid = (s[x].l + s[x].r) / 2;
    if(mid >= l)change(x * 2, l);
    else change(x * 2 + 1, l);
    s[x].maxx = max(s[x * 2].maxx, s[x * 2 + 1].maxx);
}
int solve(int x,int H)
{
    int l,r,i,ans=0;
    l = x,r = n;
    while(l < r-1)
    {
        int mid = (l+r)/2;
        if(qu(1,l+1,mid) > H)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
   // cout< H)
        {
            l  = mid;
        }
        else r = mid;
    }
    //cout<

 

你可能感兴趣的:(#,二分法,#,线段树)