HDOJ 题目3954 Level up(线段树去见面更新区间查询)

Level up

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3890    Accepted Submission(s): 1086

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

Hint

Case 1:
At first ,the information of each hero is 0(1),0(1),0(1) [Exp(level)]
After first wave, 1(2),0(1),0(1);
After second wave, 3(3),1(2),0(1);
After third wave, 6(3),3(3),1(2);
Case 2:
The information of each hero finally:
18(5) 18(5) 25(5) 5(2) 9(2)

Author

NotOnlySuccess

Source

2011 Alibaba Programming Contest

Recommend

lcy   |   We have carefully selected several similar problems for you:  3340 3397 2871 1542 1828

很好的题,题目大意是有n个英雄,m个等级,q个操作,刚开始每个英雄都是等级1,经验0,下边m-1个整数,表示升每一级所需要的经验,下边跟q个操作,w a b c,区间【a,b】的英雄去打怪,获得的经验是英雄的等级*c,q a b,查询区间【a,b】中英雄最大的经验

ac代码

#include<stdio.h>
#include<string.h>
#define INF 0x3f3f3f3f
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
struct s
{
	__int64 level,maxnum,flag,need;
	void init()
	{
		level=1;
		maxnum=0;
		flag=0;
	}
	void fun(__int64 val)
	{
		maxnum+=level*val;
		need-=val;
		flag+=val;
	}
}node[10005<<2];
__int64 need[15];
void pushdown(int tr)
{
	if(node[tr].flag)
	{
		node[tr<<1].fun(node[tr].flag);
		node[tr<<1|1].fun(node[tr].flag);
		node[tr].flag=0;
	}
}
void pushup(int tr)
{
	node[tr].maxnum=max(node[tr<<1].maxnum,node[tr<<1|1].maxnum);
	node[tr].level=max(node[tr<<1].level,node[tr<<1|1].level);
	node[tr].need=min(node[tr<<1].need,node[tr<<1|1].need);
}
void build(int l,int r,int tr)
{
	node[tr].init();
	node[tr].need=need[2];
	if(l==r)
		return;
	int mid=(l+r)>>1;
	build(l,mid,tr<<1);
	build(mid+1,r,tr<<1|1);
}
void update(int L,int R,int l,int r,int tr,int val)
{
	if(L<=l&&r<=R)
	{
		if(val>=node[tr].need)
		{
			if(l==r)
			{
				__int64 &now=node[tr].level;
				node[tr].maxnum+=now*val;
				while(node[tr].maxnum>=need[now+1])
					now++;
				__int64 temp=need[now+1]-node[tr].maxnum;
				node[tr].need=temp/now+(temp%now!=0);
			}
			else
			{
				pushdown(tr);
				int mid=(l+r)>>1;
				if(L<=mid)
					update(L,R,l,mid,tr<<1,val);
				if(R>mid)
					update(L,R,mid+1,r,tr<<1|1,val);
				pushup(tr);
			}
		}
		else
		{
			node[tr].fun(val);
		}
		return;
	}
		pushdown(tr);
		int mid=(l+r)>>1;
		if(L<=mid)
			update(L,R,l,mid,tr<<1,val);
		if(R>mid)
			update(L,R,mid+1,r,tr<<1|1,val);
		pushup(tr);
}
__int64 query(int L,int R,int l,int r,int tr)
{
	if(L<=l&&r<=R)
	{
		return node[tr].maxnum;
	}
	pushdown(tr);
	int mid=(l+r)>>1;
	__int64 temp1=0,temp2=0;
	if(L<=mid)
		temp1=query(L,R,l,mid,tr<<1);
	if(R>mid)
		temp2=query(L,R,mid+1,r,tr<<1|1);
	pushup(tr);
	return max(temp1,temp2);
}
int main()
{
	int t,c=0;
	scanf("%d",&t);
	while(t--)
	{
		int n,m,q,i,j;
		scanf("%d%d%d",&n,&m,&q);
		for(i=2;i<=m;i++)
			scanf("%I64d",&need[i]);
		need[m+1]=INF;
		build(1,n,1);
		printf("Case %d:\n",++c);
		while(q--)
		{
			char op[5];
			scanf("%s",op);
			if(op[0]=='W')
			{
				int a,b,c;
				scanf("%d%d%d",&a,&b,&c);
				update(a,b,1,n,1,c);
			}
			else
			{
				int a,b;
				scanf("%d%d",&a,&b);
				printf("%I64d\n",query(a,b,1,n,1));
			}
		}
		printf("\n");
	}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-25 19:16:01

HDOJ 题目3954 Level up(线段树去见面更新区间查询)的相关文章

HDOJ 题目4339 Query(线段树,单点更新)

Query Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2859    Accepted Submission(s): 925 Problem Description You are given two strings s1[0..l1], s2[0..l2] and Q - number of queries. Your ta

HDU 3954 Level up 线段树

---NotOnlySuccess 出的题--- 看了题之后觉得和HDU 4027有点像,给的K很小,只有10,目测只要有人升级的时候直接更新到叶子节点就ok了.不过不同于HDU 4027 的是,那题每一次更新都相当于这题的一次升级操作,这题里面可能会出现一次操作之后没有升级和出现升级两种情况,一时半会没了思路. 无奈去搜题解,发现我只要维护一个区间当中距离升级最近的人所需要的基础升级经验,即不算等级加成的裸的升级经验,如果在一次涨经验之后,出现当前区间当中有人会升级,直接将每一个要升级的人更新

HDU 4027 Can you answer these queries?(线段树的单点更新+区间查询)

题目链接 题意 : 给你N个数,进行M次操作,0操作是将区间内的每一个数变成自己的平方根(整数),1操作是求区间和. 思路 :单点更新,区间查询,就是要注意在更新的时候要优化,要不然会超时,因为所有的数开几次方之后都会变成1,所以到了1不用没完没了的更新. 1 //HDU 4027 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <iostream> 6 #defi

POJ 3264-Balanced Lineup(线段树:单点更新+区间查询)

Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34522   Accepted: 16224 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh

HDOJ 题目4325 Flowers(线段树+离散化)

Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2493    Accepted Submission(s): 1235 Problem Description As is known to all, the blooming time and duration varies between different kind

HDOJ 题目2795 Billboard(线段树单点更新)

Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12813    Accepted Submission(s): 5579 Problem Description At the entrance to the university, there is a huge rectangular billboard of

HDOJ 题目3308 LCIS(线段树,区间查询,区间合并)

LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5319    Accepted Submission(s): 2361 Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. (ind

POJ 题目3667 Hotel(线段树,区间更新查询,求连续区间)

Hotel Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 13805   Accepted: 5996 Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie

线段树(成段更新) HDU 1698 Just a Hook

题目传送门 1 /* 2 线段树-成段更新:第一题!只要更新区间,输出总长度就行了 3 虽然是超级裸题,但是用自己的风格写出来,还是很开心的:) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cmath> 8 #include <cstring> 9 #include <string> 10 #include <iostream> 11 using namesp