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 ...
随机推荐
- ref
ref: 当控制权传递回调用方法时,在方法中对参数的任何更改都将反映在该变量中. 例如: class RefExample { //使用ref返回的函数 static void Method(ref ...
- SQL Server 2008 R2——使用数字辅助表(master..spt_values)实现用计数字段对记录进行重复显示
=================================版权声明================================= 版权声明:原创文章 谢绝转载 请通过右侧公告中的“联系邮 ...
- [python]爬虫学习(一)
要学习Python爬虫,我们要学习的共有以下几点(python2): Python基础知识 Python中urllib和urllib2库的用法 Python正则表达式 Python爬虫框架Scrapy ...
- RSA加密算法的简单案例
RSA加密算法是目前最有影响力的公钥加密算法,它能够抵抗到目前为止已知的绝大多数密码攻击. 那关于RSA加密算法有哪些应用呢?以下举一个数据库身份验证的案例. 在使用数据集进行身份认证时,密码存在数据 ...
- 【2016-11-6】【坚持学习】【Day21】【主窗口关闭时,同步关闭它的子窗口】
本来想用委托实现的.但是又觉得没有必要. 方法如下: public MainWindow() { InitializeComponent(); this.Closing += MainWindow_C ...
- TCP/IP四层模型和OSI七层模型
TCP/IP四层模型 TCP/IP是一组协议的代名词,它还包括许多协议,组成了TCP/IP协议簇.TCP/IP协议簇分为四层,IP位于协议簇的第二层(对应OSI的第三层),TCP位于协议簇的第三层(对 ...
- [No000082]Convert和Parse的区别/Convert.ToInt32()与int.Parse()的区别
(1)这两个方法的最大不同是它们对null值的处理方法: Convert.ToInt32(null)会返回0而不会产生任何异常,但int.Parse(null)则会产生异常. 没搞清楚Convert. ...
- Python list
序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但最常见的是列表和元组. 序列 ...
- 配置文件类 Properties
Properties(配置文件类): 主要用于生产配置文件与读取配置文件的信息. Properties属于集合类,继承于Hashtable. Properties要注意的细节: 1. 如果配置文 ...
- IO(七)----转换流
输入字节流的转换流:InputStreamReader 是字节流通向字符流的桥梁. 输出字节流的转换流:OutputStreamWriter 可以把输出字节流转换成输出字符流 . 是符流通向字节流 ...