poj 3468 A Simple Problem with Integers(线段树 插线问线)
#include<iostream>
#include<stdio.h>
#include<string.h>
#define NN 2500000 using namespace std; typedef long long LL;
struct node
{
LL l,r,sum,flag;
} N[NN]; void build(LL l,LL r,LL i)
{
LL mid=(l+r)>>1;
N[i].flag=0;
N[i].l=l;
N[i].r=r;
N[i].sum=0;
if(l==r)
{
scanf("%lld",&N[i].sum);
return ;
}
build(l,mid,i*2);
build(mid+1,r,i*2+1);
N[i].sum=N[i*2].sum+N[i*2+1].sum;
} void renew(LL i,LL l,LL r,LL k)
{
LL mid=(N[i].l+N[i].r)>>1;
if(N[i].l==l&&N[i].r==r)
{
N[i].flag+=k;
return ;
}
N[i].sum+=(r-l+1)*k;
if(mid<l) renew(i*2+1,l,r,k);
else if(mid>=r)renew(i*2,l,r,k);
else
{
renew(i*2,l,mid,k);
renew(i*2+1,mid+1,r,k);
}
} LL query(LL i,LL l,LL r)
{
LL mid=(N[i].l+N[i].r)>>1;
if(l==N[i].l&&r==N[i].r)
{
return N[i].sum+(r-l+1)*N[i].flag;
}
if(N[i].flag)
{
N[i*2].flag+=N[i].flag;
N[i*2+1].flag+=N[i].flag;
N[i].sum+=(N[i].r-N[i].l+1)*N[i].flag;
N[i].flag=0;
}
if(l>mid) return query(i*2+1,l,r);
else if(r<=mid) return query(i*2,l,r);
else
{
return query(i*2+1,mid+1,r)+query(i*2,l,mid);
}
} int main()
{
LL n,m,suzi,a,b,i;
char s[5];
while(scanf("%lld %lld",&n,&m)!=EOF)
{
build(1,n,1);
// prLLf("sdd=%lld\n",N[8].sum);
// return 0;
for(i=1; i<=m; i++)
{
scanf("%s",s);
// return 0;
if(s[0]=='C')
{
LL a,b,c;
scanf("%lld %lld %lld",&a,&b,&c);
renew(1,a,b,c);
}
else
{
LL a,b;
scanf("%lld %lld",&a,&b);
printf("%lld\n",query(1,a,b));
}
}
}
return 0;
}
poj 3468 A Simple Problem with Integers(线段树 插线问线)的更多相关文章
- poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和
A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...
- poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和(模板)
A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...
- poj 3468 A Simple Problem with Integers 线段树第一次 + 讲解
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal w ...
- [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal ...
- poj 3468 A Simple Problem with Integers (线段树区间更新求和lazy思想)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 75541 ...
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- POJ 3468 A Simple Problem with Integers //线段树的成段更新
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 59046 ...
- poj 3468 A Simple Problem with Integers 线段树加延迟标记
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal ...
- poj 3468 A Simple Problem with Integers 线段树区间更新
id=3468">点击打开链接题目链接 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072 ...
- POJ 3468 A Simple Problem with Integers(线段树,区间更新,区间求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 67511 ...
随机推荐
- Hibrenate load 和 get
这次我们来谈一下Hibernate3.2 Session加载数据时get和load方法的区别(Hibernate 3以后的版本就用get()方法取代find()这个方法了),其实这个在网上有很多的论述 ...
- 微信小程序项目结构
- Idea其他设置
一.生成javadoc Tools->Gerenate JavaDoc 1. 选择是整个项目还是模块还是单个文件 2. 文档输出路径 3. Locale 选择地区,这个决定了文档的语言,中文就是 ...
- Idea配置Tomcat以及maven
配置Tamcat Run-->Edit Configurations +-->如果列表里没有tomcat-->点击33 items more irrelevant继续寻找--> ...
- HDU - 5572 An Easy Physics Problem (计算几何模板)
[题目概述] On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volum ...
- 高性能JS-DOM
用脚本进行DOM操作的代价是很昂贵的,它是富web应用中最常见的性能瓶颈.主要有以下三种问题: 访问和修改DOM元素 修改DOM元素的样式导致repaint和reflow 通过DOM事件处理与用户进行 ...
- react 起手式
http://blog.csdn.net/zhouzhiande/article/details/52349344 http://blog.csdn.net/zhouzhiande/article/d ...
- 一步步走向国际乱码大赛-- 恶搞C语言
大家都一直强调规范编码.可是这个世界上有个大师们娱乐的竞赛--国际乱码大赛. 能写出来的都是对语言深入了解的master.我从没想自己也能"恶搞"C,一直都是老老实实编码.就在前几 ...
- 【转】LINUX 手动建立SWAP文件及删除
如何在红帽 企业版Linux系统中添加swap文件? 解决方法: 1. 确定swap文件的大小,单位为M.将该值乘以1024得到块大小.例如,64MB的swap文件的块大小是65536. 2. 在ro ...
- [LeetCode][Java] Longest Common Prefix
题目: Write a function to find the longest common prefix string amongst an array of strings. 题意: 写出一个函 ...