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.








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
  2. 1 1
  3. 1
  4. 0 1 1
 
Sample Output
  1. 1
  2.  
  3.  
  4. 一晚上的各种手残终于做出来了
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <cmath>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <list>
  14. #include <algorithm>
  15. typedef long long LL;
  16. using namespace std;
  17. const int MAX = 100010;
  18. const LL INF = (1LL<<32);
  19. struct node
  20. {
  21.     LL a[2][2];
  22. } Tree[MAX<<2];
  23. LL Arr[MAX];
  24. int n,m;
  25. node join(node a,node b)//区间合并
  26. {
  27.     node c;
  28.     for(int i=0; i<2; i++)
  29.     {
  30.         for(int j=0; j<2; j++)
  31.         {
  32.             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]));
  33.         }
  34.     }
  35.     return c;
  36. }
  37. void Build(int L,int R,int site)
  38. {
  39.     if(L==R)
  40.     {;
  41.         for(int i=0; i<2; i++)
  42.         {
  43.             for(int j=0; j<2; j++)
  44.             {
  45.                 Tree[site].a[i][j]=-INF;
  46.             }
  47.         }
  48.         if(L%2)
  49.         {
  50.             Tree[site].a[1][1]=Arr[L];
  51.         }
  52.         else
  53.         {
  54.             Tree[site].a[0][0]=Arr[L];
  55.         }
  56.         return ;
  57.     }
  58.     int mid=(L+R)>>1;
  59.     Build(L,mid,site<<1);
  60.     Build(mid+1,R,site<<1|1);
  61.     Tree[site]=join(Tree[site<<1],Tree[site<<1|1]);
  62. }
  63. void update(int L,int R,int site,int s,LL num)
  64. {
  65.     if(L==R)
  66.     {
  67.         for(int i=0; i<2; i++)
  68.         {
  69.             for(int j=0; j<2; j++)
  70.             {
  71.                 Tree[site].a[i][j]=-INF;
  72.             }
  73.         }
  74.         if(L%2)
  75.         {
  76.             Tree[site].a[1][1]=num;
  77.         }
  78.         else
  79.         {
  80.             Tree[site].a[0][0]=num;
  81.         }
  82.         return ;
  83.     }
  84.     int mid=(L+R)>>1;
  85.     if(s<=mid)
  86.     {
  87.         update(L,mid,site<<1,s,num);
  88.     }
  89.     else
  90.     {
  91.         update(mid+1,R,site<<1|1,s,num);
  92.     }
  93.     Tree[site]=join(Tree[site<<1],Tree[site<<1|1]);
  94. }
  95. node Look(int L,int R,int l,int r,int site)
  96. {
  97.     node res;
  98.     if(L==l&&r==R)
  99.     {
  100.         res=Tree[site];
  101.         return res;
  102.     }
  103.     int mid = (L+R)>>1;
  104.     if(r<=mid)
  105.     {
  106.         return Look(L,mid,l,r,site<<1);
  107.     }
  108.     else if(l>mid)
  109.     {
  110.         return Look(mid+1,R,l,r,site<<1|1);
  111.     }
  112.     else
  113.     {
  114.         res=join(Look(L,mid,l,mid,site<<1),Look(mid+1,R,mid+1,r,site<<1|1));
  115.         return res;
  116.     }
  117. }
  118. int main()
  119. {
  120.     int T;
  121.     scanf("%d",&T);
  122.     LL sum;
  123.     int u,v,flag;
  124.     LL s;
  125.     node ans;
  126.     while(T--)
  127.     {
  128.         scanf("%d %d",&n,&m);
  129.         for(int i=1; i<=n; i++)
  130.         {
  131.             scanf("%I64d",&Arr[i]);
  132.         }
  133.         Build(1,n,1);
  134.         while(m--)
  135.         {
  136.             scanf("%d",&flag);
  137.             if(flag)
  138.             {
  139.                 scanf("%d%I64d",&u,&s);
  140.                 update(1,n,1,u,s);
  141.             }
  142.             else
  143.             {
  144.                 scanf("%d%d",&u,&v);
  145.                 ans = Look(1,n,u,v,1);
  146.                 sum = -INF;
  147.                 for(int i=0; i<2; i++)
  148.                 {
  149.                     for(int j=0; j<2; j++)
  150.                     {
  151.                         sum=max(sum,ans.a[i][j]);
  152.                     }
  153.                 }
  154.                 printf("%I64d\n",sum);
  155.             }
  156.         }
  157.     }
  158.     return 0;
  159. }

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

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

  1. 欧拉通路-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 ...

  2. Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏

    #include <cstdio> #include <cstdlib> #include <climits> #include <cstring> # ...

  3. Brush Mode --- Nyoj 737 分类: Brush Mode 2014-03-25 08:10 202人阅读 评论(0) 收藏

    石子合并(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述     有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆.合并的过程只能每次将相邻的两堆 ...

  4. 跨服务器备注SQL数据库 分类: SQL Server 2015-03-05 08:52 227人阅读 评论(0) 收藏

    任务:把服务器1上的SQL数据库自动备份到服务器2上,命名格式=数据库名+年月日+小时. 说明: 服务器2=>192.168.0.22 数据库名=>Book 共享文件夹路径:192.168 ...

  5. 树莓派入手(烧写系统,调整分区,配置Java环境,串口GPS配置) 分类: Raspberry Pi 2015-04-09 21:13 145人阅读 评论(0) 收藏

    原来的tf卡无故启动不起来,检查发现其文件系统分区使用率为0%. 数据全部丢失!!!!! 血的教训告诉我们备份文件系统的重要性,一切需要重头来.... 烧录系统 安装系统有两种方式, NOOBS工具安 ...

  6. iOS搜索框UISearchBar 分类: ios技术 2015-04-03 08:55 82人阅读 评论(0) 收藏

    当你在seachBar中输入字母之前的时候,只是用鼠标选中searchBar的时候,如图 终端输出截图如下:(这个时候调用先shouldBeginEditing,之后调用didBeginEditing ...

  7. 网络请求工具--AFNetworking 分类: ios技术 2015-02-03 08:17 76人阅读 评论(0) 收藏

    在我们开发过程中,网络请求是必不可少的,对于网络框架,现在主流的大概只有三类:ASI框架: HTTP终结者(已经停止更新了),MKNetworkKit ,AFN.今天我就来浅谈一下这个AFN AFNe ...

  8. 解决ORA-29857:表空间中存在域索引和/或次级对象 & ORA-01940:无法删除当前连接的用户问题 分类: oracle sde 2015-07-30 20:13 8人阅读 评论(0) 收藏

    今天ArcGIS的SDE发生了一点小故障,导致系统表丢失,所以需要重建一下SDE数据库,在删除SDE用户和所在的表空间过程中遇到下面两个ORA错误,解决方法如下: 1)删除表空间时报错:ORA-298 ...

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

随机推荐

  1. PAT 解题报告 1052. Linked List Sorting (25)

    1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...

  2. Static Const

    Static 内部的 Const 不可变的 一般写法 在.m文件中, static NSString *const ID = @"shop"; static const CGFlo ...

  3. Codeforce Round #210 Div2

    A:对角线为k其他为0 B:利用两个相邻的数一定gcd为1和1与任何数gcd为1错k个位就行了 C:不会做操蛋,好像是因为上一层的始终小于下一层的 好吧C又研究了一下,是个贪心题,不符合的情况先科不考 ...

  4. 树形DP+贪心(乱搞)(HDU4714)

    题意:给出一个树形图,要求把该树形成一个环最少的步骤(断开一条边和形成一条边都需一步) 分析:很明显,要想把树形成一个环,就要先把其分裂成m条子链之后把子链形成环需要的步骤是2*m+1,所以只需要m最 ...

  5. java BigInteger

    用Java来处理高精度问题,相信对很多ACMer来说都是一件很happy的事,简单易懂.用Java刷了一些题,感觉Java还不错,在处理高精度和进制转换中,调用库函数的来处理.下面是写的一些Java中 ...

  6. 从一个例子讲解拷贝构造函数与return

    #include "iostream" using namespace std; class Location { public: Location(, ) { X = xx; Y ...

  7. HDU 4834 JZP Set(数论+递推)(2014年百度之星程序设计大赛 - 初赛(第二轮))

    Problem Description 一个{1, ..., n}的子集S被称为JZP集,当且仅当对于任意S中的两个数x,y,若(x+y)/2为整数,那么(x+y)/2也属于S.例如,n=3,S={1 ...

  8. 侧菜单栏的实现SlidingPaneLayout

    SlidingPaneLayout分为两部分,上面的 左划出部分和没划出的时候 <?xml version="1.0" encoding="utf-8"? ...

  9. 杭电 1595 find the safest road

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  10. Workflow Mailer Notifications设置

    参考:http://www.docin.com/p-651716490.html http://www.360doc.com/content/12/0218/15/3200886_187602886. ...