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. php5 中魔术方法函数有哪几个

    魔术函数:9.3 构造函数:__construct() 9.3.1 实例化对象时被调用. 9.3.2 在类中,构造函数是用来初始化对象的,利用构造函数,可以操作对象,并改变它的值. 9.3.3 当__ ...

  2. Laravel源码解析之反射的使用

    前言 PHP的反射类与实例化对象作用相反,实例化是调用封装类中的方法.成员,而反射类则是拆封类中的所有方法.成员变量,并包括私有方法等.就如"解刨"一样,我们可以调用任何关键字修饰 ...

  3. STM32 软件复位并模拟USB拔插

    最近做了个USB跟上位机的通信,需要软件对MCU进行复位,复位后如果USB没有拔插,PC就不会重新枚举USB为了解决这个问题,我做了软件复位跟,软件模拟USB拔插. 这里我用的是HAL库的软件复位,复 ...

  4. Android自己定义TabActivity(实现仿新浪微博底部菜单更新UI)

    现在Android上非常多应用都採用底部菜单控制更新的UI这样的框架,比如新浪微博 点击底部菜单的选项能够更新界面.底部菜单能够使用TabHost来实现,只是用过TabHost的人都知道自己定义Tab ...

  5. scp报错:Host key verification failed. REMOTE HOST IDENTIFICATION HAS CHANGED!

    1 scp报错:REMOTE HOST IDENTIFICATION HAS CHANGED! [root@xx ~]# scp yum-3.4.3.tar.gz 10.xx.xx.12:/root ...

  6. 输入password登录到主界面,录入学生编号,排序后输出

    n 题目:输入password登录到主界面,录入学生编号,排序后输出 n 1.  语言和环境 A.实现语言 C语言 B.环境要求 VC++ 6.0 n 2.  要求 请编写一个C语言程序.将若干学生编 ...

  7. 一个build.xml实例

    <?xml version="1.0"?> <project name="ssh" basedir="." default ...

  8. OpenMp之reduction求和

    // OpenMP1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include"omp.h" #include& ...

  9. 对Java、C#转学swift的提醒:学习swift首先要突破心理障碍。

    网上非常多都说swift是一门新手友好的语言. 但以我当年从Java转学Ruby的经验,swift对于从Java.C#转来的程序猿实际并不友好.原因就在于原来总有一种错觉:一个语言最重要的就是严谨,而 ...

  10. poj--3250--Bad Hair Day(模拟)

    Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit ...