此题是一道线段树的裸题,这里只是为了保存我的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区间修改模板)的更多相关文章

  1. 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和

    poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...

  2. poj3468 A Simple Problem with Integers (线段树区间最大值)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92127   ...

  3. poj------(3468)A Simple Problem with Integers(区间更新)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 60745   ...

  4. POJ 3468 A Simple Problem with Integers(线段树模板之区间增减更新 区间求和查询)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 140120 ...

  5. poj3468 A Simple Problem with Integers (树状数组做法)

    题目传送门 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 1 ...

  6. POJ3468 A Simple Problem with Integers 【段树】+【成段更新】

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 57666   ...

  7. POJ3468:A Simple Problem with Integers(线段树模板)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 149972 ...

  8. A Simple Problem with Integers 循环节 修改 平方 找规律 线段树

    A Simple Problem with Integers 这个题目首先要打表找规律,这个对2018取模最后都会进入一个循环节,这个循环节的打表要用到龟兔赛跑. 龟兔赛跑算法 floyed判环算法 ...

  9. 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 ...

随机推荐

  1. Sql--order by、desc降序、top

    ---------通过order by 语句进行排序: --1.降序order by 列名desc --2.升序order by 列名   或order by 列名asc --3.order by语句 ...

  2. SQL SERVER Transactional Replication中添加新表如何不初始化整个快照

    在SQL SERVER的复制(Replication)中,有可能出现由于业务需求变更,需要新增一张表或一些表到已有的复制(发布订阅)当中,这种需求应该是很正常,也很常见的.但是在已有的复制(发布订阅) ...

  3. hive load数据为null

    建表语句: CREATE EXTERNAL TABLE IF NOT EXISTS student2 > (sno INT,sname STRING,age INT,sex STRING) &g ...

  4. shell变量详解

    1 shell变量基础 shell变量是一种很"弱"的变量,默认情况下,一个变量保存一个串,shell不关心这个串是什么含义.所以若要进行数学运算,必须使用一些命令例如let.de ...

  5. android布局居中

    添加android:gravity="center" 或者android:layout_gravity="center"属性.android:gravity用于 ...

  6. mysql innodb 性能优化

    建议参数: max_connections=800 key_buffer_size=512M query_cache_size=128M sort_buffer_size=64M table_open ...

  7. BI建模原则和常见问题

    BI建模的质量直接影响数据仓库项目的质量,所以在建模前,要对数据仓库的架构组成.大小以及模型功能有明确的定义. 影响BI数据仓库建模的因素众多,往往会随着项目的具体情况不同而变化.但有些原则是相通的, ...

  8. Java IO工作机制分析

    Java的IO类都在java.io包下,这些类大致可分为以下4种: 基于字节操作的 I/O 接口:InputStream 和 OutputStream 基于字符操作的 I/O 接口:Writer 和 ...

  9. 输入url到页面返回的过程

    输入url后,你看到了百度的首页,那么这一切是如何发生的呢? 这个问题之前.最近.我想以后肯定还会被问到,或者问到这样的题目,如果在百度框里输入查询的字符串开始,是怎么返回你需要的东西呢. 那这什么个 ...

  10. 一个页面从输入URL到页面加载显示完成,这个过程都发生了什么?

    对于网址栏的URL不同的操作方式有不同的加载资源.获取数据的方式,下面的详细过程针对"在地址栏输入URL,按enter(回车)键加载资源"此种操作方式做解析,其它的方式的过程大同小 ...