题目地址

分块模板

 #include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
const int Nmax=;
int num,block,l[Nmax],r[Nmax],n,q,belong[Nmax];
long long Max[Nmax],a[Nmax]; void build()
{
block=sqrt(n);
num=n/block;
if(n%block) num++;
for(int i=;i<=n;i++)
{
l[i]=(i-)*block+;
r[i]=i*block;
belong[i]=(i-)/block+;
}
r[num]=n; for(int i=;i<=n;i++)
a[i]=; for(int i=;i<=num;i++)
for(int j=l[i];j<=r[i];j++)
Max[j]=max(Max[j],a[j]);
} void update(int x,int data)
{
a[x]+=data;
Max[belong[x]]=max(Max[belong[x]],a[x]);
} long long ask(int x,int y)
{
long long ans=;
if(belong[x]==belong[y])
{
for(int i=x;i<=y;i++)
{
ans=max(ans,a[i]);
}
return ans;
}
for(int i=x;i<=r[x];i++)
ans=max(ans,a[i]);
for(int i=belong[x]+;i<belong[y];i++)
ans=max(ans,Max[i]);
for(int i=l[y];i<=y;i++)
ans=max(ans,a[i]);
return ans;
} int main()
{
scanf("%d%d",&n,&q);
while(q--)
{
int c,x,y;
scanf("%d%d%d",&c,&x,&y);
if(c==)
update(x,y);
else
printf("%lld\n",ask(x,y));
}
return ;
}

最新文章

  1. Android Activity的加载的模式
  2. [ASE]sprint2 总结 &amp; sprint3计划
  3. IO多路复用及ThreadingTCPServer源码阅读
  4. bootbox显示中文的按钮
  5. Leetcode: Max Sum of Rectangle No Larger Than K
  6. php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动
  7. 一行能装逼的JavaScript代码
  8. T语言TC发布脚本方法
  9. Hadoop MapReduce概念学习系列之shuffle大揭秘(十九)
  10. C# 6.0 的新特性
  11. VS2012(update3)编译Qt5.1.1 32位静态库debug-and-release版及结果分享
  12. 照片教你eclipse通过使用gradle 打包Android
  13. mvc5 解析route源码实现自己的route系统
  14. Javascript 进阶 继承
  15. 再谈async与await
  16. 虚拟机上的Ubuntu 文件系统成为只读模式的解决办法
  17. java多线程(6)---ThreadLocal
  18. (转)JMeter学习逻辑控制器
  19. EBS採购模块中的高速接收和高速接收事务
  20. 使用ORM进行前后端数据交互

热门文章

  1. magento获取一些值的方法函数
  2. C# 语言规范_版本5.0 (第14章 枚举)
  3. Javascript中valueOf与toString区别
  4. Linux nfs+autofs 环境搭建
  5. 【转】使用sinopia五步快速完成本地npm搭建
  6. Apache .htaccess语法之RewriteRule
  7. ZZNU 1988: Sn
  8. android 进程和线程管理
  9. 湖南多校对抗赛(2015.05.03)Problem A: Twenty-four point
  10. 用VulApps快速搭建各种漏洞环境