poj3468 A Simple Problem with Integers(zkw区间修改模板)
此题是一道线段树的裸题,这里只是为了保存我的zkw线段树模板
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL;
inline int geti() {
static int Ina; static char Inc; static bool InSign;
InSign = false;
while ((Inc = getchar()) < '0' || Inc >'9') InSign |= Inc == '-';
Ina = Inc - '0';
while ((Inc = getchar()) >= '0' && Inc <= '9') Ina = (Ina << 3) + (Ina << 1) + Inc - '0';
return InSign ? -Ina : Ina;
}
inline void Outi(LL x) {
if (x < 0) putchar('-'), x = -x;
static char buf[20]; static int Len;
Len = 0; while (x) buf[++Len] = x % 10 + '0', x /= 10;
while (Len) putchar(buf[Len--]);
}
const int N = 200005;
int pre, dl[N << 1], dr[N << 1];
LL C[N << 1], ly[N << 1];
#define ls u<<1
#define rs u<<1|1
void Down(const int &u) {
if (ly[u] && u < pre) {
C[ls] += (dr[ls] - dl[ls] + 1) * ly[u];
C[rs] += (dr[rs] - dl[rs] + 1) * ly[u];
ly[ls] += ly[u]; ly[rs] += ly[u];
ly[u] = 0;
}
}
int Stack[30], top;
void Up(int u) {
for (top = 0; u; u >>= 1) Stack[++top] = u;
while (top) Down(Stack[top--]);
}
LL Query(int s, int t) {
LL ret = 0; int lef(0), rig(0);
for (s += pre - 1, t += pre + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
if (~s & 1) (lef ? 1 : (Up(lef = s ^ 1),1)), ret += C[s ^ 1];
if ( t & 1) (rig ? 1 : (Up(rig = t ^ 1),1)), ret += C[t ^ 1];
}
return ret;
}
void Update(int s, int t, const int &val) {
int lef(0), rig(0);
for (s += pre - 1, t += pre + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
if (~s & 1) (lef ? 1 : (Up(lef = s ^ 1),1)), ly[s ^ 1] += val, C[s ^ 1] += (dr[s ^ 1] - dl[s ^ 1] + 1) * (LL)val;
if ( t & 1) (rig ? 1 : (Up(rig = t ^ 1),1)), ly[t ^ 1] += val, C[t ^ 1] += (dr[t ^ 1] - dl[t ^ 1] + 1) * (LL)val;
}
for (lef >>= 1; lef; lef >>= 1) C[lef] = C[lef << 1 | 1] + C[lef << 1];
for (rig >>= 1; rig; rig >>= 1) C[rig] = C[rig << 1 | 1] + C[rig << 1];
}
int main() {
int n = geti(), m = geti();
for (pre = 1; pre <= n + 1; pre <<= 1);
for (int i = 1; i <= n; ++i) C[i + pre] = geti(), dl[i + pre] = dr[i + pre] = i;
for (int i = pre; i; --i) C[i] = C[i << 1] + C[i << 1 | 1], dl[i] = dl[i << 1], dr[i] = dr[i << 1 | 1];
char op; int x, y, z;
while (m--) {
while ((op = getchar()) < 'C' && op > 'Q');
if (op ^ 'C') {
x = geti(), y = geti();
if (x > y) x ^= y ^= x ^= y;
cout << Query(x, y) << endl;
} else {
x = geti(), y = geti(), z = geti();
if (x > y) x ^= y ^= x ^= y;
Update(x, y, z);
}
}
return 0;
}
poj3468 A Simple Problem with Integers(zkw区间修改模板)的更多相关文章
- 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和
poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...
- poj3468 A Simple Problem with Integers (线段树区间最大值)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92127 ...
- poj------(3468)A Simple Problem with Integers(区间更新)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 60745 ...
- POJ 3468 A Simple Problem with Integers(线段树模板之区间增减更新 区间求和查询)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 140120 ...
- poj3468 A Simple Problem with Integers (树状数组做法)
题目传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 1 ...
- POJ3468 A Simple Problem with Integers 【段树】+【成段更新】
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 57666 ...
- POJ3468:A Simple Problem with Integers(线段树模板)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 149972 ...
- A Simple Problem with Integers 循环节 修改 平方 找规律 线段树
A Simple Problem with Integers 这个题目首先要打表找规律,这个对2018取模最后都会进入一个循环节,这个循环节的打表要用到龟兔赛跑. 龟兔赛跑算法 floyed判环算法 ...
- POJ3468 A Simple Problem with Integers(数状数组||区间修改的RMQ问题)
You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...
随机推荐
- mysql编码格式设置
两个地方能影响到mysql的编码格式 ①.[mysql]下default-character-set=GBK//指的是客户端输入的内容的编码(GBK只是支持中英文)②.[mysqld]下# The d ...
- Nova reboot 和 lock 操作 - 每天5分钟玩转 OpenStack(32)
前面 CloudMan 通过日志详细分析了 nova 的 launch, shut off 和 start 操作.不知道大家现在是否已经掌握了日志分析的技能? 今天咱们就来检验一下.本节讨论的是 no ...
- ubuntu下怎么给普通用户赋予sudo权限
ununtu系统安装过程中,系统会提示建立一个默认用户,比如用户名为:zhuhui.这个默认用户具有一定的管理功能,即可以通过sudo命令执行root权限的操作.由于Ubuntu系统默认不允许通过ro ...
- Nginx服务安装配置
1.Nginx介绍 Nginx是一个高性能的HTTP和反向代理服务器,由俄罗斯人开发的,第一个版本发布于2004年10月4日.Nginx由于出色的性能,在世界范围内受到了越来越多人的关注,其特点是占有 ...
- hdfs client access the hdfs cluster not in one domain
https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/HdfsMultihoming.html#Clients_u ...
- [django]利用xlwt实现文件下载功能
代码: url.py: url(r'^importmould/$', 'keywork.views.xls_mould', name='xls_mould'), view.py: from djang ...
- NYOJ 461
Fibonacci数列(四) 描述 数学神童小明终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部 ...
- iOS第八课——Navigation Controller和Tab bar Controller
今天我们要学习Navigation Controller和Tab bar Controller. Navigation Controller是iOS编程中比较常用的一种容器,用来管理多个视图控制器. ...
- python3循环语句while
Python的循环语句有for和while语句,这里讲while语句. Python中while语句的一般形式: while 条件判断 : 语句 需要注意冒号和缩进.另外,注意Python中没有do. ...
- LCM 轻量级通信组件
LCM和ZMQ比较 http://www.doc88.com/p-6711552253536.html 基于LCM和ZeroMQ的进程间通信研究 2.简介 LCM(Lightweight Commuc ...