UVALive 2191 Potentiometers (树状数组)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=192
给你一个长度为n的数组A,有两种操作,操作一:(S x y) 将A[x]的大小置为y,操作二:(M x y) 求A[x], A[x+1] ... A[y]的和
用一个额外的数组tmp存储数组A,然后将 S x y转换为树状数组的 add x y-tmp[x]
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 200010
using namespace std; typedef long long LL; LL c[maxn];
int n, arr[maxn]; int lowbit(int x); void add(int x, int u); LL sum(int x); int main(void)
{
int ca = ;
while (scanf("%d", &n), n)
{
memset( c, , sizeof(c));
int x, y;
char ope[];
for (int i = ; i <= n; ++i)
{
scanf("%d", arr + i);
add( i, arr[i]);
}
if (ca)
putchar();
printf("Case %d:\n", ++ca);
while (scanf("%s", ope), ope[] != 'E')
{
scanf("%d %d", &x, &y);
if (ope[] == 'S')
{
add( x, y - arr[x]);
arr[x] = y;
}
else
{
printf("%lld\n", sum(y) - sum(x - ));
}
}
}
return ;
} int lowbit(int x)
{
return x&(-x);
} LL sum(int x)
{
LL result = ;
while (x > )
{
result += c[x];
x -= lowbit(x);
}
return result;
} void add(int x, int u)
{
while (x <= n)
{
c[x] += u;
x += lowbit(x);
}
}
UVALive 2191 Potentiometers (树状数组)的更多相关文章
- UVALive 6911---Double Swords(贪心+树状数组(或集合))
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 4329 Ping pong(树状数组)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13895 题意:一条街上住有n个乒乓选手,每个人都有一个技能值,现在 ...
- 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 ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- bzoj1878--离线+树状数组
这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- redis实现tomcat集群session共享
1.部署两个tomcat节点,使用nginx实现集群(见http://www.cnblogs.com/zhangzhi0556/articles/nginx.html): 2.redis安装(见h ...
- Pureftpd
在lnmp目录下运行./pureftpd.sh 如下:[root@cloud lnmp1.3-full]# 执行./pureftpd.sh 使用命令 Install Pure-FTPd complet ...
- SQL Server查询结果插入表
a) 插入新表 select * into newtable from table b) 插入已经存在的表 insert into table select * from table2 where.. ...
- 关于localstorage的几个测试
1.如果在同一主域名下,localstorage能访问吗? 测试: 在www\index.php 中写入 localstorage 在www\wex5fortp\ui 目录下能否读到?? 结论:可以得 ...
- PHP入门篇
一.PHP-什么是变量 变量是用于存储值的,我们命令服务器去干活的时候,往往需要产生一些数据,需要临时性存放起来,方便取用.我们也可以理解为,变量就像一个购物袋,我们可以用来装苹果.榴莲(当然也可以 ...
- python第十九天-----Django进阶
1.机智的小django为我你们提供了快捷的表单验证! from django.shortcuts import render, HttpResponse,redirect from django i ...
- easyui 中datagrid 点击行的事件
$('#datagrid 的ID').datagrid({ onClickRow:function(index,data) { ...
- 使用sql更改表的列的数据类型和添加新列和约束
修改数据库表某一列或添加列,转载的哦~ --增加一列 ALTER TABLE 表名 ADD 列名 VARCHAR(20) NULL --删除一列 ALTER TABLE 表名 drop COLUMN ...
- git入门操作命令(转载)
以下为git环境搭建: 先建用户-->建组-->用户添加到组 新建项目,命名空间选择组 项目建完后,会分配远端地址. 然后本地配置好远端地址后,提交代码. 设置用户,邮箱 git ...
- PDFsharp Samples
http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx http://www.pdfsharp.net/?AspxAutoDetectCookieSuppo ...