多校3-Magician 分类: 比赛 2015-07-31 08:13 4人阅读 评论(0) 收藏

Magician

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1771    Accepted Submission(s): 515

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.



多校3-Magician                                                       分类:            比赛             2015-07-31 08:13    4人阅读    评论(0)    收藏




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
一晚上的各种手残终于做出来了

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <algorithm>
typedef long long LL; using namespace std; const int MAX = 100010; const LL INF = (1LL<<32); struct node
{
LL a[2][2];
} Tree[MAX<<2]; LL Arr[MAX]; int n,m; node join(node a,node b)//区间合并
{
node c;
for(int i=0; i<2; i++)
{
for(int j=0; j<2; j++)
{
c.a[i][j]=max(max(a.a[i][j],b.a[i][j]),max(a.a[i][0]+b.a[1][j],a.a[i][1]+b.a[0][j]));
}
}
return c;
} void Build(int L,int R,int site)
{
if(L==R)
{;
for(int i=0; i<2; i++)
{
for(int j=0; j<2; j++)
{
Tree[site].a[i][j]=-INF;
}
}
if(L%2)
{
Tree[site].a[1][1]=Arr[L];
}
else
{
Tree[site].a[0][0]=Arr[L];
}
return ;
}
int mid=(L+R)>>1;
Build(L,mid,site<<1);
Build(mid+1,R,site<<1|1);
Tree[site]=join(Tree[site<<1],Tree[site<<1|1]);
} void update(int L,int R,int site,int s,LL num)
{
if(L==R)
{
for(int i=0; i<2; i++)
{
for(int j=0; j<2; j++)
{
Tree[site].a[i][j]=-INF;
}
}
if(L%2)
{
Tree[site].a[1][1]=num;
}
else
{
Tree[site].a[0][0]=num;
}
return ;
}
int mid=(L+R)>>1;
if(s<=mid)
{
update(L,mid,site<<1,s,num);
}
else
{
update(mid+1,R,site<<1|1,s,num);
}
Tree[site]=join(Tree[site<<1],Tree[site<<1|1]);
} node Look(int L,int R,int l,int r,int site)
{
node res;
if(L==l&&r==R)
{
res=Tree[site];
return res;
}
int mid = (L+R)>>1;
if(r<=mid)
{
return Look(L,mid,l,r,site<<1);
}
else if(l>mid)
{
return Look(mid+1,R,l,r,site<<1|1);
}
else
{ res=join(Look(L,mid,l,mid,site<<1),Look(mid+1,R,mid+1,r,site<<1|1));
return res;
}
} int main()
{
int T;
scanf("%d",&T);
LL sum;
int u,v,flag;
LL s;
node ans;
while(T--)
{
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++)
{
scanf("%I64d",&Arr[i]);
}
Build(1,n,1);
while(m--)
{
scanf("%d",&flag);
if(flag)
{
scanf("%d%I64d",&u,&s);
update(1,n,1,u,s);
}
else
{
scanf("%d%d",&u,&v);
ans = Look(1,n,u,v,1);
sum = -INF;
for(int i=0; i<2; i++)
{
for(int j=0; j<2; j++)
{
sum=max(sum,ans.a[i][j]);
}
}
printf("%I64d\n",sum);
}
}
}
return 0;
}

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

上一篇:ECMAScript版本号总结


下一篇:ubuntu系统安装mysql登陆提示 解决Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'问题