LA 2191 - Potentiometers
Fenwick树的应用~~~
#include <cstdio>
#include <cstring>
#include<algorithm>
using namespace std;
const int MAXN=200000+10;
int a[MAXN],c[MAXN],n; inline int lowbit(const int &x)
{
return x&(-x);
} void add(int x,int d)
{
while(x<=n)
{
c[x]+=d;
x+=lowbit(x);
}
} long long sum(int L,int R)
{
int x=R;
long long ans=0;
while(x>0)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
} int main()
{
int kase=1;
while(scanf("%d",&n),n)
{
if(kase!=1)
printf("\n");
printf("Case %d:\n",kase++);
memset(c,0,sizeof(c));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
add(i,a[i]);
}
char action[10];
while(scanf("%s",action),strcmp(action,"END"))
{
int x,y;
scanf("%d%d",&x,&y);
if(action[0]=='S')
{
add(x,y-a[x]);
a[x]=y;
}
else
{ printf("%lld\n",sum(x,y)-sum(1,x-1));}
}
}
}
LA 2191 - Potentiometers的更多相关文章
- UVALive 2191 Potentiometers (树状数组)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- TTTTTTTTTTTTT LA 2191 树状数组 稍修改
题意:给出n个数字,操作有修改(S)和输出区间和(M). #include <iostream> #include <cstdio> #include <cstring& ...
- 数据结构习题 线段树&树状数组
说明:这是去年写了一半的东西,一直存在草稿箱里,今天整理东西的时候才发现,还是把它发表出来吧.. 以下所有题目来自Lrj的<训练指南> LA 2191 单点修改,区间和 Fenwick直 ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- hdu 2191 珍惜现在,感恩生活
链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2191 思路:多重背包模板题 #include <stdio.h> #include ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
- hdu 2191 多重背包
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
随机推荐
- 认识 Atlassian Datacenter 产品
认识 Atlassian Datacenter 产品 云端原本就是群集化的架构,Atlassian 系列产品.应用的开发团队相当广范且行之有年,可是将应用程序作为节点(比方Jira,confluenc ...
- tomcat 分别在window 和 Linux上配置SSL-安全问题
公司项目收尾后.通过压力測试后的安全測试.安全測试后中,对于网络传输中数据加密问题存在安全隐患. 须要配置SSL. 简介下SSL协议:SSL或者Secure Socket Layer,是一种同意web ...
- 通过js动态创建button
通过js动态创建button 一.实例描述 通过JS的DOM对象,实现元素的动态创建. 二.效果 三.代码 <!DOCTYPE html> <html lang="zh-c ...
- ubuntu 分屏工具
本文提到的分屏工具,均可通过sudo apt-get install的方式进行安装: 基本:terminator 高级:tmux,screen 还可进一步使用:ctrl + superkey + 方向 ...
- C#使用一般处理程序(ashx)中session
.ashx中引用 session必须 using System.Web.SessionState ,继承IReadOnlySessionState/IRequiresSessionState IRea ...
- linux6.0系统如何安装portmap
因为在6.0的系统里,portmap已经改名了.在Redhat或CentOS5中可以使用 service portmap start启动服务,然后在启动nfs服务,实现挂载. 6里面可是试试 serv ...
- VFS相关内容
http://blog.csdn.net/icyfire0105/article/details/1899927 VFS是一个软件层,用来处理与Unix标准文件系统相关的所有系统调用,是用户应用程序与 ...
- poj3244(公式题)
Difference between Triplets Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2476 Acce ...
- ubuntu16 升级后找不到 eth0 网卡 的解决方法
ubuntu16 升级后找不到 eth0 网卡 的解决方法 今天在VPS上一时手痒,执行了升级命令 apt-get update 更新软件包索引,源 apt-get upgrade 更新软件包 apt ...
- 19,tuple多元数组
#include <iostream> #include <tuple> using namespace std; void main() { char ch = 'a'; ; ...