CDOJ 1324 卿学姐与公主 分块
分块模板
#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 ;
}
CDOJ 1324 卿学姐与公主 分块的更多相关文章
- CDOJ 1324 卿学姐与公主(分块)
CDOJ 1324 卿学姐与公主(分块) 传送门: UESTC Online Judgehttp://acm.uestc.edu.cn/#/problem/show/1324 某日,百无聊赖的卿学姐打 ...
- cdoj 1324 卿学姐与公主 线段树裸题
卿学姐与公主 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit St ...
- UESTC 1324 卿学姐与公主 分块板子
#include<iostream> #include<cmath> using namespace std; ; //表示当前数在哪一块里面 int belong[maxn] ...
- UESTC - 1324 卿学姐与公主
题目链接 某日,百无聊赖的卿学姐打开了某11区的某魔幻游戏 在这个魔幻的游戏里,生活着一个美丽的公主,但现在公主被关押在了魔王的城堡中. 英勇的卿学姐拔出利刃冲向了拯救公主的道路. 走过了荒野,翻越了 ...
- CDOJ 1292 卿学姐种花 暴力 分块 线段树
卿学姐种花 题目连接: http://acm.uestc.edu.cn/#/problem/show/1292 Description 众所周知,在喵哈哈村,有一个温柔善良的卿学姐. 卿学姐喜欢和她一 ...
- cdoj1324卿学姐与公主
地址:http://acm.uestc.edu.cn/#/problem/show/1324 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others) Memo ...
- UESTC 1324:卿学姐与公主(分块)
http://acm.uestc.edu.cn/#/problem/show/1324 题意:…… 思路:卿学姐的学习分块例题. 分块是在线处理区间问题的类暴力算法,复杂度O(n*sqrt(n)),把 ...
- A - 卿学姐与公主(线段树+单点更新+区间极值)
A - 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- 卿学姐与公主 UESTC - 1324 分块模板题
题意:http://acm.uestc.edu.cn/#/problem/show/1324 中文题,自己看喽. 题解:分块模板,update时顺便更新块属性.ask时先判掉belong[l]==be ...
随机推荐
- HTML a标签 target属性作用
特殊的目标 有 4 个保留的目标名称用作特殊的文档重定向操作: _blank 浏览器总在一个新打开.未命名的窗口中载入目标文档. _self 这个目标的值对所有没有指定目标的 <a> 标签 ...
- git 客户端提交
01 按照git到本地 02 按照小乌龟操作面板, 03 (git 和小乌龟)自动加载到右键快捷方式
- Gentoo双网卡同时启用上内外网
引言:本文配置网络通过 OpenRC/netifrc 方法(net.*scritps)配置. 外网网卡:enp3s4 内网网卡:enp2s0 外网地址(通过路由器) IP: 192.168.1.10 ...
- something funny
something funny. #include <stdio.h> #include <windows.h> #define N 50 HANDLE hConsole; v ...
- Digi. Certificates: Key pairs usages
In short, we have some sort of algorithms to gen pair of private and public keys. The public key is ...
- @Autowired注解(转)
5.6.4 @Autowired注解 自Spring诞生以来,
- 【转】MapReduce的优化
相信每个程序员在编程时都会问自己两个问题“我如何完成这个任务”,以及“怎么能让程序运行得更快”.同样,MapReduce计算模型的多次优化也是为了更好地解答这两个问题. MapReduce计算模型的优 ...
- ARM驱动调试方法、思路总结、笔记
驱动程序的调试一. 打印: prink, 自制proc文件UBOOT传入console=ttySAC0 console=tty11. 内核处理UBOOT传入的参数console_setup add_p ...
- Ubuntu操作相关笔记
Eclipse添加图标 #sudo vim /usr/share/applications/eclipse.desktop 写入以下内容 [Desktop Entry] Name=Eclipse Co ...
- 设计模式 --迭代器模式(Iterator)
能够游走于聚合内的每一个元素,同时还可以提供多种不同的遍历方式. 基本概念: 就是提供一种方法顺序访问一个聚合对象中的各个元素,而不是暴露其内部的表示. 使用迭代器模式的优点: 遍历集合或者数 ...