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.
    Output

    For 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 resistance

    in 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 Input

    3
    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
    0

    Sample Output

    Case 1:
    100
    300
    300

    200

    Case 2: 55


单点修改和区间查询

改成y等价于+y-a[x]
 
#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[树状数组]的更多相关文章

  1. UVALive 4329 Ping pong(树状数组)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13895 题意:一条街上住有n个乒乓选手,每个人都有一个技能值,现在 ...

  2. UVALive 6947 Improvements(DP+树状数组)

    [题目链接] https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sho ...

  3. UVALive 3942 Remember the Word 字典树+dp

    /** 题目:UVALive 3942 Remember the Word 链接:https://vjudge.net/problem/UVALive-3942 题意:给定一个字符串(长度最多3e5) ...

  4. UVALive 6911---Double Swords(贪心+树状数组(或集合))

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  5. UVALive 2191 Potentiometers (树状数组)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. UvaLive 6667 Longest Chain (分治求三元组LIS&amp;树状数组)

    题目链接: here 题意: 和hdu4742类似.差别就是一部分三元组是直接给出的.另一部分是用他给的那个函数生成的.还有就是这里的大于是严格的大于a>b必须ax>bx,ay>by ...

  7. UVALive - 4329 Ping pong 树状数组

    这题不是一眼题,值得做. 思路: 假设第个选手作为裁判,定义表示在裁判左边的中的能力值小于他的人数,表示裁判右边的中的能力值小于他的人数,那么可以组织场比赛. 那么现在考虑如何求得和数组.根据的定义知 ...

  8. UVALive 6911 Double Swords 树状数组

    Double Swords 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8 ...

  9. UVALive 4329 树状数组第二题

    大白书上的题目,比较巧妙的是其分析,为了求某个i点做裁判的时候的情况数,只要知道左边有多少比它小的记为ansc,右边有多少比它小的记为ansd,则总种数,必定为 ansc*(右边总数-ansd)+an ...

随机推荐

  1. Unity3D 5.x 简单实例 - 发射炮弹

    1,下载.安装: http://unity3d.com/cn/get-unity/download/archive 建议直接借助 UnityDownloadAssistant 进行安装,根据需要勾选需 ...

  2. swift变量和函数

    func getNums()->(Int,Int){ //swift函数可以返回多个变量 ,) } let (a,b) = getNums() //let是常量,一旦赋值后不可改变, var是变 ...

  3. Intellij IDEA 导入 eclipese项目之后,中文注释乱码解决方案

    首先,看导入后整个IJ界面: 可以看到注释是乱码,要解决问题就跟我开始做吧,看右下角有个"UTF-8",点一下选择"GBk",选择"Reload&qu ...

  4. Session中load/get方法的详细区别

    Session.load/get方法均可以根据指定的实体类和id从数据库读取记录,并返回与之对应的实体对象.其区别在于: 如果未能发现符合条件的记录,get方法返回null,而load方法会抛出一个O ...

  5. ASP.NET MVC搭建项目后台UI框架—4、tab多页签支持

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  6. 第一次react-native项目实践要点总结

    今天完成了我的第一个react-native项目的封包,当然其间各种环境各种坑,同时,成就感也是满满的.这里总结一下使用react-native的一些入门级重要点(不涉及环境).注意:阅读需要语法基础 ...

  7. Quartz2D简介

    Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统 Quartz 2D能完成的工作:

  8. WaterfallFlowLayout瀑布流用重写UICollectionViewFlowLayout类实现

    最近调研瀑布流,在gitHub上下了个Demo发现它的所有视图都是用Main.storyboard拖的, 自己研究半天没研究明白; 然后就又找了一个Demo, 它的视图全是手打的, 但是实现的方法不太 ...

  9. Android Bitmap占用内存计算公式

    Android对各分辨率的定义 当图片以格式ARGB_8888存储时的计算方式 占用内存=图片长*图片宽*4字节 图片长 = 图片原始长 (设备DPI/文件夹DPI)  图片宽 = 图片原始宽(设备D ...

  10. linux版基金看板

    程序员的吊丝们,还在害怕上班时偷偷看基金被老板发现吗?今天你们的福利来了,专属程序员吊丝一族的礼物,linux版基金看板. 优点: 1.自定义设置关注基金 2.linux系统,让别人可以以为你一直都在 ...