思路:线段树,区间更新,区间查找

 #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<set>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cstring>
#include<list> #define MAXSIZE 100010 using namespace std; long long tree[*MAXSIZE];
long long lz[*MAXSIZE];
int N, Q; void init()
{
memset(tree, , sizeof(tree));
memset(lz, , sizeof(lz));
} void build(int node, int l, int r)
{
if(l == r)
{
scanf("%lld", &tree[node]);
return;
} int mid = (l+r)/;
build(node*, l, mid);
build(node*+, mid+, r); tree[node] = tree[node*] + tree[node*+];
} void push_down(int node, int l, int r)
{
if(lz[node])
{
int mid = (l+r)/;
lz[node*] += lz[node];
lz[node*+] += lz[node];
tree[node*] += (mid-l+)*lz[node];
tree[node*+] += (r-mid)*lz[node];
lz[node] = ;
}
} void update_range(int node, int l, int r, int L, int R, int add)
{
if(l <= L && r >= R)
{
lz[node] += add;
tree[node] += (R-L+)*add;
return;
}
push_down(node, L, R);
int mid = (L+R)/;
if(mid >= l)
update_range(node*, l, r, L, mid, add);
if(mid < r)
update_range(node*+, l, r, mid+, R, add);
tree[node] = tree[node*] + tree[node*+];
} long long query_range(int node, int l, int r, int L, int R)
{
if(l <= L && r >= R)
{
return tree[node];
}
push_down(node, L, R);
int mid = (L+R)/;
long long sum = ;
if(mid >= l)
sum += query_range(node*, l, r, L, mid);
if(mid < r)
sum += query_range(node*+, l, r, mid+, R); return sum;
} int main()
{
scanf("%d%d", &N, &Q);
init();
build(, , N);
while(Q--)
{
char ch;
scanf(" %c", &ch);
if(ch == 'Q')
{
int a, b;
scanf("%d%d", &a, &b);
printf("%lld\n", query_range(, a, b, , N));
}
else if(ch == 'C')
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
update_range(, a, b, , N, c);
}
} return ;
}

A Simple Problem with Integers POJ - 3468 (线段树)的更多相关文章

  1. C - A Simple Problem with Integers POJ - 3468 线段树模版(区间查询区间修改)

    参考qsc大佬的视频 太强惹 先膜一下 视频在b站 直接搜线段树即可 #include<cstdio> using namespace std; ; int n,a[maxn]; stru ...

  2. A Simple Problem with Integers POJ - 3468 线段树区间修改+区间查询

    //add,懒标记,给以当前节点为根的子树中的每一个点加上add(不包含根节点) // #include <cstdio> #include <cstring> #includ ...

  3. A Simple Problem with Integers poj 3468 多树状数组解决区间修改问题。

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

  4. ACM: A Simple Problem with Integers 解题报告-线段树

    A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...

  5. POJ 3468 A Simple Problem with Integers(详细题解) 线段树

    这是个线段树题目,做之前必须要有些线段树基础才行不然你是很难理解的. 此题的难点就是在于你加的数要怎么加,加入你一直加到叶子节点的话,复杂度势必会很高的 具体思路 在增加时,如果要加的区间正好覆盖一个 ...

  6. A Simple Problem with Integers~POJ - 3468

    You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...

  7. A Simple Problem with Integers POJ - 3468 (分块)

    题目链接:https://cn.vjudge.net/problem/POJ-3468 题目大意:区间加减+区间查询操作. 具体思路:本来是一个线段树裸题,为了学习分块就按照分块的方法做吧. 分块真的 ...

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

    题意:有一个比较长的区间可能是100000.长度, 每个点都有一个值(值还比较大),现在有一些操作,C abc, 把区间a-b内全部加上c, Qab,求区间ab的值. 分析:很明显我们不可能对区间的每 ...

  9. POJ 3468 线段树 成段更新 懒惰标记

    A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Descr ...

随机推荐

  1. nginx压力测试webbench

    下载压力测试工具webbench wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz 安装依赖包 yum -y in ...

  2. order方法属于模型的连贯操作方法之一

    order方法属于模型的连贯操作方法之一,用于对操作的结果排序. 用法如下: $Model->where('status=1')->order('id desc')->limit(5 ...

  3. Python操作MySQL以及数据库索引

    目录 python操作MySQL 安装 使用 SQL注入问题 MySQL的索引 为什么使用索引 索引的种类 主键索引 唯一索引 普通索引 索引优缺点 不会命中索引的情况 explain 索引覆盖 My ...

  4. mybatis 一对多和一对一写法注意事项

    <resultMap id="ChartResultMap" type="com.qif.dsa.ucenter.planinfo.entity.ChartDate ...

  5. 牛客网在线判题系统JavaScript(V8)使用

    JavaScript作为一种弱类型的编程语言,语法和C/C++.JAVA等存在差别,但是对于大部算法题,不只是C/C++.JAVA,也依然可以使用JavaScript来实现.所以在牛客网中,如果你喜欢 ...

  6. vue-cli新手总结

    项目中需要用到vue-cli脚手架来搭建前端框架,对于vue小白,总结一下自己遇到的问题以及解决方案,还要学习的地方有很多. vue-cli安装下载网上有很多教程,但对于新手而言,有些地方需要自己摸索 ...

  7. 如何用maven读取本地架包

    一.这篇微博是建立在已经把架包复制过来的情况下的.其余情况另外谈. 二.本篇文章用的是cmd控制的 maven的安装请看以下链接:https://jingyan.baidu.com/article/3 ...

  8. C++ 函数模板&类模板详解

    在 C++ 中,模板分为函数模板和类模板两种.函数模板是用于生成函数的,类模板则是用于生成类的. 函数模板&模板函数     类模板&模板类  必须区分概念 函数模板是模板,模板函数时 ...

  9. Linux的基本原则

    Linux的基本原则:1.由目的单一的小程序组成,一个程序只做一件事,且做好: 2.’组合小程序完成复杂任务: 3.一切皆文件: 4.尽量避免捕获用户接口: 5.配置文件保存为纯文本格式: 6.提供机 ...

  10. 使用xshell远程连接到linux

      1.检查是否安装ssh rpm -qa | grep ssh 已安装是这样 如果没有安装,则 yum install openssh* #命令安装 2.开启ssh服务 [root@localhos ...