http://blog.csdn.net/acm_cxlove/article/details/7548087

感觉最巧的是定义了min_dis……将区间内有无英雄升级分开处理

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> #define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define lc rt << 1
#define rc rt << 1 | 1 using namespace std; const int MAXN = ;
const int INF = << ; struct node
{
int exp, level;
int min_dis;
int flag;
}; int N, K, Q;
node Tr[ MAXN << ];
int sum[]; void build( int l, int r, int rt )
{
Tr[rt].exp = Tr[rt].flag = ;
Tr[rt].level = ;
Tr[rt].min_dis = sum[];
if ( l == r ) return ;
int m = ( l + r ) >> ;
build( lson );
build( rson );
return;
} void PushDown( int rt )
{
if ( Tr[rt].flag )
{
Tr[lc].exp += Tr[rt].flag * Tr[lc].level;
Tr[lc].min_dis -= Tr[rt].flag;
Tr[lc].flag += Tr[rt].flag; Tr[rc].exp += Tr[rt].flag * Tr[rc].level;
Tr[rc].min_dis -= Tr[rt].flag;
Tr[rc].flag += Tr[rt].flag; Tr[rt].flag = ;
}
return;
} void PushUp( int rt )
{
Tr[rt].level = max( Tr[lc].level, Tr[rc].level );
Tr[rt].exp = max( Tr[lc].exp, Tr[rc].exp );
Tr[rt].min_dis = min( Tr[lc].min_dis, Tr[rc].min_dis );
return;
} void Update( int L, int R, int v, int l, int r, int rt )
{
if ( l == r )
{
Tr[rt].exp += Tr[rt].level * v;
while ( Tr[rt].exp >= sum[ Tr[rt].level ] )
++Tr[rt].level;
Tr[rt].min_dis = ( sum[ Tr[rt].level ] - Tr[rt].exp ) / Tr[rt].level;
if( ( sum[ Tr[rt].level ] - Tr[rt].exp ) % Tr[rt].level ) ++Tr[rt].min_dis;
return;
}
int m = ( l + r ) >> ; if ( L == l && r == R )
{
if ( v >= Tr[rt].min_dis )
{
PushDown(rt);
if ( R <= m ) Update( L, R, v, lson );
else if ( L > m ) Update( L, R, v, rson );
else
{
Update( L, m, v, lson );
Update( m + , R, v, rson );
}
PushUp(rt);
}
else
{
Tr[rt].exp += Tr[rt].level * v;
Tr[rt].min_dis -= v;
Tr[rt].flag += v;
}
return;
} PushDown(rt); if ( R <= m ) Update( L, R, v, lson );
else if ( L > m ) Update( L, R, v, rson );
else
{
Update( L, m, v, lson );
Update( m + , R, v, rson );
} PushUp(rt); return;
} int Query( int L, int R, int l, int r, int rt )
{
if ( L <= l && r <= R ) return Tr[rt].exp;
PushDown(rt);
int m = ( l + r ) >> ;
int res = ;
if ( L <= m ) res = max( res, Query( L, R, lson ) );
if ( R > m ) res = max( res, Query( L, R, rson ) );
//PushUp(rt);
return res;
} int main()
{
int T;
int cas = ;
scanf( "%d", &T );
while ( T-- )
{
scanf( "%d%d%d", &N, &K, &Q );
for ( int i = ; i < K; ++i )
scanf( "%d", &sum[i] );
sum[K] = INF; build( , N, );
printf( "Case %d:\n", ++cas );
while ( Q-- )
{
char op[];
int a, b, c;
scanf( "%s", op );
if ( op[] == 'W' )
{
scanf( "%d%d%d", &a, &b, &c );
Update( a, b, c, , N, );
}
else
{
scanf( "%d%d", &a, &b );
printf("%d\n", Query( a, b, , N, ) );
}
}
puts("");
}
return ;
}

HDU 3954 Level up (线段树特殊懒惰标记)的更多相关文章

  1. hdu 3954 Level up(线段树)

    题目链接:hdu 3954 Level up 题目大意:N个英雄,M个等级,初始等级为1,给定每一个等级须要的经验值,Q次操作,操作分两种,W l r x:表示l~r之间的英雄每一个人杀了x个怪物:Q ...

  2. HDU 4107 Gangster(线段树 特殊懒惰标记)

    两种做法. 第一种:标记区间最大值和最小值,若区间最小值>=P,则本区间+2c,若区间最大值<P,则本区间+c.非常简单的区间更新. 最后发一点牢骚:最后query查一遍就行,我这个2B竟 ...

  3. HDU 3397 线段树 双懒惰标记

    这个是去年遗留历史问题,之前思路混乱,搞了好多发都是WA,就没做了 自从上次做了大白书上那个双重懒惰标记的题目,做这个就思路很清晰了 跟上次大白上那个差不多,这个也是有一个sets标记,代表这个区间全 ...

  4. poj3468 线段树的懒惰标记

    题目链接:poj3468 题意:给定一段数组,有两种操作,一种是给某段区间加c,另一种是查询一段区间的和 思路:暴力的方法是每次都给这段区间的点加c,查询也遍历一遍区间,复杂度是n*n,肯定过不去,另 ...

  5. HDU 3954 Level up(线段树)

    HDU 3954 Level up 题目链接 题意:k个等级,n个英雄,每一个等级升级有一定经验,每次两种操作,一个区间加上val,这样区间内英雄都获得当前等级*val的经验,还有一个操作询问区间经验 ...

  6. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  7. hdu 5700区间交(线段树)

    区间交 Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  8. HDU 3954 Level up(多颗线段树+lazy操作)

    又是一开始觉得的水题,结果GG了好久的东西... 题意是给你n个英雄,每个英雄开始为1级经验为0,最多可以升到k级并且经验一直叠加,每一级都有一个经验值上限,达到就升级.接着给你两种操作:W li r ...

  9. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

随机推荐

  1. Adobe CS2提供免费序列号

    据Adobe官方博客报道,自2012年12月13日起,因为技术故障,该公司已停止使用Creative Suite(CS2)产品及Acrobat 7的激活服务器. 这些产品大多是7年前发布,很多已经无法 ...

  2. bind改变this的指向

    <script type="text/javascript"> var Hello = function(){ this.setT = function(){ wind ...

  3. MySQL 中while loop repeat 的基本用法

    -- MySQL中的三中循环 while . loop .repeat 求 1-n 的和 -- 第一种 while 循环 -- 求 1-n 的和 /* while循环语法: while 条件 DO 循 ...

  4. git中.gitignore 文件

    现在项目的根目录放了 .gitignore 文件,并且git远程仓库的项目根目录已经有了 logs文件夹. 由于每次本地运行项目,都会生成新的log文件,但是我并不想提交logs文件夹里面的内容,所以 ...

  5. HttpContext.RewritePath

    定义:使用给定路径重写 URL.就是可以跳转到指定的URL. 也可以做为伪静态的跳转.具体如下. 他的重载 ①新建一个页面,放两个链接到另一个页面,注意给的链接 ②在 global.asax 文件中 ...

  6. JavaServlet 路径书写总结

    在写javaweb项目的时候,总会遇到路径书写的问题,现在将其作个总结. 在javaweb中需要书写路径的地方主要有这四大类: 客服端路径 超链接 表单 重定向 服务器端路径 转发 包含 资源获取路径 ...

  7. turtle画玫瑰花

    import turtle turtle.screensize(400, 300, "pink") turtle.setup(1000, 600) turtle.write('作者 ...

  8. ES6笔记01-声明变量

    ES6只有六种声明变量的方法:var命令和function命令,let和const命令,import命令和class命令.所以,ES6一共有6种声明变量的方法. const声明一个只读的常量.一旦声明 ...

  9. 谷歌浏览器如何调试JS

    平常在开发过程中,经常会接触到前端页面.那么对于js的调试那可是家常便饭,谷歌浏览器是常用来调试JS代码的工具,本文主要介绍如何利用谷歌浏览器来调试JS代码,协助我们进行开发工作,加快开发效率. 1. ...

  10. Linux基本的指令操作

    绝对路径: 路径的写法,由根目录/写起,例如:/usr/share/doc这个目录. 相对路径: 路径的写法,不由/写起,例如由/usr/share/doc要到/usr/share/man底下时,可以 ...