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(线段树)相关推荐

  1. hdu 3397 Sequence operation(线段树,lazy,区间合并)

    hdu 3397 Sequence operation 线段树lazy和区间合并结合的一个题,相当于几个题集中到一起嘛,分开想就好了 0,1,2操作都要lazy,2的异或操作找到每一只含1或只含0的区 ...

  2. 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)...

    HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...

  3. hdu 2871 Memory Control(线段树)

    题目链接:hdu 2871 Memory Control 题目大意:模拟一个内存分配机制. Reset:重置,释放全部空间 New x:申请内存为x的空间,输出左地址 Free x:释放地址x所在的内 ...

  4. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  5. HDU 4262 Juggler (模拟+线段树优化)

    转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove http://acm.hdu.e ...

  6. HDU 5669 Road(线段树建树)(分层图最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5669 [分析]线段树建树+分层图最短路 #include <cstdio> #includ ...

  7. HDU - I Hate It(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 Time Limit: 9000/3000 MS (Java/Others) Memory Li ...

  8. HDU - 3333 Turing Tree 线段树区间不同值和+详解+思想

    传送门 首先第一次做这种求不同元素和的线段树题,猜想是个裸题.但是题目中有一句话显然给题目降低了很大的难度,就是 想想其实它就是在暗示你这道题你要结合多次询问来处理,也就是所谓的离线,而不是一次一次的 ...

  9. HDU 3333-Turing Tree(线段树解决离线询问)

    题意: 给定一个长度为n的序列,给定m个查询,每次查询区间[L,R]范围内不同元素的和. 题解: x,yx,yx,y为查询的区间左右端点 用一个数组left[i]left[i]left[i],表示左边 ...

最新文章

  1. python 爬取网页照片!全代码!指定数量,指定目录,爬取过程详细!关于有下载照片过程但是不显示照片的问题的解释
  2. JAVA C++ 左花括号{该另起一行写还是写在行尾的思考
  3. python基础3(来自廖雪峰的官方网站)
  4. Codeforces 1284E New Year and Castle Building (计算几何)
  5. spring整合mybatis是如何配置事务的?
  6. spring学习记录(一)
  7. 一建机电实务教材电子版_必背!一建《机电实务》高频考点,每日一背
  8. java indexof方法_【3-14】Java中集合类list的增删改查
  9. 加密软件漏洞评测系统_调查:加密货币挖矿仍居恶意软件威胁前列
  10. 冯诺依曼计算机的组成
  11. 一笔订单,但是误付了两笔钱!这种重复付款异常到底该如何解决?
  12. dj鲜生-17-改造激活用户的代码-解决安全隐患
  13. C#学习成果 质数判断
  14. extjs4动态生成多表头
  15. flutter实现Icon可以用Image替换
  16. 64位windows系统 asp.net 对word Com 组件访问的设计.对于word2010/2007同样适用
  17. js工具栏悬浮提示文字js特效
  18. DDD中的“领域模型”
  19. skycons.js 基于canvas的天气动态图标小插件
  20. 关于控件注册和使用许可问题的解决办法

热门文章

  1. 默认子进程与父进程属于同一个进程组,所以注意对接受到的信号的处理方式
  2. AOV网拓扑排序(c/c++)
  3. Apache Beam和BigQuery的错误处理(Java SDK)
  4. 响应式网页之媒体查询
  5. 利用dynamic简化数据库的访问
  6. 关于Unity中物理检测的准备
  7. ASP.NET系统 + Access数据库
  8. 用于 Outlook 2003 的删除重复邮件的插件(加载项)
  9. request.getParameter()与request.setAttribute()的区别
  10. 【boundfield】GridView中BoundField与TemplateField的区别_boundfield