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 ...
随机推荐
- MS SQL 排序规则总结
排序规则术语 什么是排序规则呢? 排序规则是根据特定语言和区域设置标准指定对字符串数据进行排序和比较的规则.SQL Server 支持在单个数据库中存储具有不同排序规则的对象.MSDN解 ...
- Android:使用代理服务器安装SDKs
在使用Android SDK Manager来安装SDK时,因为google的ip被墙了,所以下载文件时,下载不到. 面对不能访问google的问题,通常有下列方案: 1)修改hosts文件,需要有正 ...
- 把Tomcat注册为windows服务
配置环境变量 JAVA_HOME=D:\java CLASSPATH=.;%JAVA_HOME%\lib; PATH=%JAVA_HOME%\bin; 提示:一般jre默认在jdk目录下%JAVA_H ...
- TFS 升级错误一则 TF400654
升级后报 [错误] TF400654: 无法配置规划工具.以下元素包含错误: BugWorkItems/BugWorkItems.TF400506: 此元素将定义表示 Bug 或缺陷的工作项的状态.每 ...
- ClearContainer 网络部分源码分析
// cc-oci-runtime/src/oci.c /*! * Create the state file, apply mounts and run hooks, but do not star ...
- SDN:motivation
今天公交车上看了会SDN一本介绍性的书籍,具体名字不记得了.我想,我已经在实验室呆了很久的时间的,接触SDN也有一段时间了.对SDN的一些基本的知识还是需要好好整理一番.当然,这里只是一个随笔,想到什 ...
- angular的跨域(angular百度下拉提示模拟)和angular选项卡
1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 实现缓存预热
因为大型应用系统可能有几十个子系统,为了减轻数据库频繁读写压力.提高系统的运行速度.反映速度,大型应用系统都需要采用缓存机制提高运行效率.Redis 缓存预热实现将来大家很多基础数据都可以缓存获取,不 ...
- Python-12-MySQL & sqlalchemy ORM
MySQL MySQL相关文章这里不在赘述,想了解的点击下面的链接: >> MySQL安装 >> 数据库介绍 && MySQL基本使用 >> MyS ...
- 使用getopt_long来解析参数的小函数模板
getopt_long原型 #define no_argument 0 #define required_argument 1 #define optional_argument 2 struct o ...