Magician

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 543    Accepted Submission(s): 151

Problem Description
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an innate talent, gaining it through study and practice, or receiving it from another being, often a god, spirit, or demon of some sort. Some wizards are depicted as having a special gift which sets them apart from the vast majority of characters in fantasy worlds who are unable to learn magic.

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 ?

 
Input
The first line is an integer T represent the number of test cases.
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)
 
Output
For each 0 type query, output the corresponding answer.
 
Sample Input
1
1 1
1
0 1 1
 
Sample Output
1
 
Source
 
解题:线段树 水题,当时居然没想出来,愣是百分百傻逼啊
 
 
 #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的更多相关文章

  1. 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 ...

  2. 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:  ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. is == id 的用法;代码块;深浅copy;集合

    1 内容总览 is == id 用法 代码块 同一代码块下的缓存机制 (字符串驻留机制) 不同代码块下的缓存机制 (小数据池) 总结 集合(了解) 深浅copy 2 具体内容 id is == # i ...

  2. libvirtd.service

    [root@kvm-server ~]# systemctl status libvirtd.service ● libvirtd.service - Virtualization daemon Lo ...

  3. 页面下载文件方法,post与get

    一般下载文件,常见使用的是window.open('url'):方法进行下载.若需要带参数,直接在url后面拼接参数,进行传递.window.open方法仅可以进行get方法进行参数提交. 若需要进行 ...

  4. [luogu] P3089 [USACO13NOV]POGO的牛Pogo-Cow

    P3089 [USACO13NOV]POGO的牛Pogo-Cow 题目描述 In an ill-conceived attempt to enhance the mobility of his pri ...

  5. excel2013超链接进不去,提示“您的组织策略不允许...”

    搜索regedit 然后找到HKEY_CURRENT_USER->Software->Classes->.html 右键修改或者双击修改数值数据为Htmlfile 关闭之后此窗口,关 ...

  6. 监控SQLserver计数器

  7. 字符串的HashCode可能相同

    字符串的HashCode可能相同 学习了:http://blog.csdn.net/hl_java/article/details/71511815

  8. html 标签: image也能提交form!!!

    html 标签: image也能提交form! !! image也能提交form 先前常常使用"<input type="submit" value="i ...

  9. Python爬糗百热门20条并邮件分发+wxPython简易GUI+py2app转成可运行文件

    学了一阵子Python,拿来做个什么有意思的东西呢?爬糗百好了.爬到的内容,邮件分发出去. 然后又啃了两天的wxpython,做了个简易的邮件管理界面,能够在这里添加或者删除邮件,而且一键爬虫发送. ...

  10. ES 遇到 unassigned shard如何处理?

    解决方法:(1)如果是红色的,可以直接分片shard给你认为有最新(或最多)数据的节点.见下: 摘自:https://discuss.elastic.co/t/how-to-resolve-the-u ...