HDU 3954 Level up(线段树)
HDU 3954 Level up
题意:k个等级,n个英雄,每一个等级升级有一定经验,每次两种操作,一个区间加上val,这样区间内英雄都获得当前等级*val的经验,还有一个操作询问区间经验最大值
思路:由于等级少,所以每一个结点用Max[10]记录下每一个等级的最大值,假设有一个升级就一直找究竟,由于一个英雄升级最多10次,所以这个操作最多就10W次能够接受,剩下就是普通的区间改动区间查询的延迟操作了
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = 10005;
const int M = 11; int t, n, k, qw, need[M]; #define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2) struct Node {
int l, r, Max[M], add;
bool cover;
} node[N * 4]; void build(int l, int r, int x = 0) {
node[x].l = l; node[x].r = r;
memset(node[x].Max, -1, sizeof(node[x].Max));
node[x].Max[1] = 0;
node[x].add = 0;
node[x].cover = false;
if (l == r) return;
int mid = (l + r) / 2;
build(l, mid, lson(x));
build(mid + 1, r, rson(x));
} bool judge(int x, int v) {
for (int i = 1; i < k; i++) {
if (node[x].Max[i] == -1) continue;
if (node[x].Max[i] + i * v >= need[i + 1]) return true;
}
return false;
} void pushup(int x) {
node[x].cover = (node[lson(x)].cover && node[rson(x)].cover);
for (int i = 1; i <= k; i++)
node[x].Max[i] = max(node[lson(x)].Max[i], node[rson(x)].Max[i]);
} void pushdown(int x) {
if (node[x].add) {
node[lson(x)].add += node[x].add;
node[rson(x)].add += node[x].add;
for (int i = 1; i <= k; i++) {
if (node[lson(x)].Max[i] != -1)
node[lson(x)].Max[i] += node[x].add * i;
if (node[rson(x)].Max[i] != -1)
node[rson(x)].Max[i] += node[x].add * i;
}
node[x].add = 0;
}
} void add(int l, int r, int v, int x = 0) {
if (node[x].l >= l && node[x].r <= r && (node[x].cover || !judge(x, v))) {
node[x].add += v;
for (int i = 1; i <= k; i++) {
if (node[x].Max[i] == -1) continue;
node[x].Max[i] += i * v;
}
return;
}
if (node[x].l == node[x].r) {
int have;
for (int i = 1; i < k; i++) {
if (node[x].Max[i] != -1) {
have = node[x].Max[i] + i * v;
break;
}
}
memset(node[x].Max, -1, sizeof(node[x].Max));
for (int i = 2; i <= k; i++) {
if (have < need[i]) {
node[x].Max[i - 1] = have;
return;
}
}
node[x].Max[k] = have;
node[x].cover = true;
return;
}
int mid = (node[x].l + node[x].r) / 2;
pushdown(x);
if (l <= mid) add(l, r, v, lson(x));
if (r > mid) add(l, r, v, rson(x));
pushup(x);
} int query(int l, int r, int x = 0) {
if (node[x].l >= l && node[x].r <= r) {
for (int i = k; i >= 1; i--) {
if (node[x].Max[i] == -1) continue;
return node[x].Max[i];
}
}
int mid = (node[x].l + node[x].r) / 2;
int ans = 0;
pushdown(x);
if (l <= mid) ans = max(ans, query(l, r, lson(x)));
if (r > mid) ans = max(ans, query(l, r, rson(x)));
pushup(x);
return ans;
} int main() {
int cas = 0;
scanf("%d", &t);
while (t--) {
printf("Case %d:\n", ++cas);
scanf("%d%d%d", &n, &k, &qw);
for (int i = 2; i <= k; i++)
scanf("%d", &need[i]);
build(1, n);
char op[15];
int a, b, c;
while (qw--) {
scanf("%s%d%d", op, &a, &b);
if (op[0] == 'W') {
scanf("%d", &c);
add(a, b, c);
} else printf("%d\n", query(a, b));
}
printf("\n");
}
return 0;
}
HDU 3954 Level up(线段树)的更多相关文章
- hdu 3954 Level up(线段树)
题目链接:hdu 3954 Level up 题目大意:N个英雄,M个等级,初始等级为1,给定每一个等级须要的经验值,Q次操作,操作分两种,W l r x:表示l~r之间的英雄每一个人杀了x个怪物:Q ...
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU 3954 Level up(多颗线段树+lazy操作)
又是一开始觉得的水题,结果GG了好久的东西... 题意是给你n个英雄,每个英雄开始为1级经验为0,最多可以升到k级并且经验一直叠加,每一级都有一个经验值上限,达到就升级.接着给你两种操作:W li r ...
- HDU 4107 Gangster(线段树 特殊懒惰标记)
两种做法. 第一种:标记区间最大值和最小值,若区间最小值>=P,则本区间+2c,若区间最大值<P,则本区间+c.非常简单的区间更新. 最后发一点牢骚:最后query查一遍就行,我这个2B竟 ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
- HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- HDU 5820 (可持久化线段树)
Problem Lights (HDU 5820) 题目大意 在一个大小为50000*50000的矩形中,有n个路灯.(n<=500000) 询问是否每一对路灯之间存在一条道路,使得长度为|x1 ...
随机推荐
- 数学之路-python计算实战(2)-初遇pypy
PyPy是Python开发人员为了更好的Hack Python创建的项目.此外,PyPy比CPython是更加灵活,易于使用和试验,以制定详细的功能在不同情况的实现方法,能够非常easy实施. 该项目 ...
- <摘录>详谈高性能TCP服务器的开发
对于开发一款高性能服务器程序,广大服务器开发人员在一直为之奋斗和努力.其中一个影响服务器的重要瓶颈就是服务器的网络处理模块.如果一款服务器程序不能及时的处理用户的数据.则服务器的上层业务逻辑再高效也是 ...
- HDU 4296 Buildings (YY)
题意: 给定N个物体,每个物体有两个参数w,s. w代表它自身的重量: s代表它的强度.现在要把这些物体叠在一起,会产生一个PDV值. PDV解释:(Σwj)-si, where (Σwj) st ...
- Test oracle db iops
Today, i need to test one database's iops and do something for oracle db's io test. How to test the ...
- 无法安装vmware tools的解决方PLEASE WAIT! VMware Tools is currently being installed on your system. Dependin
VMware安装unbuntu 12.04 LTS时,当你使用VMware的Easy Mode安装时,提示须要安装VMware Tools,屏幕会出现下方的文字: installed unbuntu ...
- windows系统port监听
通常情况下.假设想发现全部已经使用的和正在监听的port,我们能够使用netstat命令. netstat并不是一个port扫描工具.假设你想扫描计算机开放了哪些port的话.建议使用本文介绍的方法. ...
- Delphi的组件读写机制
Delphi的组件读写机制(一) 一.流式对象(Stream)和读写对象(Filer)的介绍在面向对象程序设计中,对象式数据管理占有很重要的地位.在Delphi中,对对象式数据管理的支持方式是其一大特 ...
- [docker]coreOS与atomic对照
声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结,如有雷同,实属荣幸! 摘自https://majo ...
- DataReader和DataSet的区别以及使用
DataReader和DataSet这两个对象都可以将检索的关系数据存储在内存中.它们在功能使用方面非常相似,但是它们不可以相互替换. 主要区别如表所示: DataReader DataSet 数 ...
- C#整理
输入输出--数据类型--变量与常量--运算符表达式--语句(顺序.分支.循环)--数组--函数--结构体一.输入与输出.Console.ReadLine();Console.WriteLine();C ...