博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Magician
阅读量:4477 次
发布时间:2019-06-08

本文共 4867 字,大约阅读时间需要 16 分钟。

12231: Magician

时间限制: 9 Sec  内存限制: 128 MB
提交: 5  解决: 2
[] [] [命题人:外部导入]

题目描述

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 ?

 

输入

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)

 

输出

For each 0 type query, output the corresponding answer.

 

样例输入

复制样例数据

11 110 1 1

样例输出

1
#include
using namespace std;const int maxn = 300060;typedef long long ll;struct segment_tree { int l, r; ll ee, oo, eo, oe; inline void init() { ee = oo = eo = oe = -INT_MAX / 2; }} o[maxn];int T, n, m;ll c[maxn];inline void pushup(segment_tree &rt, segment_tree &ltree, segment_tree &rtree) { ll oo = max(ltree.oo, rtree.oo); oo = max(oo, max(ltree.oe + rtree.oo, ltree.oo + rtree.eo)); rt.oo = oo; ll oe = max(ltree.oe, rtree.oe); oe = max(oe, max(ltree.oo + rtree.ee, ltree.oe + rtree.oe)); rt.oe = oe; ll eo = max(ltree.eo, rtree.eo); eo = max(eo, max(ltree.eo + rtree.eo, ltree.ee + rtree.oo)); rt.eo = eo; ll ee = max(ltree.ee, rtree.ee); ee = max(ee, max(ltree.ee + rtree.oe, ltree.eo + rtree.ee)); rt.ee = ee;}inline void build(int l, int r, int rt) { o[rt].l = l; o[rt].r = r; o[rt].ee = o[rt].oo = o[rt].eo = o[rt].oe = -INT_MAX / 2; if (l == r) { if (l % 2) { o[rt].oo = c[l]; } else { o[rt].ee = c[l]; } return; } int mid = l + r >> 1; build(l, mid, rt << 1); build(mid + 1, r, rt << 1 | 1); pushup(o[rt], o[rt << 1], o[rt << 1 | 1]);}inline segment_tree query(int rt, int ql, int qr) { int l = o[rt].l; int r = o[rt].r; if (ql <= l && qr >= r) { return o[rt]; } int mid = l + r >> 1; segment_tree p, q, w; p.init(); q.init(); w.init(); if (ql <= mid) { p = query(rt << 1, ql, qr); } if (qr > mid) { q = query(rt << 1 | 1, ql, qr); } pushup(w, p, q); return w;}inline void update(int rt, int pos, ll val) { int l = o[rt].l; int r = o[rt].r; if (l == r) { if (pos % 2) { o[rt].oo = val; } else { o[rt].ee = val; } return; } int mid = l + r >> 1; if (pos <= mid) { update(rt << 1, pos, val); } else { update(rt << 1 | 1, pos, val); } pushup(o[rt], o[rt << 1], o[rt << 1 | 1]);}int main() {#ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin);#endif scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); for (register int i = 1; i <= n; ++i) { scanf("%lld", &c[i]); } build(1, n, 1); int op, a; ll b; while (m--) { scanf("%d%d%lld", &op, &a, &b); if (op == 0) { segment_tree res = query(1, a, b); printf("%lld\n", max(res.ee, max(res.oo, max(res.eo, res.oe)))); } else { update(1, a, b); } } } return 0;}

 

 

转载于:https://www.cnblogs.com/czy-power/p/11489561.html

你可能感兴趣的文章
批量梯度下降法(Batch Gradient Descent)
查看>>
说说无线路由器后门的那些事儿(1)-D-Link篇
查看>>
AJAX POST&跨域 解决方案 - CORS
查看>>
C#基础之接口
查看>>
三相交流电路中三相负载的计算方法
查看>>
Webform(Linq高级查、分页、组合查询)
查看>>
nio 序列化
查看>>
android:强大的图像下载和缓存库Picasso
查看>>
Tick and Tick------HDOJ杭州电(无法解释,直接看代码)
查看>>
開始Unity3D的学习之旅
查看>>
WEB安全实战(一)SQL盲注
查看>>
华为HG8347R V3R016C10S135光猫桥接 北京联通 恢复华为原版
查看>>
Java文件下载:如何编码文件名称以及如何设置HttpServletResponse
查看>>
python 之@staticmethod和@classmethod
查看>>
QQ通信机制(转)
查看>>
泛型高级通配符
查看>>
[复习]Python回顾 OS模块,函数传参,模块导入
查看>>
什么是反射?以及应用场景?
查看>>
Hadoop集群时钟同步
查看>>
IT从业者真的成了民工,悲哀呀
查看>>