UESTCOJ不知道为什么进不去了哇

跟着叉姐的算法讲堂写的板子

叉姐的思路真的好清晰啊,一定是练习的多并且理解的够深了

希望自己也可以每天进步一点点吧

代码:

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e5+;
int n,a[maxn],q;
struct node{
int l,r;
long long sum,lazy;
void update(long long x){
sum+=1ll*(r-l+)*x;
lazy+=x;
}
}tree[maxn*];
void push_up(int x){
tree[x].sum=tree[x<<].sum+tree[x<<|].sum;
}
void push_down(int x){
int lazyval=tree[x].lazy;
if(lazyval){
tree[x<<].update(lazyval);
tree[x<<|].update(lazyval);
tree[x].lazy=;
}
}
void build(int x,int l,int r){
tree[x].l=l,tree[x].r=r;
tree[x].sum=tree[x].lazy=;
if(l==r){
tree[x].sum=a[l];
}else{
int mid=(l+r)/;
build(x<<,l,mid);
build(x<<|,mid+,r);
push_up(x);
}
}
void update(int x,int l,int r,long long val){
int L=tree[x].l,R=tree[x].r;
if(l<=L&&R<=r){
tree[x].update(val);
}else{
push_down(x);
int mid=(L+R)/;
if(mid>=l) update(x<<,l,r,val);
if(r>mid) update(x<<|,l,r,val);
push_up(x);
}
}
long long query(int x,int l,int r){
int L=tree[x].l,R=tree[x].r;
if(l<=L&&R<=r){
return tree[x].sum;
}else{
push_down(x);
long long ans=;
int mid=(L+R)/;
if(mid>=l) ans+=query(x<<,l,r);
if(r>mid) ans+=query(x<<|,l,r);
push_up(x);
return ans;
}
} int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
scanf("%d",&q);
for(int i=;i<=q;i++){
int l,r,val;
scanf("%d%d%d",&l,&r,&val);
update(,l,r,val);
printf("%lld\n",query(,l,r));
}
}

线段树模板 CDOJ1057的更多相关文章

  1. [AHOI 2009] 维护序列(线段树模板题)

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...

  2. hdu1754 I hate it线段树模板 区间最值查询

    题目链接:这道题是线段树,树状数组最基础的问题 两种分类方式:按照更新对象和查询对象 单点更新,区间查询; 区间更新,单点查询; 按照整体维护的对象: 维护前缀和; 维护区间最值. 线段树模板代码 # ...

  3. P3373 线段树模板

    好,这是一个线段树模板. #include <cstdio> using namespace std; ; long long int sum[N],tag1[N],tag2[N],mo; ...

  4. 线段树模板hdu 1754:I Hate It

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. UESTC - 1057 秋实大哥与花 线段树模板题

    http://acm.uestc.edu.cn/#/problem/show/1057 题意:给你n个数,q次操作,每次在l,r上加上x并输出此区间的sum 题解:线段树模板, #define _CR ...

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

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

  7. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

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

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

  9. HDU1166:敌兵布阵(线段树模板)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

随机推荐

  1. redhat6.5安装oracle 11g

    1.修改操作系统核心参数 在Root用户下执行以下步骤: 1)修改用户的SHELL的限制,修改/etc/security/limits.conf文件 输入命令:vi /etc/security/lim ...

  2. uva 509 RAID!(磁盘数据)

    来自 https://blog.csdn.net/su_cicada/article/details/80085318 习题4-7 RAID技术(RAID!, ACM/ICPC World Final ...

  3. (数据科学学习手札02)Python与R在循环语句与条件语句上的异同

    循环是任何一种编程语言的基本设置,是进行批量操作的基础,而条件语句是进行分支运算的基础,Python与R有着各自不同的循环语句与条件语句语法,也存在着一些相同的地方. Python 1.for循环 ' ...

  4. COURSES POJ1469(模板)

    Description Consider a group of N students and P courses. Each student visits zero, one or more than ...

  5. 批处理bat实现创建、复制、删除文件及文件夹

    转自:http://blog.csdn.net/linda1000/article/details/10221285 1 建bat文件自动执行复制,删除命令. 例1:以下是复制cd.dll文件至win ...

  6. 1176: [Balkan2007]Mokia

    1176: [Balkan2007]Mokia 链接 分析 三维偏序问题,CDQ分治论文题. 代码 #include<bits/stdc++.h> using namespace std; ...

  7. SXOI2018游记

    day0 动身去太原.太原五中虽然挺小的但是很好看啊qwq(进门口一个"通天堂"(逃 试机.似乎看到了__stdcall!!然而没敢去认orz.linux选手似乎是9个.准考证(一 ...

  8. 为什么在默认情况下无法修改被block捕获的变量? __block都做了什么?

    默认情况下,block里面的变量,拷贝进去的是变量的值,而不是指向变量的内存的指针.使用__block修饰后的变量,拷贝到block里面的就是指向变量的指针,所以我们就可以修改变量的值.

  9. ubuntu 14.04安装nginx+php

    转自:http://www.cnblogs.com/helinfeng/p/4219051.html 基于最新的Ubuntu 14.04(2014年9月)搭建nginx.php.mysql环境,以下全 ...

  10. AutoMapper.RegExtension 介绍

    AutoMapper.RegExtension 为一个特小特小特小的用来根据约定自动调用AutoMapper中的方法配置映射的扩展库.你可以引入该库也可以将源码中核心部分的代码文件夹整个拷贝至项目中. ...