【线段树(单点修改,区间求和)】HDU1166 - 敌军布阵
hdu1166 敌兵布阵,单点修改,区间求和。
【ATTENTION】MAXN要开成节点数的4倍,开得不够会提示TLE。
#include<iostream>
#include<cstdio>
#include<cstring>
#define lson l,m,root<<1
#define rson m+1,r,root<<1|1
using namespace std;
const int MAXN=*+;
int n;
int sum[MAXN]; void pushUP(int root)
{
sum[root]=sum[root<<]+sum[root<<|];
} void build(int l,int r,int root)
{
if (l==r)
{
scanf("%d",&sum[root]);
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
pushUP(root);
} void update(int p,int delta,int l,int r,int root)
{
if (l==r)
{
sum[root]+=delta;
return;
}
int m=(l+r)>>;
if (p<=m) update(p,delta,lson);
if (p>m) update(p,delta,rson);
pushUP(root);
} int query(int L,int R,int l,int r,int root)
{
int result=;
if (l>=L && r<=R)
{
return sum[root];
}
int m=(l+r)>>;
if (L<=m) result+=query(L,R,lson);
if (R>m) result+=query(L,R,rson);
return result;
} int main()
{
int t;
scanf("%d",&t);
for (int kase=;kase<t;kase++)
{
cout<<"Case "<<kase+<<":"<<endl;
scanf("%d",&n);
build(,n,);
char s[];
while (scanf("%s",s))
{
if (s[]=='E') break;
int a,b;
scanf("%d%d",&a,&b);
if (s[]=='A') update(a,b,,n,);
if (s[]=='S') update(a,-b,,n,);
if (s[]=='Q') cout<<query(a,b,,n,)<<endl;
}
}
return ;
}
【线段树(单点修改,区间求和)】HDU1166 - 敌军布阵的更多相关文章
- Lightoj 1348 Aladdin and the Return Journey (树链剖分)(线段树单点修改区间求和)
Finally the Great Magical Lamp was in Aladdin's hand. Now he wanted to return home. But he didn't wa ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)
POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu1166(线段树单点更新&区间求和模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...
- hdu1394(枚举/树状数组/线段树单点更新&区间求和)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给出一个循环数组,求其逆序对最少为多少: 思路:对于逆序对: 交换两个相邻数,逆序数 +1 ...
- I Hate It HDU - 1754 线段树 单点修改+区间最值
#include<iostream> #include<cstring> using namespace std; ; int m,n,p; struct node{ int ...
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
- hdu1754(线段树单点替换&区间最值模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 题意:中文题诶- 思路:线段树单点替换&区间最大值查询模板 代码: #include & ...
随机推荐
- js刷新页面方法 -- (转)
1,reload 方法,该方法强迫浏览器刷新当前页面. 语法:location.reload([bForceGet]) 参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里 ...
- python进行机器学习(五)之模型打分
一.画出模型的残差值分布情况 #!/usr/bin/python import pandas as pd import numpy as np import csv as csv import mat ...
- 记一次Powershell反混淆 (1)
样本地址: https://www.virustotal.com/#/file/6f9034646e6fcead5342f708031412e3c2efdb4fb0f37bba43133a471d1c ...
- ubuntu tomcat的安装与配置
一.下载jdk 大概是tomat大部分是由java写的, 所以一开始安装tomcat必须得配置好jdk http://www.oracle.com/technetwork/java/javase/do ...
- Opencv模块功能介绍
本文为原创作品,转载请注明出处 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www.cnblogs.com/xujianqing/ 站在巨 ...
- monkey测试===easyMonkey测试【推荐】
easymonkey测试: easymonkey是基于monkey测试的一个二次开发工具.(关于monkey测试参见之前blog) easymonkey的特点就是方便,解决了很多参数命令上设置的麻烦, ...
- 003 CopyOnWriteArrayList原理
聊聊并发-Java中的Copy-On-Write容器 Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容,当某个人想要修改这个内容的时候 ...
- BNU - 49102
进化之地(Evoland) Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO for ...
- golang fmt格式占位符
golang 的fmt 包实现了格式化I/O函数,类似于C的 printf 和 scanf. # 定义示例类型和变量 type Human struct { Name string } var peo ...
- LeetCode解题报告—— Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = ...