POJ3468:A Simple Problem with Integers——题解
http://poj.org/problem?id=3468
实现一个线段树,能够做到区间修改和区间查询和。
明显板子题。
- #include<cstdio>
- #include<cmath>
- #include<algorithm>
- #include<cstring>
- #include<iostream>
- using namespace std;
- typedef long long ll;
- inline ll read(){
- ll X=,w=; char ch=;
- while(ch<'' || ch>'') {w|=ch=='-';ch=getchar();}
- while(ch>='' && ch<='') X=(X<<)+(X<<)+(ch^),ch=getchar();
- return w?-X:X;
- }
- ll tree[],b[];
- ll lazy[];
- void build(int a,int l,int r){
- lazy[a]=;
- if(l==r){
- tree[a]=b[l];
- return;
- }
- int mid=(l+r)/;
- build(a*,l,mid);
- build(a*+,mid+,r);
- tree[a]=tree[a*]+tree[a*+];
- return;
- }
- inline void push(int a,int l,int mid,int r){
- lazy[a*+]+=lazy[a];
- lazy[a*]+=lazy[a];
- tree[a*+]+=lazy[a]*(r-mid);
- tree[a*]+=lazy[a]*(mid-l+);
- lazy[a]=;
- return;
- }
- ll wen(int a,int l,int r,int l1,int r1){
- if(l1<=l&&r1>=r){
- return tree[a];
- }
- if (l1>r||r1<l) return ;
- int mid=(l+r)/;
- push(a,l,mid,r);
- return wen(a*,l,mid,l1,r1)+wen(a*+,mid+,r,l1,r1);
- }
- void gai(int a,int l,int r,int l1,int r1,int add){
- if (l1>r||r1<l) return;
- if(l1<=l&&r1>=r){
- lazy[a]+=add;
- tree[a]+=add*(r-l+);
- return;
- }
- int mid=(l+r)/;
- push(a,l,mid,r);
- gai(a*,l,mid,l1,r1,add);
- gai(a*+,mid+,r,l1,r1,add);
- tree[a]=tree[a*]+tree[a*+];
- return;
- }
- int main(){
- int m=read();
- int ha=read();
- for(int i=;i<=m;i++){
- b[i]=read();
- }
- build(,,m);
- for(int i=;i<=ha;i++){
- char w;
- cin>>w;
- if(w=='C'){
- int a1=read();
- int a2=read();
- int a3=read();
- gai(,,m,a1,a2,a3);
- }else{
- int x=read();
- int y=read();
- printf("%lld\n",wen(,,m,x,y));
- }
- }
- return ;
- }
POJ3468:A Simple Problem with Integers——题解的更多相关文章
- 线段树---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: 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 ...
- 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 —— 线段树 区间修改
题目链接:https://vjudge.net/problem/POJ-3468 You have N integers, A1, A2, ... , AN. You need to deal wit ...
- poj3468 A Simple Problem with Integers(线段树区间更新)
https://vjudge.net/problem/POJ-3468 线段树区间更新(lazy数组)模板题 #include<iostream> #include<cstdio&g ...
- [POJ3468] A Simple Problem with Integers (Treap)
题目链接:http://poj.org/problem?id=3468 这题是线段树的题,拿来学习treap. 不旋转的treap. #include <cstdio> #include ...
- POJ3468 A Simple Problem with Integers(线段树延时标记)
题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...
随机推荐
- unity3d 角色头顶信息3D&2D遮挡解决方案(二)
在阅读本文之前请先阅读上一篇文章:http://www.cnblogs.com/shenggege/p/4179012.html 本来一篇文章就可以说完了,但是上次只是实现了已知的一些功能 后来在实际 ...
- Java图片转字符
很久都没有更新博客了,昨天下午一个朋友问我能不能将一张图片转换成字符画,然后我想我这个朋友不知道,也许有的朋友以不知道,我就简单的分享一下 package com.xsl.zhuanhuan; imp ...
- Appium1.8及以上命令行启动
安装命令行启动版本的Appium,appium-doctor需要独立下载了,用 npm的话需要FQ才好使,所有安装了cnpm代替npm, cnpm是从淘宝的国内镜像下载 npm config rm p ...
- PyCharm 2018 最新激活方式总结(最新最全最有效)!!!
PyCharm 2018 最新激活方式总结(最新最全最有效!!!) pycharm2018 是目前python编程的主要应用工具,具有非常广泛的应用,不过对于它的破解一直比较麻烦,这里我为大家提供了三 ...
- wordlist 4
wordlist 4 desolate 啥啥啥lete adj. 荒凉的:无人烟的 repression depression n. 抑制,[心理] 压抑:镇压 / n. 沮丧:忧愁:抑郁症: spe ...
- 前端开发工程师 - 03.DOM编程艺术 - 期末考试
期末考试客观题 返回 倒计时: 01:24 1 单选(2分) 以下选项中不是节点类型的是 A. COMMENT_NODE B. DOCUMENT_NODE C. BODY_NODE D. E ...
- TW实习日记:第23天
主要的项目已经在修改一些细节以提高用户体验的阶段了,所以并不是太忙,主要就是对样式和一些细节修修改改.然后下午帮助同事的新项目做了一个功能点,主要就是调通接口就行,因为参数巨多,所以总要和网端那边的后 ...
- python 文件编译成exe可执行文件。
pyinstaller打包方法: pyinstaller安装参考地址:http://www.pyinstaller.org/ pywin32的下载地址:https://sourceforge.net/ ...
- Vue-cli 工具 / 通过 Vue-cli 工具重构 todoList
本博文归纳在 Vue 学习过程中, Vue-cli 工具的使用说明.除此之外还通过 Vue-cli 工具将之前 Vuejs 基本语法当中实现的 todoList 进行重构. 安装 npm instal ...
- 【转】jQuery的deferred对象详解
jQuery的开发速度很快,几乎每半年一个大版本,每两个月一个小版本. 每个版本都会引入一些新功能.今天我想介绍的,就是从jQuery 1.5.0版本开始引入的一个新功能----deferred对象. ...