FZU Problem 2171 防守阵地 II (线段树区间更新模板题)
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 (线段树区间更新模板题)的更多相关文章
- POJ 3468:A Simple Problem with Integers(线段树区间更新模板)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 141093 ...
- hihoCoder #1078 : 线段树的区间修改(线段树区间更新板子题)
#1078 : 线段树的区间修改 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 对于小Ho表现出的对线段树的理解,小Hi表示挺满意的,但是满意就够了么?于是小Hi将问题 ...
- 线段树 + 区间更新 + 模板 ---- poj 3468
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 59798 ...
- A Simple Problem with Integers(线段树区间更新模板)
最基本的线段树的区间更新及查询和 用tag(lazy)数组来“延缓”更新,查询或添加操作必须进行pushdown操作,即把tag从p传到lp和rp并清楚tag[p],既然得往lp和rp递归,那么就可以 ...
- FZU2171:防守阵地 II(线段树)
Problem Description 部队中总共同拥有N个士兵,每一个士兵有各自的能力指数Xi.在一次演练中,指挥部确定了M个须要防守的地点,指挥部将选择M个士兵依次进入指定地点进行防守任务.获得 ...
- HDU 1698 Just a Hook (线段树区间更新入门题)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU1698:Just a Hook(线段树区域更新模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- fzu 2171 防守阵地 II
Problem 2171 防守阵地 II Accept: 31 Submit: 112Time Limit: 3000 mSec Memory Limit : 32768 KB Prob ...
随机推荐
- java 缓冲流 Buffer
缓冲流 Buffer :设置缓冲区加快执行效率 子类: (一)BufferedInputStream : 缓冲输入字节流 ,目的:提高读取文件的效率 注意: BufferedInputStream ...
- Android 图片文件和Bitmap之间的转换
String filePath="c:/01.jpg"; Bitmap bitmap=BitmapFactory.decodeFile(filePath); 如果图片过大,可能导致 ...
- Rxjava2的学习与总结
博客地址:https://luhaoaimama1.github.io/2017/07/31/rxjava/
- Wamp搭建的服务器登录的时候出现Access denied for user 'hello'@'localhost' (using password: YES)
想用自己电脑做一个服务器,然后就选择了Wamp,本来一切顺利,可是到登录的时候却出现了问题,出现了 Access denied for user 'hello'@'localhost' (using ...
- 了解java内存回收机制-博客导读
此文作为读优质博客前的导读文 1.如何判断对象是否该回收 该对象是否被引用,是否处于不可达状态 2.对象的引用机制 强引用.软引用.弱引用.虚引用 3.垃圾回收机制如何回收.算法. 串行回收.并行回收 ...
- Spark学习笔记--Spark在Windows下的环境搭建(转)
本文主要是讲解Spark在Windows环境是如何搭建的 一.JDK的安装 1.1 下载JDK 首先需要安装JDK,并且将环境变量配置好,如果已经安装了的老司机可以忽略.JDK(全称是JavaTM P ...
- InChatter系统之客户端消息处理中心
一.模块结构 首先来看下客户端消息处理中心模块的简单结构: ChatCallback:服务器端我们定义的回调接口IChatCallback的客户端实现 ChatMsgCenter:服务端的消息处理中心 ...
- win+r 快速命令
control keymgr.dll 打开凭据管理器 secpol.msc 本地安全策略 mstsc 远程 msconfig 启动选项 %temp% 临时文件夹 \\192.168 ...
- day22-类的封装、property特性以及绑定方法与非绑定方法
目录 类的封装 两个层面的封装 第一个层面 第二个层面 封装的好处 私有模块 类的propertry特性 setter 和 deleter 类与对象的绑定方法与非绑定方法 类的封装 将类的属性或方法隐 ...
- C#根據當前DataGridView查詢數據導出Excel
private void btnsuggestinfo_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.C ...