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. phpMyAdmin 高级功能尚未完全设置,部分功能未激活(转载)

    phpMyAdmin 高级功能尚未完全设置,部分功能未激活.请点击这里查看原因. 第一步: 使用Mysql管理员帐号通过phpmyadmin登陆,然后点击“导入”,然后点击“浏览”按钮,找到phpmy ...

  2. Vue经典开源项目

    Vue常用的开源项目和插件库 UI组件 element ★34,784 - 饿了么出品的基于Vue2的web UI工具套件storybook ★33,503 - 响应式UI 开发及测试环境Vux ★1 ...

  3. idea 编辑器 光标问题!(insert键)

    今天写代码不小心按了键盘的insert键,光标莫名闪退了 ,重新打开的时候发现 光标变成了  按了insert 的效果  ,简直无语的要命啊! 这敲代码太恶心了!怒搜资料 结果找到了解决办法! 1.打 ...

  4. 监控iis计数器

  5. 笔试中java的输入输出

    一,输入 import java.util.*; import java.io.*; public class Main { public static void main(String[] args ...

  6. hdu 1722 Cake 数学yy

    题链:http://acm.hdu.edu.cn/showproblem.php? pid=1722 Cake Time Limit: 1000/1000 MS (Java/Others)    Me ...

  7. USACO runaround

    /* ID:kevin_s1 PROG:runround LANG:C++ */ #include <iostream> #include <cstdio> #include ...

  8. bzoj3262: 陌上花开(cdq分治+树状数组)

    3262: 陌上花开 题目:传送门 题解: %%%cdq分治 很强大的一个暴力...感觉比分块高级多了 这道题目就是一个十分经典的三维偏序的例题: 一维直接暴力排序x 二维用csq维护y 三维用树状数 ...

  9. (四)Hystrix容错保护

    Feign默认是整合了Ribbon和Hystrix这两个框架,所以代码我们在上一篇的基础上进行修改,启动Eureka,service-hello,Feign 所谓的熔断机制和日常生活中见到电路保险丝是 ...

  10. 整数转罗马数字 C++实现 java实现 leetcode系列(十二)

    罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并 ...