http://acm.fzu.edu.cn/problem.php?pid=2171

成段增减,区间求和.add累加更新的次数。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 100010
#define mod 1000000007
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int sum[maxn<<];
int add[maxn<<]; void PushUp(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
} void PushDown(int rt,int m)
{
if(add[rt])
{
add[rt<<]+=add[rt];
add[rt<<|]+=add[rt];
sum[rt<<]+=(m-(m>>))*add[rt];
sum[rt<<|]+=(m>>)*add[rt];
add[rt]=;
}
} void build(int l,int r,int rt)
{
add[rt]=;
if(l==r)
{
scanf("%d",&sum[rt]);
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
PushUp(rt);
} void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
add[rt]+=c;
sum[rt]+=c*(r-l+);
return;
}
PushDown(rt,r-l+);
int m=(l+r)>>;
if(L<=m) update(L,R,c,lson);
if(m<R) update(L,R,c,rson);
PushUp(rt);
} int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
return sum[rt];
}
PushDown(rt,r-l+);
int m=(l+r)>>;
int ret=;
if(L<=m) ret+=query(L,R,lson);
if(m<R) ret+=query(L,R,rson);
return ret;
}
int main()
{
// freopen("a.txt","r",stdin);
int n,m,q;
while(~scanf("%d%d%d",&n,&m,&q))
{
build(,n,);
int ans,x;
while(q--)
{
scanf("%d",&x);
ans=query(x,x+m-,,n,);
update(x,x+m-,-,,n,);
printf("%d\n",ans);
}
}
return ;
}

FZU Problem 2171 防守阵地 II (线段树区间更新模板题)的更多相关文章

  1. POJ 3468:A Simple Problem with Integers(线段树区间更新模板)

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

  2. hihoCoder #1078 : 线段树的区间修改(线段树区间更新板子题)

    #1078 : 线段树的区间修改 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 对于小Ho表现出的对线段树的理解,小Hi表示挺满意的,但是满意就够了么?于是小Hi将问题 ...

  3. 线段树 + 区间更新 + 模板 ---- poj 3468

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

  4. A Simple Problem with Integers(线段树区间更新模板)

    最基本的线段树的区间更新及查询和 用tag(lazy)数组来“延缓”更新,查询或添加操作必须进行pushdown操作,即把tag从p传到lp和rp并清楚tag[p],既然得往lp和rp递归,那么就可以 ...

  5. FZU2171:防守阵地 II(线段树)

     Problem Description 部队中总共同拥有N个士兵,每一个士兵有各自的能力指数Xi.在一次演练中,指挥部确定了M个须要防守的地点,指挥部将选择M个士兵依次进入指定地点进行防守任务.获得 ...

  6. HDU 1698 Just a Hook (线段树区间更新入门题)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. HDU1698:Just a Hook(线段树区域更新模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat ...

  8. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  9. fzu 2171 防守阵地 II

    Problem 2171 防守阵地 II Accept: 31    Submit: 112Time Limit: 3000 mSec    Memory Limit : 32768 KB  Prob ...

随机推荐

  1. Elasticsearch--集群&吞吐量

    目录 高查询和高吞吐量 过滤器缓存 字段数据缓存和断路器 断路器 存储模块 索引缓冲和刷新率 索引刷新率 线程池的配置 一些通用的建议来配置高索引和查询吞吐量的集群 高查询和高吞吐量 过滤器缓存 过滤 ...

  2. Hadoop YARN学习之重要术语总结(6)

    Hadoop YARN学习之重要术语总结(6) - SLA服务等级 - RM(ResourceManager) - AM(ApplicationMaster) - NM(NodeMaster) - M ...

  3. Android 在代码中安装 APK 文件

    废话不说,上代码 private void install(String filePath) { Log.i(TAG, "开始执行安装: " + filePath); File a ...

  4. 掌握Spark机器学习库-07-回归算法原理

    1)机器学习模型理解 统计学习,神经网络 2)预测结果的衡量 代价函数(cost function).损失函数(loss function) 3)线性回归是监督学习

  5. 10.3 Implementing pointers and objects and 10.4 Representing rooted trees

    Algorithms 10.3 Implementing pointers and  objects  and 10.4 Representing rooted trees Allocating an ...

  6. 【My First Blog】评近期国产烂片-《何以笙箫默》

    昨晚,我脑抽去看了[何以笙箫默],看完后我的感觉就是被这部片子恶心到了,现在想起来我还是想说:何以笙箫默是烂片烂片烂片!重要的是说三遍.以前,我问电视剧版<何以笙箫默>何以这么LOW,看了 ...

  7. druid监控及慢sql记录

    本文提要 前文也提到过druid不仅仅是一个连接池技术,因此在将整合druid到项目中后,这一篇文章将去介绍druid的其他特性和功能,作为一个辅助工具帮助提升项目的性能,本文的重点就是两个字:监控. ...

  8. 使用Caliburn.Micro系列2:Convention

    CM中实现一个比较有意思的特性,就是智能匹配. 通常使用MVVM的写法:在匹配 View和ViewModel时会使用DataContext,在匹配数据属性时使用Binding,在匹配事件命令时使用Co ...

  9. 在mac下做web开发,shell常用的快捷键

    Ctrl + A 光标移动到行首 Ctrl + E 光标移动到行末 Ctrl + K 清屏(也可是用clear命令) Command +shift+{} 终端的tab左右切换

  10. BZOJ 3595: [Scoi2014]方伯伯的Oj Splay + 动态裂点 + 卡常

    Description 方伯伯正在做他的Oj.现在他在处理Oj上的用户排名问题. Oj上注册了n个用户,编号为1-”,一开始他们按照编号排名.方伯伯会按照心情对这些用户做以下四种操作,修改用户的排名和 ...