UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 |
A potentiometer, or potmeter for short, is an electronic device with a variable electric resistance. It has two terminals and some kind of control mechanism (often a dial, a wheel or a slide) with which the resistance between the terminals can be adjusted from zero (no resistance) to some maximum value. Resistance is measured in Ohms, and when two or more resistors are connected in series (one after the other, in a row), the total resistance of the array is the sum of the resistances of the individual resistors.
In this problem we will consider an array of N potmeters, numbered 1 to N from left to right. The left terminal of some potmeter numbered x is connected to the right terminal of potmeter x − 1, and its right terminal to the left terminal of potmeter x + 1. The left terminal of potmeter 1 and the right terminal of potmeter N are not connected.
Initially all the potmeters are set to some value between 0 and 1000 Ohms. Then we can do two things:
• Set one of the potmeters to another value.
• Measure the resistance between two terminals anywhere in the array.
Input
The input consists less than 3 cases. Each case starts with N, the number of potmeters in the array,
on a line by itself. N can be as large as 200000. Each of next N lines contains one numbers between 0
and 1000, the initial resistances of the potmeters in the order 1 to N. Then follow a number of actions,
each on a line by itself. The number of actions can be as many as 200000. There are three types of
action:
“S x r” - set potmeter x to r Ohms. x is a valid potmeter number and r is between 0 and 1000.
“M x y” - measure the resistance between the left terminal of potmeter x and the right terminal
of potmeter y. Both numbers will be valid and x is smaller than or equal to y.
“END” - end of this case. Appears only once at the end of a list of actions.
A case with N = 0 signals the end of the input and it should not be processed.
OutputFor each case in the input produce a line ‘Case n:’, where n is the case number, starting from 1.
For each measurement in the input, output a line containing one number: the measured resistancein Ohms. The actions should be applied to the array of potmeters in the order given in the input.
Print a blank line between cases.Warning: Input Data is pretty big (∼ 8 MB) so use faster IO.
Sample Input3
100
100
100
M11
M13
S 2 200
M12
S30
M23
END
10
1
2
3
4
5
6
7
8
9
10
M 1 10
END
0Sample Output
Case 1:
100
300
300200
Case 2: 55
单点修改和区间查询
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N=2e5+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,a[N],c[N],x,y;
char op[];
inline int lowbit(int x){return x&-x;}
inline void build(int n){
memset(c,,sizeof(c));
for(int i=;i<=n;i++){
c[i]+=a[i];
if(i+lowbit(i)<=n) c[i+lowbit(i)]+=c[i];
}
}
inline void add(int p,int v){
a[p]+=v;
for(int i=p;i<=n;i+=lowbit(i)) c[i]+=v;
}
inline int sum(int p){
int ans=;
for(int i=p;i>;i-=lowbit(i)) ans+=c[i];
return ans;
}
int main(){
int cas=;
while((n=read())){
if(cas!=) putchar('\n');
printf("Case %d:\n",++cas);
for(int i=;i<=n;i++) a[i]=read();
build(n);
while(true){
scanf("%s",op);
if(op[]=='E') break;
if(op[]=='S'){
x=read();y=read();
y=y-a[x];
add(x,y);
}else{
x=read();y=read();
printf("%d\n",sum(y)-sum(x-));
}
}
}
}
UVALive - 3942 Remember the Word[树状数组]的更多相关文章
- UVALive 4329 Ping pong(树状数组)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13895 题意:一条街上住有n个乒乓选手,每个人都有一个技能值,现在 ...
- UVALive 6947 Improvements(DP+树状数组)
[题目链接] https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sho ...
- UVALive 3942 Remember the Word 字典树+dp
/** 题目:UVALive 3942 Remember the Word 链接:https://vjudge.net/problem/UVALive-3942 题意:给定一个字符串(长度最多3e5) ...
- UVALive 6911---Double Swords(贪心+树状数组(或集合))
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 2191 Potentiometers (树状数组)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UvaLive 6667 Longest Chain (分治求三元组LIS&树状数组)
题目链接: here 题意: 和hdu4742类似.差别就是一部分三元组是直接给出的.另一部分是用他给的那个函数生成的.还有就是这里的大于是严格的大于a>b必须ax>bx,ay>by ...
- UVALive - 4329 Ping pong 树状数组
这题不是一眼题,值得做. 思路: 假设第个选手作为裁判,定义表示在裁判左边的中的能力值小于他的人数,表示裁判右边的中的能力值小于他的人数,那么可以组织场比赛. 那么现在考虑如何求得和数组.根据的定义知 ...
- UVALive 6911 Double Swords 树状数组
Double Swords 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8 ...
- UVALive 4329 树状数组第二题
大白书上的题目,比较巧妙的是其分析,为了求某个i点做裁判的时候的情况数,只要知道左边有多少比它小的记为ansc,右边有多少比它小的记为ansd,则总种数,必定为 ansc*(右边总数-ansd)+an ...
随机推荐
- 【C#进阶系列】23 程序集加载和反射
程序集加载 程序集加载,CLR使用System.Reflection.Assembly.Load静态方法,当然这个方法我们自己也可以显式调用. 还有一个Assembly.LoadFrom方法加载指定路 ...
- 基于Eclipse的Hadoop应用开发环境配置
基于Eclipse的Hadoop应用开发环境配置 我的开发环境: 操作系统ubuntu11.10 单机模式 Hadoop版本:hadoop-0.20.1 Eclipse版本:eclipse-java- ...
- 为什么document.firstChild找到的不是html节点
DOM是针对HTML4.01开发的,我们现在是XHTML1.0. 所以要想使用核心DOM中的属性和方法,必须去掉DTD类型定义. <!DOCTYPE html PUBLIC "-//W ...
- Apache Shiro系列(1)
Apache Shiro是啥呢,安全框架. 360百科是这么描述的: Apache Shiro(日语"堡垒(Castle)"的意思)是一个强大易用的Java安全框架, ...
- struts通过action返回json
其实struts2通过action返回json挺简单的,但是就是老要忘,所以索性写在博客上.好的,开始. 首先是引入必须的jar包: struts2-json-plugin-2.3.24.jar 然后 ...
- S2---深入.NET平台和C#编程的完美总结
1.NET简单解说 l 面向对象提升 OOP(Object Oriented Programming)面向对象编程 AOP:(Aspache Oriented Programming):面向切面编 ...
- box-sizing重置盒子模型计算规则
目标大纲 一.语法声明 box-sizing : content-box | border-box | inherit 二.属性值说明 content-box 在宽度和高度之外绘制元素的内边距和边框 ...
- jquery和css3实现滑动导航菜单
效果预览:http://keleyi.com/keleyi/phtml/html5/15/ 有都中颜色可供选择,请使用支持HTML5/CSS3的浏览器访问. HTML源代码: <!DOCTYPE ...
- jquery右下角自动弹出关闭层
效果体验:http://keleyi.com/keleyi/phtml/jqtexiao/36.htm 右下角弹出层后,会在一定时间后自动隐藏.第一版本:http://www.cnblogs.com/ ...
- JS高程3.基本概念(3)
1.ECMAScript数值的范围 由于内存的限制,在大多数浏览器中,ECMAScript能够拿保存的数据的范围是 5e-324 ~ 1.7976931348623157e+308,其中最小的数值保存 ...