多校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
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 ?
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)
1
1 1
1
0 1 1
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
多校3-Magician 分类: 比赛 2015-07-31 08:13 4人阅读 评论(0) 收藏的更多相关文章
- 欧拉通路-Play on Words 分类: POJ 图论 2015-08-06 19:13 4人阅读 评论(0) 收藏
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10620 Accepted: 3602 Descri ...
- Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏
#include <cstdio> #include <cstdlib> #include <climits> #include <cstring> # ...
- Brush Mode --- Nyoj 737 分类: Brush Mode 2014-03-25 08:10 202人阅读 评论(0) 收藏
石子合并(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆.合并的过程只能每次将相邻的两堆 ...
- 跨服务器备注SQL数据库 分类: SQL Server 2015-03-05 08:52 227人阅读 评论(0) 收藏
任务:把服务器1上的SQL数据库自动备份到服务器2上,命名格式=数据库名+年月日+小时. 说明: 服务器2=>192.168.0.22 数据库名=>Book 共享文件夹路径:192.168 ...
- 树莓派入手(烧写系统,调整分区,配置Java环境,串口GPS配置) 分类: Raspberry Pi 2015-04-09 21:13 145人阅读 评论(0) 收藏
原来的tf卡无故启动不起来,检查发现其文件系统分区使用率为0%. 数据全部丢失!!!!! 血的教训告诉我们备份文件系统的重要性,一切需要重头来.... 烧录系统 安装系统有两种方式, NOOBS工具安 ...
- iOS搜索框UISearchBar 分类: ios技术 2015-04-03 08:55 82人阅读 评论(0) 收藏
当你在seachBar中输入字母之前的时候,只是用鼠标选中searchBar的时候,如图 终端输出截图如下:(这个时候调用先shouldBeginEditing,之后调用didBeginEditing ...
- 网络请求工具--AFNetworking 分类: ios技术 2015-02-03 08:17 76人阅读 评论(0) 收藏
在我们开发过程中,网络请求是必不可少的,对于网络框架,现在主流的大概只有三类:ASI框架: HTTP终结者(已经停止更新了),MKNetworkKit ,AFN.今天我就来浅谈一下这个AFN AFNe ...
- 解决ORA-29857:表空间中存在域索引和/或次级对象 & ORA-01940:无法删除当前连接的用户问题 分类: oracle sde 2015-07-30 20:13 8人阅读 评论(0) 收藏
今天ArcGIS的SDE发生了一点小故障,导致系统表丢失,所以需要重建一下SDE数据库,在删除SDE用户和所在的表空间过程中遇到下面两个ORA错误,解决方法如下: 1)删除表空间时报错:ORA-298 ...
- Hiking 分类: 比赛 HDU 函数 2015-08-09 21:24 3人阅读 评论(0) 收藏
Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...
随机推荐
- InterProScan 5.17-56.0 安装和使用
InterProScan 5.18-57.0 安装和使用,目前最新版的interproscan 引用自 每日一生信--interproscan安装及使用(终结版)原文官网:http://code.go ...
- SQL 基本的函数
select * from emp;
- 根据搜素的字符串改变label包含该字符串的文字
http://www.2cto.com/kf/201504/391811.html NSString *text =@"人生若只如初见"; //判断字符串所在的位置,并不区分大小写 ...
- [转]JAVA程序员一定知道的优秀第三方库(2016版)
原文地址:http://blog.csdn.net/zxc123e/article/details/51418163 几乎每个程序员都知道要“避免重复发明轮子”的道理——尽可能使用那些优秀的第三方框架 ...
- Java基础(9):Java生成随机数一定范围内的数的一个典型例子
题目:编写一个JAVA程序,创建指定长度的 int 型数组,并生成 100 以内随机数为数组中的每个元素赋值,然后输出数组 note: 通过 (int)(Math.random() * 100) 生成 ...
- bean在容器上的生命周期
初始化两种方法: 1,使用init-method属性指定那个方法在bean依赖关系设置好后自动执行. 2,实现initializingBean接口 实现 ...
- JavaScript中Date(日期对象),Math对象--学习笔记
Date对象 1.什么是Date对象? 日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 语法:var Udate=new Date(); 注:初始值为当前时间(当前电脑系统 ...
- paper 28 :一些常见常用数据库的下载网站集锦
做图像处理+模式识别的童鞋怎么可以没有数据库呢? 但是,如果自己做一个数据库,费时费力费钱先不说,关键是建立的数据库的公信力一般不会高,做出的算法也别人也不好比较,所以呢,下载比较权威的公共数据库还是 ...
- 16---Net基础加强
更新中,敬请期待............ Xml介绍 xml读写练习 xml练习1 xml练习2
- EBS R12版 GL追溯到各个模块
应收.应付.收款.付款等单据都可以生成ERP的日记帐,那么这些模块的关系是如何关联的呢,我们将会解决这个问题. 各个模块与总帐模块的关系,主要是通过子分类帐来进行关联的. 下面的SQL就是总帐与子分类 ...