Level up

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3973    Accepted Submission(s): 1104

Problem Description
Level up is the task of all online games. It's very boooooooooring. There is only level up in those games, except level up.
In a online game, there are N heroes numbered id from 1 to N, each begins with level 1 and 0 Experience. They need to kill monsters to get Exp and level up.


There are many waves of monsters, each wave, the heroes with id from li to ri will come to kill monsters and those hero with level k will get ei*k Exp. If one hero's Exp reach Needk then the hero level up to level k immediately.
After some waves, I will query the maximum Exp from li to ri.
Now giving the information of each wave and Needk, please tell me the answer of my query.
 
Input
The first line is a number T(1<=T<=30), represents the number of case. The next T blocks follow each indicates a case.
The first line of each case contains three integers N(1<=N<=10000), K(2<=K<=10) and QW(1<=QW<=10000)each represent hero number, the MAX level and querys/waves number.
Then a line with K -1 integers, Need2, Need3...Needk.(1 <= Need2 < Need3 < ... < Needk <= 10000).
Then QW lines follow, each line start with 'W' contains three integers li ri ei (1<=li<=ri<=N , 1<=ei<=10000); each line start with 'Q' contains two integers li ri (1<=li<=ri<=N).
 
Output
For each case, output the number of case in first line.(as shown in the sample output)
For each query, output the maximum Exp from li to ri.
Output a black line after each case.
 
Sample Input
2
3 3 5
1 2
W 1 1 1
W 1 2 1
Q 1 3
W 1 3 1
Q 1 3

5 5 8
2 10 15 16
W 5 5 9
W 3 4 5
W 1 1 2
W 2 3 2
Q 3 5
W 1 3 8
Q 1 2
Q 3 5

 
Sample Output
Case 1:
3
6

Case 2:
9
18
25

/*
hdu 3954 线段树 (标记) 给你n个人,然后打怪升级,如果当前人的等级为x,怪的经验为k,则这个人
可以得到x*k的经验。
然后k-1个数表示2-k即所需要的经验,假设你有leve[k]的经验,便能马上
升到k级。(最开始以为是k-1到k级要leve[k]的经验 TAT) 最开始只是记录的经验最大值MAX和add标记,然后更新最大值。
但是每次都要查找等级大小,感觉应该是TLE,但却一直WR.感觉很费解 然后借鉴了下别人的思路
新增了一个need和grade,即区间中升级所差经验的最小值,如果添加的经验小于
这个need,则更新这些标记即可.否则就找到那些需要升级的进行升级。 hhh-2016-03-22 22:48:41
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
int n,qw;
int k;
const int maxn = 10010;
struct node
{
int l,r,grade;
int Max;
int add,need;
int mid()
{
return (l+r)>>1;
}
} tree[maxn*10];
int leve[15]; void push_up(int i)
{
tree[i].Max = max(tree[lson].Max,tree[rson].Max);
tree[i].grade = max(tree[lson].grade,tree[rson].grade);
tree[i].need = min(tree[lson].need,tree[rson].need);
} void fin_level(int cur)
{
for(int i = tree[cur].grade; i < k; i++)
{
if(tree[cur].Max >= leve[i])
tree[cur].grade = i+1;
}
} void build(int l,int r,int i)
{
tree[i].l = l;
tree[i].r = r;
tree[i].Max = tree[i].add = 0;
tree[i].need = leve[1];
tree[i].grade = 1;
if(l == r)
{
return ;
}
int mid = tree[i].mid();
build(l,mid,lson);
build(mid+1,r,rson);
push_up(i);
} void push_down(int i)
{
if(tree[i].add)
{
tree[lson].add += tree[i].add;
tree[rson].add += tree[i].add;
tree[lson].Max += tree[i].add*tree[lson].grade;
tree[rson].Max += tree[i].add*tree[rson].grade;
tree[lson].need -= tree[i].add;
tree[rson].need -= tree[i].add;
tree[i].add = 0;
}
} void Insert(int i,int l,int r,int val)
{
push_down(i);
int mid = tree[i].mid();
if(tree[i].l == tree[i].r)
{
tree[i].Max += val*tree[i].grade;
fin_level(i);
tree[i].need = (leve[tree[i].grade]-tree[i].Max)/(tree[i].grade)+
((leve[tree[i].grade]-tree[i].Max)%(tree[i].grade)!=0);
return ;
}
else if(tree[i].l >= l && tree[i].r <= r)
{
if(tree[i].need > val)
{
tree[i].add += val;
tree[i].need -= val;
tree[i].Max += (ll)val*tree[i].grade;
return ;
}
push_down(i);
if(l <= mid)Insert(lson,l,r,val);
if(r > mid)Insert(rson,l,r,val);
push_up(i);
return;
}
if(l <= mid)Insert(lson,l,r,val);
if(r > mid)Insert(rson,l,r,val);
push_up(i);
} int query(int i,int l,int r)
{
if(tree[i].l >= l && tree[i].r <= r)
{
return tree[i].Max;
}
push_down(i);
int ma = 0;
int mid = tree[i].mid(); if(l <= mid)
ma =max(ma,query(lson,l,r));
if(r > mid)
ma =max(ma,query(rson,l,r));
return ma;
} int main()
{
int T,cas = 1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&k,&qw);
for(int i = 1; i < k; i++)
scanf("%d",&leve[i]);
build(1,n,1);
leve[0] = 0; leve[k] = 1<<30;
char ch[4];
int l,r;
int val;
printf("Case %d:\n",cas++);
for(int i = 1; i <=qw; i++)
{
scanf("%s",ch);
if(ch[0] == 'Q')
{
scanf("%d%d",&l,&r);
ll ma = query(1,l,r);
printf("%I64d\n",ma);
}
if(ch[0] == 'W')
{
scanf("%d%d%d",&l,&r,&val);
Insert(1,l,r,val);
}
}
printf("\n");
}
return 0;
}

  

hdu 3954 线段树 (标记)的更多相关文章

  1. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  2. hdu 3397 线段树双标记

    Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. hdu 2871 线段树(各种操作)

    Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  4. hdu 4267 线段树间隔更新

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  5. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  6. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  8. hdu 4533 线段树(问题转化+)

    威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  9. hdu 4052 线段树扫描线、奇特处理

    Adding New Machine Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. 利用python实现简单随机验证码

    #!/usr/bin/env python # -*- coding:utf-8 -*- import random temp ='' for i in range(6): num = random. ...

  2. android 自定义ScrollView实现背景图片伸缩(阻尼效果)

    android 自定义ScrollView实现强调内容背景图片伸缩(仿多米,qq空间背景的刷新) 看到一篇文章,自己更改了一下bug: 原文地址:http://www.aiuxian.com/arti ...

  3. 10-TypeScript中的接口

    接口是一种规约的约定,从接口继承的类必须实现接口的约定.在高级开发中,通常接口是用于实现各种设计模式的基础,没有接口,设计模式无从谈起. 定义接口: interface ILog{ recordlog ...

  4. 策略模式(Stratety)

    namespace StrategyPattern //策略模式 { /// <summary> /// 定义所以支持的算法的公共接口 /// </summary> abstr ...

  5. B+树介绍

    B+树 B+树和二叉树.平衡二叉树一样,都是经典的数据结构.B+树由B树和索引顺序访问方法(ISAM,是不是很熟悉?对,这也是MyISAM引擎最初参考的数据结构)演化而来,但是在实际使用过程中几乎已经 ...

  6. Mego(03) - ORM框架的新选择

    前言 从之前的两遍文章可以看出ORM的现状. Mego(01) - NET中主流ORM框架性能对比 Mego(02) - NET主流ORM框架分析 首先我们先谈下一个我们希望的ORM框架是什么样子的: ...

  7. 新概念英语(1-53)An interesting climate

    新概念英语(1-53)An interesting  climate What's the favourite subject of conversation in England? A:Where ...

  8. 新手解决jsp页面<%@报错的方法

    昨天菇凉我很崩溃的重装电脑系统(嗯,没错,第一次自己装系统,我可能是一个假的计算机系学生!),但这没难倒天生聪慧的我,都是小case~.这都不是重点,重点来了,当我火速配置好java的开发环境jdk, ...

  9. python--socket粘包

    socket粘包 1 什么是粘包 须知:只有TCP有粘包现象,UDP永远不会粘包,首先需要掌握一个socket收发消息的原理, 所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少 ...

  10. 最小二乘法多项式拟合的Java实现

    背景 由项目中需要根据一些已有数据学习出一个y=ax+b的一元二项式,给定了x,y的一些样本数据,通过梯度下降或最小二乘法做多项式拟合得到a.b,解决该问题时,首先想到的是通过spark mllib去 ...