A - 卿学姐与公主

Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

某日,百无聊赖的卿学姐打开了某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哦

#include<iostream>
#include<cstring>
#include<cstdio> using namespace std;
const int N = + ;
typedef long long LL;
LL T[N << ];
int M;
void Build(int n){
for(M = ; M <= n + ; M *= );
} void Updata(int n, int V){
for(T[n+=M] += V, n /= ; n; n /= )
T[n] = max(T[n << ], T[n << |]);
} LL Query(int s, int t){
LL ans = ;
for(s=s+M-, t=t+M+; s^t^; s/=, t/=){
if(~s&) ans = max(ans, T[s^]);
if(t&) ans = max(ans, T[t^]);
}
return ans;
} int main(){
int n, q;
scanf("%d %d", &n, &q);
Build( n );
int t, p, l, r, x;
while(q --){
scanf("%d", &t);
if(t == ){
scanf("%d %d", &p, &x);
Updata(p, x);
}else{
scanf("%d %d", &l, &r);
printf("%lld\n", Query(l, r));
}
}
return ;
}
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1 const int N = + ;
typedef long long LL;
LL T[N << ]; void PushUP(int rt){
T[rt] = max(T[rt << ], T[rt << |]);
} void Updata(int p, int c, int l, int r, int rt){
if(l == r){
T[rt] += c;
return ;
}
int m = (l + r) >> ;
if(p <= m) Updata(p, c, lson);
else Updata(p, c, rson);
PushUP( rt );
} LL Query(int L, int R, int l, int r, int rt){
if(L <= l && r <= R){
return T[rt];
}
int m = (l + r) >> ;
LL ret = ;
if(L <= m) ret = max(ret, Query(L, R, lson));
if(R > m) ret = max(ret, Query(L, R, rson));
return ret;
}
int main(){
int n, q;
scanf("%d %d", &n, &q);
int t, p, l, r, x;
while(q --){
scanf("%d", &t);
if(t == ){
scanf("%d %d", &p, &x);
Updata(p, x, , n, );
}else{
scanf("%d %d", &l, &r);
printf("%lld\n", Query(l, r, , n, ));
}
}
return ;
}

A - 卿学姐与公主(线段树+单点更新+区间极值)的更多相关文章

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

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

  2. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  3. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  4. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  5. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. hdu1166(线段树单点更新&区间求和模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...

  7. B - 卿学姐与基本法 (离散化+成段更新+区间求和)

    卿学姐与基本法 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  8. hdu2795(线段树单点更新&区间最值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...

  9. POJ 2892 Tunnel Warfare(线段树单点更新区间合并)

    Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7876   Accepted: 3259 D ...

随机推荐

  1. IDC机房跳线

    服务网卡口与配线架 这里有一根网线 记录方式 签 A:23FM-23U-T07 (配线架网线) B:23FM-23U-NIC1(服务器网线) 在配线架的机柜旁边一定写明了 跳线的对面的   交换和配线 ...

  2. java.lang.IllegalArgumentException: java.io.IOException: Alias name [tomcat] does not identify a key entry

    java.lang.IllegalArgumentException: java.io.IOException: Alias name [tomcat] does not identify a key ...

  3. linux 内存

    [转]Linux 查看内存(free buffer cache) 转自:http://elf8848.iteye.com/blog/1995638 Linux下如何查内存信息,如内存总量.已使用量.可 ...

  4. golang rabbitmq实践(啰嗦)

    目录 rabbitmq ubuntu下的配置 go 实现rabbitmq的消息收发 1:背景简介 我是一个.net一线开发,今年6月份离开帝都来到魔都,后入职于莫江互联网在线教育公司.现刚刚转正,在这 ...

  5. 【HDU6667】Roundgod and Milk Tea【贪心】

    题目大意:给你ai,bi,限制ai不能流向bi,求最大流 题解:贪心,对于第i个班级,考虑前i-1个班级匹配完剩余多少a,b,将这些ab对第i个班级进行贪心匹配 匹配完若第i个班级还有剩余的ab,考虑 ...

  6. tf_upgrade_v2.exe实验

    实验前 import tensorflow as tf import numpy as np #create data x_data=np.random.rand(100).astype(np.flo ...

  7. 向android模拟器打电话发短信的简单方法

    在开发android应用程序时,有时候需要测试一下向android手机拨打电话发送短信时该应用程序的反应.譬如编写一个广播接收器,来提示用户有短信收到或者处理短信,就需要向该手机发送短信来进行测试.这 ...

  8. 将DVD.iso 挂载到虚拟机

    将DVD.iso挂载到虚机之后,默认设备名是/dev/sr0 挂载DVD.iso文件到/mnt. 操作: mount /dev/sr0 /mnt 查看: ll /mnt

  9. Elasticsear搭建

    2.1:创建用户: (elasticsearch不能使用root用户) useradd angelpasswd angel 2.2:解压安装包 tar -zxvf elasticsearch-5.5. ...

  10. 常用的vi快捷方式

    一般情况来说: 0代表行首,$代表行末 $,G代表最后一行 光标移动 0 移动到本行最前面 $ 移动到本行最后 G 移动文件最后一行 nG 移动到文件第n行 gg 移动到文件第一行 n[space]移 ...