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

传送门:

UESTC Online Judge
http://acm.uestc.edu.cn/#/problem/show/1324

某日,百无聊赖的卿学姐打开了某11区的某魔幻游戏

在这个魔幻的游戏里,生活着一个美丽的公主,但现在公主被关押在了魔王的城堡中。

英勇的卿学姐拔出利刃冲向了拯救公主的道路。

走过了荒野,翻越了高山,跨过了大洋,卿学姐来到了魔王的第一道城关。

在这个城关面前的是魔王的精锐部队,这些士兵成一字排开。

卿学姐的武器每次只能攻击一个士兵,并造成一定伤害,卿学姐想知道某时刻从LL到RR这个区间内,从开始到现在累计受伤最严重的士兵受到的伤害。

最开始每个士兵的受到的伤害都是0

Input

第一行两个整数N,QN,Q表示总共有NN个士兵编号从11到NN,和QQ个操作。

接下来QQ行,每行三个整数,首先输入一个tt,如果tt是11,那么输入p,xp,x,表示卿学姐攻击了pp这个位置的士兵,并造成了xx的伤害。如果tt是22,那么输入L,RL,R,表示卿学姐想知道现在[L,R][L,R]闭区间内,受伤最严重的士兵受到的伤害。

1≤N≤1000001≤N≤100000

1≤Q≤1000001≤Q≤100000

1≤p≤N1≤p≤N

1≤x≤1000001≤x≤100000

1≤L≤R≤N1≤L≤R≤N

Output

对于每个询问,回答相应的值

Sample input and output

Sample Input Sample Output
5 4
2 1 2
1 2 4
1 3 5
2 3 3
0
5

Hint

注意可能会爆int哦

Source

2016 UESTC Training for Data Structures
 #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
int belong[maxn], num, l[maxn], r[maxn];
int n, q, block;
long long a[maxn], Max[maxn];
//num 分块的个数
//block 块的大小
//belong[i]表示i属于哪一块
//l[i]表示i这块的左端点位置
//r[i]表示i这块的右端点位置
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 query(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);
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", query(l, r));
}
return ;
}

CDOJ 1324 卿学姐与公主(分块)的更多相关文章

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

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

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

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

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

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

  4. UESTC - 1324 卿学姐与公主

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

  5. CDOJ 1292 卿学姐种花 暴力 分块 线段树

    卿学姐种花 题目连接: http://acm.uestc.edu.cn/#/problem/show/1292 Description 众所周知,在喵哈哈村,有一个温柔善良的卿学姐. 卿学姐喜欢和她一 ...

  6. cdoj1324卿学姐与公主

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

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

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

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

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

  9. 卿学姐与公主 UESTC - 1324 分块模板题

    题意:http://acm.uestc.edu.cn/#/problem/show/1324 中文题,自己看喽. 题解:分块模板,update时顺便更新块属性.ask时先判掉belong[l]==be ...

随机推荐

  1. bzoj3940 censoring 题解(AC自动机)

    题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...

  2. 牛客多校Round 8

    Solved:2 rank:164 签了两个oeis,但这样真的开心嘛

  3. python json格式和csv文件转换

    python json格式和csv文件转换 上代码 import csv import json ''' json格式示例 [{ "firstName":"Bill&qu ...

  4. Linux之修改主机名(永久生效)

    Linux系统安装好后,都会有默认的主机名,这里以CentOS系统为例,默认的主机名为localhost.localdomain,为了便于使用,我们常常需要修改主机名,下面演示的是永久更改主机名的方法 ...

  5. 爬虫之Re库

    一.常见匹配模式 \W # 匹配字母数字及下划线 \W # 匹配非字母数字下划线 \s # 匹配任意空白字符,等价于[\t\n\r\f] \S # 匹配任意非空字符 \d # 匹配任意数字,等价于[0 ...

  6. 日常操作之如何打开windows注册表

    1.打开注册表:第一步按“win+R”或者点击开始菜单,找到运行,在运行输入框里面输入“regedit”.

  7. LINUX-RPM 包 - (Fedora, Redhat及类似系统)

    rpm -ivh package.rpm 安装一个rpm包 rpm -ivh --nodeeps package.rpm 安装一个rpm包而忽略依赖关系警告 rpm -U package.rpm 更新 ...

  8. Django-Rest framework中文翻译-Request

    REST framework的Request类扩展自标准的HttpRequest,增加了REST framework灵活的请求解析和请求验证支持. 请求解析 REST framework的Reques ...

  9. 腾讯云:iptables基础

    iptables 基础 iptables 基本命令 任务时间:5min ~ 10min iptables 可以简单理解为 Linux 系统内核级防火墙 netfilter 的用户态客户端. Linux ...

  10. 数据库——mysql如何获取当前时间---https://www.cnblogs.com/Chenshuai7/p/5136469.html

    数据库——mysql如何获取当前时间 1.1 获得当前日期+时间(date + time)函数:now() -------https://www.cnblogs.com/Chenshuai7/p/51 ...