传送门

分析

我们考虑把每个A[i]考虑为山峰的高度,每次的B考虑为海平面

于是我们知道对于A[i]和A[i-1],如果A[i-1]<A[i]则在A[i-1]<B<=A[i]时会使陆地总数加一

于是树状数组维护即可

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define N cnt
int D[],a[],opt[],b[],c[],d[];
int id[],cnt;
int lb(int x){return x&(-x);}
void add(int x,int k){while(x<=N)D[x]+=k,x+=lb(x);}
void update(int le,int ri,int k){add(le,k),add(ri+,-k);}
int q(int x){int res=;while(x){res+=D[x];x-=lb(x);}return res;}
int wh(int x){return lower_bound(id+,id+cnt+,x)-id;}
int main(){
int n,m,i,j,k;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)scanf("%d",&a[i]),id[++cnt]=a[i];
for(i=;i<=m;i++){
scanf("%d",&opt[i]);
if(opt[i]==)scanf("%d",&b[i]),id[++cnt]=b[i];
else scanf("%d%d",&c[i],&d[i]),id[++cnt]=d[i];
}
sort(id+,id+cnt+);
cnt=unique(id+,id+cnt+)-id-;
for(i=;i<=n;i++)
if(a[i]>a[i-])
update(wh(a[i-])+,wh(a[i]),);
for(i=;i<=m;i++){
if(opt[i]==)printf("%d\n",q(wh(b[i])));
else {
if(a[c[i]]<a[c[i]+])update(wh(a[c[i]])+,wh(a[c[i]+]),-);
if(a[c[i]-]<a[c[i]])update(wh(a[c[i]-])+,wh(a[c[i]]),-);
a[c[i]]=d[i];
if(a[c[i]]<a[c[i]+])update(wh(a[c[i]])+,wh(a[c[i]+]),);
if(a[c[i]-]<a[c[i]])update(wh(a[c[i]-])+,wh(a[c[i]]),);
}
}
return ;
}

ZROI #88的更多相关文章

  1. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)

    建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...

  2. long l=88;这个表达式是正确的,因为long比int类型大,会发生自动转换

    long l=88;这个表达式是正确的,因为long比int类型大,会发生自动转换

  3. 重新想象 Windows 8.1 Store Apps (88) - 通信的新特性: 新的 HttpClient

    [源码下载] 重新想象 Windows 8.1 Store Apps (88) - 通信的新特性: 新的 HttpClient 作者:webabcd 介绍重新想象 Windows 8.1 Store ...

  4. 程序清单 8-8 exec函数实例,a.out是程序8-9产生的可执行程序

    /* ============================================================================ Name : test.c Author ...

  5. #有如下值集合[11,22,33,44,55,66,77,88,99,90...],将所有大于66值保存至字典的一个key中,将小于66的值保存至大二个key的值

    #!/usr/bin/env python #有如下值集合[11,22,33,44,55,66,77,88,99,90...],将所有大于66值保存至字典的一个key中,将小于66的值保存至大二个ke ...

  6. leetcode 88

    88. Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as on ...

  7. BestCoder Round #88

    传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...

  8. iisapp 命令 弹出 iisschlp.wsc [88,25] 属性值无效 progid

    iisapp 命令 弹出 iisschlp.wsc [88,25] 属性值无效 progid 在执行iisapp.vbs时,可能会提示如下错误:Windows Script Component - f ...

  9. Part 86 to 88 Talking about Multithreading in C#

    Part 86   Multithreading in C# What is a Process: Process is what the operating system uses to facil ...

随机推荐

  1. LeetCode OJ:Sum Root to Leaf Numbers(根到叶节点数字之和)

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  2. LeetCode OJ:Binary Tree Right Side View(右侧视角下的二叉树)

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  3. KVM- 日常管理与配置

    KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理. 1.  查看KVM虚拟机配置文件及运行状态 (1) KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/ autostar ...

  4. hihocoder #1138 : Islands Travel

    题意,求1到n的最短路.不难想到单源最短路,难点在于数量级太大,因此如何建图是关键: 因为cost = min{|Xi-Xj|, |Yi-Yj|}:所以,点i的移动只有两种情况,. x距离最近的点,. ...

  5. sort--Linux下文本处理五大神器之三

    转自:http://www.cnblogs.com/dong008259/archive/2011/12/08/2281214.html sort命令是帮我们依据不同的数据类型进行排序,其语法及常用参 ...

  6. swing之复杂登陆界面的实现

    package jiemian; import gonggong.message; import gonggong.messageType; import gonggong.user; import ...

  7. 微信无法跳转appstore总结--应用宝微下载申请

    以前是有方法,可以实现微信下跳转appstore的. 大概就是把url改为:http://mp.weixin.qq.com/mp/redirect?url="跳转url"(可编码也 ...

  8. jenkins 参数化构建,获取git分支

    def heads= ("git ls-remote -h git@gitlab.com:*.git").execute()def headlist=heads.text.read ...

  9. POJ3292(素数筛选)

    Semi-prime H-numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8706   Accepted: 3 ...

  10. Day1--Python基础1--下半部分

    一..pyc是什么 1. Python是一门解释型语言? 我初学Python时,听到的关于Python的第一句话就是,Python是一门解释性语言,我就这样一直相信下去,直到发现了*.pyc文件的存在 ...