http://poj.org/problem?id=3468

实现一个线段树,能够做到区间修改和区间查询和。

明显板子题。

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<iostream>
  6. using namespace std;
  7. typedef long long ll;
  8. inline ll read(){
  9. ll X=,w=; char ch=;
  10. while(ch<'' || ch>'') {w|=ch=='-';ch=getchar();}
  11. while(ch>='' && ch<='') X=(X<<)+(X<<)+(ch^),ch=getchar();
  12. return w?-X:X;
  13. }
  14. ll tree[],b[];
  15. ll lazy[];
  16. void build(int a,int l,int r){
  17. lazy[a]=;
  18. if(l==r){
  19. tree[a]=b[l];
  20. return;
  21. }
  22. int mid=(l+r)/;
  23. build(a*,l,mid);
  24. build(a*+,mid+,r);
  25. tree[a]=tree[a*]+tree[a*+];
  26. return;
  27. }
  28. inline void push(int a,int l,int mid,int r){
  29. lazy[a*+]+=lazy[a];
  30. lazy[a*]+=lazy[a];
  31. tree[a*+]+=lazy[a]*(r-mid);
  32. tree[a*]+=lazy[a]*(mid-l+);
  33. lazy[a]=;
  34. return;
  35. }
  36. ll wen(int a,int l,int r,int l1,int r1){
  37. if(l1<=l&&r1>=r){
  38. return tree[a];
  39. }
  40. if (l1>r||r1<l) return ;
  41. int mid=(l+r)/;
  42. push(a,l,mid,r);
  43. return wen(a*,l,mid,l1,r1)+wen(a*+,mid+,r,l1,r1);
  44. }
  45. void gai(int a,int l,int r,int l1,int r1,int add){
  46. if (l1>r||r1<l) return;
  47. if(l1<=l&&r1>=r){
  48. lazy[a]+=add;
  49. tree[a]+=add*(r-l+);
  50. return;
  51. }
  52. int mid=(l+r)/;
  53. push(a,l,mid,r);
  54. gai(a*,l,mid,l1,r1,add);
  55. gai(a*+,mid+,r,l1,r1,add);
  56. tree[a]=tree[a*]+tree[a*+];
  57. return;
  58. }
  59. int main(){
  60. int m=read();
  61. int ha=read();
  62. for(int i=;i<=m;i++){
  63. b[i]=read();
  64. }
  65. build(,,m);
  66. for(int i=;i<=ha;i++){
  67. char w;
  68. cin>>w;
  69. if(w=='C'){
  70. int a1=read();
  71. int a2=read();
  72. int a3=read();
  73. gai(,,m,a1,a2,a3);
  74. }else{
  75. int x=read();
  76. int y=read();
  77. printf("%lld\n",wen(,,m,x,y));
  78. }
  79. }
  80. return ;
  81. }

POJ3468:A Simple Problem with Integers——题解的更多相关文章

  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: 1 ...

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

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

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

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

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

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

  6. POJ3468 A Simple Problem with Integers —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/POJ-3468 You have N integers, A1, A2, ... , AN. You need to deal wit ...

  7. poj3468 A Simple Problem with Integers(线段树区间更新)

    https://vjudge.net/problem/POJ-3468 线段树区间更新(lazy数组)模板题 #include<iostream> #include<cstdio&g ...

  8. [POJ3468] A Simple Problem with Integers (Treap)

    题目链接:http://poj.org/problem?id=3468 这题是线段树的题,拿来学习treap. 不旋转的treap. #include <cstdio> #include ...

  9. POJ3468 A Simple Problem with Integers(线段树延时标记)

    题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...

随机推荐

  1. unity3d 角色头顶信息3D&2D遮挡解决方案(二)

    在阅读本文之前请先阅读上一篇文章:http://www.cnblogs.com/shenggege/p/4179012.html 本来一篇文章就可以说完了,但是上次只是实现了已知的一些功能 后来在实际 ...

  2. Java图片转字符

    很久都没有更新博客了,昨天下午一个朋友问我能不能将一张图片转换成字符画,然后我想我这个朋友不知道,也许有的朋友以不知道,我就简单的分享一下 package com.xsl.zhuanhuan; imp ...

  3. Appium1.8及以上命令行启动

    安装命令行启动版本的Appium,appium-doctor需要独立下载了,用 npm的话需要FQ才好使,所有安装了cnpm代替npm, cnpm是从淘宝的国内镜像下载 npm config rm p ...

  4. PyCharm 2018 最新激活方式总结(最新最全最有效)!!!

    PyCharm 2018 最新激活方式总结(最新最全最有效!!!) pycharm2018 是目前python编程的主要应用工具,具有非常广泛的应用,不过对于它的破解一直比较麻烦,这里我为大家提供了三 ...

  5. wordlist 4

    wordlist 4 desolate 啥啥啥lete adj. 荒凉的:无人烟的 repression depression n. 抑制,[心理] 压抑:镇压 / n. 沮丧:忧愁:抑郁症: spe ...

  6. 前端开发工程师 - 03.DOM编程艺术 - 期末考试

    期末考试客观题 返回    倒计时: 01:24 1 单选(2分) 以下选项中不是节点类型的是 A. COMMENT_NODE B. DOCUMENT_NODE C. BODY_NODE D. E ...

  7. TW实习日记:第23天

    主要的项目已经在修改一些细节以提高用户体验的阶段了,所以并不是太忙,主要就是对样式和一些细节修修改改.然后下午帮助同事的新项目做了一个功能点,主要就是调通接口就行,因为参数巨多,所以总要和网端那边的后 ...

  8. python 文件编译成exe可执行文件。

    pyinstaller打包方法: pyinstaller安装参考地址:http://www.pyinstaller.org/ pywin32的下载地址:https://sourceforge.net/ ...

  9. Vue-cli 工具 / 通过 Vue-cli 工具重构 todoList

    本博文归纳在 Vue 学习过程中, Vue-cli 工具的使用说明.除此之外还通过 Vue-cli 工具将之前 Vuejs 基本语法当中实现的 todoList 进行重构. 安装 npm instal ...

  10. 【转】jQuery的deferred对象详解

    jQuery的开发速度很快,几乎每半年一个大版本,每两个月一个小版本. 每个版本都会引入一些新功能.今天我想介绍的,就是从jQuery 1.5.0版本开始引入的一个新功能----deferred对象. ...