题意: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 分块模板题的更多相关文章

  1. CDOJ 1324 卿学姐与公主(分块)

    CDOJ 1324 卿学姐与公主(分块) 传送门: UESTC Online Judgehttp://acm.uestc.edu.cn/#/problem/show/1324 某日,百无聊赖的卿学姐打 ...

  2. cdoj 1324 卿学姐与公主 线段树裸题

    卿学姐与公主 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit St ...

  3. cdoj1324卿学姐与公主

    地址:http://acm.uestc.edu.cn/#/problem/show/1324 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others)     Memo ...

  4. A - 卿学姐与公主(线段树+单点更新+区间极值)

    A - 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  5. UESTC 1324:卿学姐与公主(分块)

    http://acm.uestc.edu.cn/#/problem/show/1324 题意:…… 思路:卿学姐的学习分块例题. 分块是在线处理区间问题的类暴力算法,复杂度O(n*sqrt(n)),把 ...

  6. UESTC - 1324 卿学姐与公主

    题目链接 某日,百无聊赖的卿学姐打开了某11区的某魔幻游戏 在这个魔幻的游戏里,生活着一个美丽的公主,但现在公主被关押在了魔王的城堡中. 英勇的卿学姐拔出利刃冲向了拯救公主的道路. 走过了荒野,翻越了 ...

  7. CDOJ 1324 卿学姐与公主 分块

    题目地址 分块模板 #include<cstdio> #include<algorithm> #include<math.h> using namespace st ...

  8. UESTC 1324 卿学姐与公主 分块板子

    #include<iostream> #include<cmath> using namespace std; ; //表示当前数在哪一块里面 int belong[maxn] ...

  9. CDOJ1324-卿学姐与公主 【线段树点更新】

    http://acm.uestc.edu.cn/#/problem/show/1324 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others)     Memory ...

随机推荐

  1. map 集合的遍历

    List<Map<String,Object>> autoReplyList= wechatService.queryAutoReplyByOrg(orgId); for(Ma ...

  2. MyEclipse 10 下在线安装插件

    昨天不知道怎么就删除了电脑中的eclipse 我x,还原不回来了. 今天就安装了最新版本的myeclipse10,大家都知道,MyEclipse 中有一个烦人的 Software and Worksp ...

  3. Android学习之Spinner

    Android给我们提供了一个spinner控件,这个控件主要就是一个列表,那么我们就来说说这个控件吧,这个控件在以前的也看见过,但今天还是从新介绍一遍吧.Spinner位于 android.widg ...

  4. x64枚举DPC定时器

    @写在前面      不同于x86,x64的DPC是被加密了的.对于x64DPC的兴趣始于我已经流产的scalpel计划.当时问某牛怎么遍历,得到的答案是“500大洋给代码”.真是R了狗了,好歹小哥我 ...

  5. Android NDK学习(4)使用cygwin生成.so库文件

    转:http://www.cnblogs.com/fww330666557/archive/2012/12/14/2817389.html 简单的示例: makefile文件: LOCAL_PATH: ...

  6. 解决win764位安装pycrypto遇到unable to find vcvarsall.bat 问题

    今天安装pycrypto的库.安装中遇到一些问题,这里简单记录下来. 首先安装python,pycrypto是基于python的一个库. 第一种:搜索关键字pycrypto,找到pycrypto的官方 ...

  7. Word插入htm文件导致文本域动态增加的一个问题

    受html标签影响,超链接也会被变成文本域(HYPERLINK).当遍历文本域进行替换之前如果预存了文本域的数量(Count/Length/etc.)将导致遗漏.

  8. JDBC的驱动是如何加载的

    注:本文出处:http://www.cnblogs.com/jiaoyiping/ 转载请保留出处 JDBC定义了一套接口,数据库产品的提供商会实现这些接口来提供自己的数据库驱动程序,这是个很好的面向 ...

  9. shell脚本技巧记录

    2014/4/9 shell脚本变量处理: ${varible##*string} //从左向右截取最后一个string后的字符串 ${varible#*string} //从左向右截取第一个stri ...

  10. Promise在await报错后,如何继续往下跑...

    一.resolve 当a>0时,正常情况依次输出A.B.C console.log("A"); let result = await this.test(); console ...