【Mail.Ru Cup 2018 Round 2 B】 Alice and Hairdresser

【链接】 我是链接,点我呀:)
【题意】

【题解】


因为只会增加。
所以。
一开始暴力算出来初始答案
每次改变一个点的话。
就只需要看看和他相邻的数字的值就好。
看看他们是不是大于l
分情况增加、减少答案就好

【代码】

#include <bits/stdc++.h>
#define LL long long
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;

const int N = 1e5;

int n,m,l;
int ans;
LL a[N+10];

int main(){
    scanf("%d%d%d",&n,&m,&l);
    rep1(i,1,n) scanf("%lld",&a[i]);
    rep1(i,1,n)
        if(a[i]>l){
            int j = i;
            while (j+1<=n && a[j+1]>l) j++;
            ans++;
            i = j;
        }
    rep1(i,1,m){
        int ope;
        scanf("%d",&ope);
        if (ope==0){
            printf("%d\n",ans);
        }else{
            int pos,delta;
            scanf("%d%d",&pos,&delta);
            if (a[pos]<=l && a[pos]+delta>l){
                int ll,rr;
                if (a[pos-1]>l) ll = 1;else ll = 0;
                if (a[pos+1]>l) rr = 1;else rr = 0;
                if (ll>0 && rr>0){
                    ans--;
                }else{
                    if (ll==0 && rr==0){
                        ans++;
                    }else{

                    }
                }
            }
            a[pos]+=delta;
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/AWCXV/p/9956659.html
今日推荐