2015 Multi-University Training Contest 3 hdu 5316 Magician
Magician
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 543 Accepted Submission(s): 151
Magicians, sorcerers, wizards, magi, and practitioners of magic by other titles have appeared in myths, folktales, and literature throughout recorded history, with fantasy works drawing from this background.
In medieval chivalric romance, the wizard often appears as a wise old man and acts as a mentor, with Merlin from the King Arthur stories representing a prime example. Other magicians can appear as villains, hostile to the hero.
Mr. Zstu is a magician, he has many elves like dobby, each of which has a magic power (maybe negative). One day, Mr. Zstu want to test his ability of doing some magic. He made the elves stand in a straight line, from position 1 to position n, and he used two kinds of magic, Change magic and Query Magic, the first is to change an elf’s power, the second is get the maximum sum of beautiful subsequence of a given interval. A beautiful subsequence is a subsequence that all the adjacent pairs of elves in the sequence have a different parity of position. Can you do the same thing as Mr. Zstu ?
Each of the test case begins with two integers n, m represent the number of elves and the number of time that Mr. Zstu used his magic.
(n,m <= 100000)
The next line has n integers represent elves’ magic power, magic power is between -1000000000 and 1000000000.
Followed m lines, each line has three integers like
type a b describe a magic.
If type equals 0, you should output the maximum sum of beautiful subsequence of interval [a,b].(1 <= a <= b <= n)
If type equals 1, you should change the magic power of the elf at position a to b.(1 <= a <= n, 1 <= b <= 1e9)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = ;
struct node{
LL a,b,c,d;
//分别代表奇奇、奇偶、偶偶、偶奇
}tree[maxn<<];
void pushup(node &z,const node &x,const node &y){
z.a = max(x.a,y.a);
z.a = max(z.a,x.a + y.d);
z.a = max(z.a,x.b + y.a);
z.b = max(x.b,y.b);
z.b = max(z.b,x.b + y.b);
z.b = max(z.b,x.a + y.c);
z.c = max(x.c,y.c);
z.c = max(z.c,x.c + y.b);
z.c = max(z.c,x.d + y.c);
z.d = max(x.d,y.d);
z.d = max(z.d,x.c + y.a);
z.d = max(z.d,x.d + y.d);
}
void build(int lt,int rt,int v){
if(lt == rt){
LL tmp;
scanf("%I64d",&tmp);
if(lt&){
tree[v].a = tmp;
tree[v].b = tree[v].c = tree[v].d = -INF;
}else{
tree[v].c = tmp;
tree[v].a = tree[v].b = tree[v].d = -INF;
}
return;
}
int mid = (lt + rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
pushup(tree[v],tree[v<<],tree[v<<|]);
}
void update(int L,int R,int lt,int rt,LL val,int v){
if(lt <= L && rt >= R){
if(lt&){
tree[v].a = val;
tree[v].b = tree[v].c = tree[v].d = -INF;
}else{
tree[v].c = val;
tree[v].a = tree[v].b = tree[v].d = -INF;
}
return;
}
int mid = (L + R)>>;
if(lt <= mid) update(L,mid,lt,rt,val,v<<);
if(rt > mid) update(mid+,R,lt,rt,val,v<<|);
pushup(tree[v],tree[v<<],tree[v<<|]);
}
node query(int L,int R,int lt,int rt,int v){
if(lt == L && rt == R) return tree[v];
int mid = (L + R)>>;
if(rt <= mid) return query(L,mid,lt,rt,v<<);
else if(lt > mid) return query(mid+,R,lt,rt,v<<|);
else{
node x = query(L,mid,lt,mid,v<<);
node y = query(mid+,R,mid+,rt,v<<|);
node z;
pushup(z,x,y);
return z;
}
}
int main(){
int kase,n,m,op,x,y;
LL val;
scanf("%d",&kase);
while(kase--){
scanf("%d%d",&n,&m);
build(,n,);
while(m--){
scanf("%d%d",&op,&x);
if(!op){
scanf("%d",&y);
node ret = query(,n,x,y,);
printf("%I64d\n",max(max(ret.a,ret.b),max(ret.c,ret.d)));
}else{
scanf("%I64d",&val);
update(,n,x,x,val,);
}
}
}
return ;
}
2015 Multi-University Training Contest 3 hdu 5316 Magician的更多相关文章
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- Extjs win
//创建window var win = Ext.create("Ext.window.Window", { id: "myWin", title: " ...
- 每日Linux命令--不完整命令
配置文件优化,即把默认的空行还有#注释行去掉,优化前先拷贝一份配置文件 egrep -v '^$|#' 拷贝的配置文件 > 原配置文件 mysql如何修改root用户的密码 方法1: 用SET ...
- springmvcjson中文乱码处理
在sping.xml中增加配置信息 <bean class="org.springframework.web.servlet.mvc.method.annotation.Request ...
- nignx 502错误不能使用/的路径方式 即pathinfo
在server中加入 include enable-php-pathinfo.conf; 引入nginx.conf下的这个文件即可. 如果是tp框架,主要隐藏index.php的入口文件,再加入下面这 ...
- 【hihocoder 1519】 逃离迷宫II
[题目链接]:http://hihocoder.com/problemset/problem/1519?sid=1098756 [题意] Chinese [题解] bfs题; 根据bfs的性质; 第一 ...
- 2015 Multi-University Training Contest 5 hdu 5349 MZL's simple problem
MZL's simple problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- Bootstrap组件之页头、缩略图
.page-header--指定div元素包裹页头组件. <div class="page-header"> <h1>小镇菇凉<small> 2 ...
- poj2528 Mayor's posters(线段树,离散化)
离散化的思想: 对于这样的数据 (3,10000). (9,1000000). (5.100000), (1,1000). (7,1000000) 我们能够将其处理为 (2,7). (5,9). (3 ...
- Session小案例-----简单购物车的使用
Session小案例-----简单购物车的使用 同上篇一样,这里的处理请求和页面显示相同用的都是servlet. 功能实现例如以下: 1,显示站点的全部商品 2.用户点击购买后,可以记住用户选择的商品 ...
- m_Orchestrate learning system---五、学的越多,做的越快
m_Orchestrate learning system---五.学的越多,做的越快 一.总结 一句话总结: 1.上传的图像文件用input('post.')方法取不到是为什么? 图片不来就这样取不 ...