• 转换成一个数在(0,X + Y)的加减问题
  • 考虑一种使用线段树处理的方法, 维护前缀最大值, 前缀最小值, 前缀和, 然后查询的时候先询问右区间是否会同时碰到上下界, 会的话左区间无用直接递归右区间, 否则的话递归左区间, 然后右区间只会碰到上边界或者下边界, 分两种情况讨论即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define M 500010
#define ls now << 1
#define rs now << 1 | 1
#define lson l, mid, now << 1
#define rson mid + 1, r, now << 1 | 1
#define ll long long
#define mmp make_pair
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int n, q, x, y, z;
ll sum[M << 2], minn[M << 2], maxx[M << 2]; void pushup(int now) {
sum[now] = sum[ls] + sum[rs];
minn[now] = min(minn[ls], sum[ls] + minn[rs]);
maxx[now] = max(maxx[ls], sum[ls] + maxx[rs]);
} void modify(int l, int r, int now, int pl, int v) {
if(l > pl || r < pl) return;
if(l == r) {
sum[now] = v;
minn[now] = min(v, 0);
maxx[now] = max(v, 0);
return;
}
int mid = (l + r) >> 1;
modify(lson, pl, v), modify(rson, pl, v);
pushup(now);
}
ll s; ll merge(ll v, int now) {
if(v + maxx[now] > s) return s - maxx[now] + sum[now];
if(v + minn[now] < 0) return sum[now] - minn[now];
return v + sum[now];
} ll query(int l, int r, int now, ll v) {
if(l == r) return max(min(s, sum[now] + v), 0ll);
int mid = (l + r) >> 1;
if(maxx[rs] - minn[rs] > s) return query(rson, 0);
else return merge(query(lson, v), rs);
} int main() {
// freopen("stone1.in", "r", stdin);
n = read(), q = read();
x = read(), y = read();
for(int i = 1; i <= n; i++) {
z = read();
if(i % 2 == 0) z = -z;
modify(1, n, 1, i, z);
}
while(q--) {
int op = read();
if(op == 1) x = read();
else if(op == 2) y = read();
else {
int pl = read(), v = read();
if(pl % 2 == 0) v = -v;
modify(1, n, 1, pl, v);
}
s = x + y;
cout << query(1, n, 1, x) << "\n";
}
return 0;
}

Problem B: 取石子的更多相关文章

  1. 【poj1067】 取石子游戏

    http://poj.org/problem?id=1067 (题目链接) 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走 ...

  2. HDU 2516 取石子游戏(斐波那契博弈)

    取石子游戏 Time Limit: 2000/1000 MS(Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  3. hdu 1527 取石子游戏(Wythoff Game)

    题意:Wythoff Game 思路:Wythoff Game #include<iostream> #include<stdio.h> #include<math.h& ...

  4. HDU 2516 取石子游戏(FIB博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. poj 1067 取石子游戏( 威佐夫博奕)

    题目:http://poj.org/problem?id=1067 题意:有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的 ...

  6. [原博客] POJ 1067 取石子游戏

    题目链接有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后把石子全部取完者 ...

  7. HDU-1527 取石子游戏

    http://acm.hdu.edu.cn/showproblem.php?pid=1527 交换  :可实现. if( n < m ) { n^=m; m^=n; n^=m; } (三)尼姆博 ...

  8. HDU 2516 取石子游戏 (博弈论)

    取石子游戏 Problem Description 1堆石子有n个,两人轮流取.先取者第1次能够取随意多个,但不能所有取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出" ...

  9. HDU - 4994 Revenge of Nim (取石子游戏)

    Problem Description Nim is a mathematical game of strategy in which two players take turns removing ...

随机推荐

  1. day059 ajax初识 登录认证练习

    ajax初识 ajax有两个特点: 一个是异步,另一个是浏览器页面局部刷新(这个特点是用户感受不到的时候进行的) 示例: 页面输入两个整数,通过AJAX传输到后端计算结果并返回 在HTML文件中: & ...

  2. ﺑﯘﻟﺒﯘﻟﻼﺭ--思恋--IPA--维吾尔语

    很美的维语歌曲, 迪里拜尔将之唱得十分动人心弦.

  3. nasm学习资料

    http://cee.github.io/NASM-Tutorial/   学习nasm的一个例子, 不错, 代码跟着敲, 出结果.理解起来不费事. http://www.mouseos.com/as ...

  4. Jsの练习-将 数组中值为0 的去掉,不为0的存入一个新的数组

    要求:将 数组中值为0 的去掉,不为0的存入一个新的数组 代码如下: <!DOCTYPE html> <html lang="en"> <head&g ...

  5. 野(wild)指针与悬空(dangling)指针

    1. 什么是野指针(wild pointer)? A pointer in c which has not been initialized is known as wild pointer. 野指针 ...

  6. .net ORM框架(Dapper简单应用)

    1.引入 Dapper.dll类库 2.创建书籍模型book using System; using System.Collections.Generic; using System.Linq; us ...

  7. 一个class标签里面有多个属性时的提取标签

    <div class="uibox-con carpic-list03 border-b-solid">   #即这个标签同时满足三个class:“uibox”.“ca ...

  8. 剑指Offer 36. 两个链表的第一个公共结点 (链表)

    题目描述 输入两个链表,找出它们的第一个公共结点. 题目地址 https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46?tp ...

  9. 通过GUID确保winform运行唯一实例

    通过程序生成的GUIDwinform唯一实例 using System.Threading;bool createdNew; Guid ownGUID = new Guid(((GuidAttribu ...

  10. _proto_ && prototype (原型 && 原型链)

    原型一直都是JavaScript基础里面的痛点,因为在JavaScript里面没有类的概念,都是通过原型对象来实现继承,下面的这个图很好的说明几者之间的关系! a.__proto__ = A.prot ...