poj 3468 A Simple Problem with Integers 模板题 线段树 懒惰标记
来源:互联网 发布:i5处理器编程够用么 编辑:程序博客网 时间:2024/05/22 00:40
#include <iostream>
#include<cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int maxn=100000;
ll data[4*maxn+5],datb[4*maxn+5],l[maxn+5],r[maxn+5],v[maxn+5];
char op[maxn+5][3];
ll max(ll a,ll b)
{
return a>b?a:b;
}
ll min(ll a ,ll b)
{
return a<b?a:b;
}
ll s(int k,int a,int b,int l,int r)
{
ll sum=0;
if(l<=a&&b<=r)
sum=data[k]*(b-a)+datb[k];
else if(r>a&&l<b)
{
ll left=s(2*k+1,a,(a+b)>>1,l,r);
ll right=s(2*k+2,(a+b)>>1,b,l,r);
sum=data[k]*(min(b,r)-max(a,l))+left+right;
}
return sum;
}
void add(int k,int a,int b,int l,int r,int v)
{
if(l<=a&&b<=r)
data[k]+=v;
else if(r>a&&l<b)
{
datb[k]+=(min(b,r)-max(a,l))*v;
add(2*k+1,a,(a+b)>>1,l,r,v);
add(2*k+2,(a+b)>>1,b,l,r,v);
}
}
int main()
{
int n,c,temp;
while(~scanf("%d %d",&n,&c))
{
for(int i=1;i<=n;i++)
{
scanf("%d",&temp);
add(0,1,n+1,i,i+1,temp);
}
for(int i=1;i<=c;i++)
{
scanf("%s",op[i]);
if(op[i][0]=='Q')
scanf("%d %d",&l[i],&r[i]);
else
scanf("%d %d %d",&l[i],&r[i],&v[i]);
}
for(int i=1;i<=c;i++)
{
if(op[i][0]=='Q')
printf("%lld\n",s(0,1,n+1,l[i],r[i]+1));
else
add(0,1,n+1,l[i],r[i]+1,v[i]);
}
}
return 0;
}
- poj 3468 A Simple Problem with Integers 模板题 线段树 懒惰标记
- [ACM] poj 3468 A Simple Problem with Integers(线段树,成段更新,懒惰标记)
- poj 3468 A Simple Problem with Integers(线段树成段更新,懒惰标记的使用)经典题目
- poj 3468 Simple Problem with Integers(区间更新+懒惰标记)
- poj3468 A Simple Problem with Integers (线段树的懒惰标记)
- POJ-3468 A Simple Problem with Integers(线段树模板题)
- POJ 3468 A Simple Problem with Integers 线段树区间更新 纯模板题
- POJ 3468 A Simple Problem with Integers(线段树区间更新模板题)
- POJ 3468 A Simple Problem with Integers (线段树区间更新模板题)
- POJ 3468 A Simple Problem with Integers(线段树区间更新模板题)
- poj-3468-A Simple Problem with Integers 线段树lazy标记
- POJ 3468-A Simple Problem with Integers(线段树_区间更新+lazy标记)
- C - A Simple Problem with Integers POJ 3468(线段树+延迟标记)
- Poj 3468 A Simple Problem with Integers(线段树 区间更新 延迟标记)
- POJ 3468 A Simple Problem with Integers(线段树 ,延迟标记)
- poj 3468 A Simple Problem with Integers(线段树+延迟标记)
- [poj] 3468 A Simple Problem with Integers [线段树][区间加&求和][懒标记]
- POJ 3468 A Simple Problem with Integers(线段树,延迟标记)
- poj 3279 Fliptile 反转
- poj 3185 The Water Bowls 反转(开关)
- poj 1930 Dead Fraction 循环小数的处理
- poj 3421 X-factor Chains 素数筛选 因子分解
- poj 3292 Semi-prime H-numbers 素数变形+打表+筛选法
- poj 3468 A Simple Problem with Integers 模板题 线段树 懒惰标记
- POJ 3264 Balanced Lineup 线段树 维护区间最大值和最小值 建树
- poj 3368 Frequent values 线段树 节点值得变化
- git中checkout前后的branch变化
- 修改FMRadio频率的工作范围
- poj 1201 Intervals 线段树+贪心
- hdu 2602 Bone Collector 0-1背包;
- openssl与数字证书的使用
- CF #318 (Div. 2) C. Bear and Poker 唯一分解定理