CDOJ 1324 卿学姐与公主 分块
2024-09-09 13:50:45
分块模板
#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 ;
}
最新文章
- Android Activity的加载的模式
- [ASE]sprint2 总结 &; sprint3计划
- IO多路复用及ThreadingTCPServer源码阅读
- bootbox显示中文的按钮
- Leetcode: Max Sum of Rectangle No Larger Than K
- php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动
- 一行能装逼的JavaScript代码
- T语言TC发布脚本方法
- Hadoop MapReduce概念学习系列之shuffle大揭秘(十九)
- C# 6.0 的新特性
- VS2012(update3)编译Qt5.1.1 32位静态库debug-and-release版及结果分享
- 照片教你eclipse通过使用gradle 打包Android
- mvc5 解析route源码实现自己的route系统
- Javascript 进阶 继承
- 再谈async与await
- 虚拟机上的Ubuntu 文件系统成为只读模式的解决办法
- java多线程(6)---ThreadLocal
- (转)JMeter学习逻辑控制器
- EBS採购模块中的高速接收和高速接收事务
- 使用ORM进行前后端数据交互
热门文章
- magento获取一些值的方法函数
- C# 语言规范_版本5.0 (第14章 枚举)
- Javascript中valueOf与toString区别
- Linux nfs+autofs 环境搭建
- 【转】使用sinopia五步快速完成本地npm搭建
- Apache .htaccess语法之RewriteRule
- ZZNU 1988: Sn
- android 进程和线程管理
- 湖南多校对抗赛(2015.05.03)Problem A: Twenty-four point
- 用VulApps快速搭建各种漏洞环境