2015 Multi-University Training Contest 3 hdu 5316 Magician
2015-07-28 20:41
323 查看
Magician
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 543 Accepted Submission(s): 151
[align=left]Problem Description[/align]
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.
#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL INF = 0x3f3f3f3f3f3f3f3f; const int maxn = 100010; struct node{ LL a,b,c,d; //分别代表奇奇、奇偶、偶偶、偶奇 }tree[maxn<<2]; 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&1){ 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)>>1; build(lt,mid,v<<1); build(mid+1,rt,v<<1|1); pushup(tree[v],tree[v<<1],tree[v<<1|1]); } void update(int L,int R,int lt,int rt,LL val,int v){ if(lt <= L && rt >= R){ if(lt&1){ 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)>>1; if(lt <= mid) update(L,mid,lt,rt,val,v<<1); if(rt > mid) update(mid+1,R,lt,rt,val,v<<1|1); pushup(tree[v],tree[v<<1],tree[v<<1|1]); } node query(int L,int R,int lt,int rt,int v){ if(lt == L && rt == R) return tree[v]; int mid = (L + R)>>1; if(rt <= mid) return query(L,mid,lt,rt,v<<1); else if(lt > mid) return query(mid+1,R,lt,rt,v<<1|1); else{ node x = query(L,mid,lt,mid,v<<1); node y = query(mid+1,R,mid+1,rt,v<<1|1); 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(1,n,1); while(m--){ scanf("%d%d",&op,&x); if(!op){ scanf("%d",&y); node ret = query(1,n,x,y,1); printf("%I64d\n",max(max(ret.a,ret.b),max(ret.c,ret.d))); }else{ scanf("%I64d",&val); update(1,n,x,x,val,1); } } } return 0; }
View Code
相关文章推荐
- HDU5319.Painter
- FirstChildElement() http://baike.baidu.com/link?url=VdlvQlGU-NGLshFepuft_u3MRdjZ9CAfGhOYuL915Oo-9pb
- hdu 5319 Painter
- 7.28多校1004——模拟——Painter
- HDU 5319 Painter(2015多校联合)
- 2015 Multi-University Training Contest 3
- atcoder它A Mountaineer
- HDU 5319 Painter
- hdu 5316 Magician(2015 Multi-University Training Contest 3)
- ZOJ 3802 Easy 2048 Again 像缩进DP
- HDU 5319 Painter (模拟)
- hdu5326_(优美的并查集解法)2015 Multi-University Training Contest 3(1011)
- XSSFDataValidationHelper.createDateConstraint有Bug
- Sinatra:一个可以作为Rails有益补充的框架. 简洁而不简单
- 15/7/27/正则表达式/进程线程/wait/notify
- 语言中如何在main函数开始前执行函数
- HDU 5319 Painter (模拟 脑洞题)
- 2015 Multi-University Training Contest 3
- Acboy needs your help again!
- Failed to install *.apk on device 'emulator-5554': timeout