卿学姐与公主 UESTC - 1324 分块模板题
题意:http://acm.uestc.edu.cn/#/problem/show/1324 中文题,自己看喽。
题解:分块模板,update时顺便更新块属性。ask时先判掉belong[l]==belong[r]。build函数时直接用模板喽。
坑:打错了个字母,改了一下还改错了。还写错个括号。
ac代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<queue>
#include<string.h>
#include<iostream>
#include<cmath>
using namespace std;
const long long maxn = ;
int belong[maxn], num, block, l[maxn], r[maxn], n, q;
long long Max[maxn], a[maxn];
void build()
{
block = sqrt(n);
num = n / block;
if (n%block) num++;
for (int i = ; i <= num; i++)
l[i] = (i - ) * block + , r[i] = i*block;
r[num] = n;
for (int i = ; i <= n; i++) {
belong[i] = (i - ) / block + ;
} for (int i = ; i <= num; i++)
for (int j = l[i]; j <= r[i]; j++)
Max[i] = max(Max[i], a[j]); }
void update(int x, int y) {
a[x] += y;
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[belong[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[belong[y]]; i <= y; i++) {
ans = max(ans, a[i]);
}
return ans;
}
int main() {
scanf("%d%d", &n, &q);
build(); for (int i = ; i <= q; i++) {
int op, l, r;
scanf("%d%d%d", &op, &l, &r);
if (op == )update(l, r);
else printf("%lld\n", ask(l, r)); }
}
看到了2014年6月的卿学姐刷题推荐http://www.cnblogs.com/qscqesze/p/3852521.html 1320道题吧。。。Orz
卿学姐与公主 UESTC - 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 ...
- cdoj1324卿学姐与公主
地址:http://acm.uestc.edu.cn/#/problem/show/1324 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others) Memo ...
- 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 题意:…… 思路:卿学姐的学习分块例题. 分块是在线处理区间问题的类暴力算法,复杂度O(n*sqrt(n)),把 ...
- UESTC - 1324 卿学姐与公主
题目链接 某日,百无聊赖的卿学姐打开了某11区的某魔幻游戏 在这个魔幻的游戏里,生活着一个美丽的公主,但现在公主被关押在了魔王的城堡中. 英勇的卿学姐拔出利刃冲向了拯救公主的道路. 走过了荒野,翻越了 ...
- CDOJ 1324 卿学姐与公主 分块
题目地址 分块模板 #include<cstdio> #include<algorithm> #include<math.h> using namespace st ...
- UESTC 1324 卿学姐与公主 分块板子
#include<iostream> #include<cmath> using namespace std; ; //表示当前数在哪一块里面 int belong[maxn] ...
- CDOJ1324-卿学姐与公主 【线段树点更新】
http://acm.uestc.edu.cn/#/problem/show/1324 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others) Memory ...
随机推荐
- C#------如何处理缺少对公共可见类型或成员的xml注释的警告
出现警告的原因: 使用Swagger框架时 如图,只要加上注释就可以了 使用前: 使用后:
- 简单的面向过程的Redis存储加入购物车
群里有人问这个Redis存储用户购物车信息,我简单的写了个面向过程的demo 代码如下: <?php $user_id=session("user_id");//获取用户登录 ...
- Python 统计代码量
#统计代码量,显示离10W行代码还有多远 #递归搜索各个文件夹 #显示各个类型的源文件和源代码数量 #显示总行数与百分比 import os import easygui as g #查找文件 def ...
- 旺店通erp系统
http://www.wangdian.cn/ api 文档:https://wenku.baidu.com/view/cd0d21ffbd64783e08122b80.html
- PHP代码层防护与绕过
0x01 前言 在一些网站通常会在公用文件引入全局防护代码进行SQL注入.XSS跨站脚本等漏洞的防御,在一定程度上对网站安全防护还是比较有效的. 这里讨论一下关键字过滤不完善及常见正则匹配存在的问题, ...
- java.lang.IllegalArgumentException: No converter found for return value of type
原文地址: http://blog.csdn.net/linhaiguo/article/details/51554766 问题原因: 请求返回的数据无法转换,需要添加如下配置 解决方法: 1.在po ...
- ubuntu 手动安装mysql
申请了一台云主机,需要手动安装所有环境,今天将mysql安装过程记下. 安装mysqla. 下载不了gcc, 需要先运行apt-get updateb. cmake报错,每次要先删除cmakeCach ...
- iOS应用内支付(IAP)的那些坑
本文转载至 http://blog.devtang.com/2013/04/07/tricks-in-iap/ 前言 udacity 中的在线课程 <How to build a startup ...
- MySQL按照汉字拼音首字母排序
按照汉字的拼音排序,用的比较多是在人名的排序中,按照姓氏的拼音字母,从A到Z排序: 如果存储姓名的字段采用的是GBK字符集,那就好办了,因为GBK内码编码时本身就采用了拼音排序的方法(常用一级汉字37 ...
- Clock skewdetected. Your build may be incomplete.
解决方法: find . -type f | xargs -n touch make clean make