题目链接: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 (树状数组)的更多相关文章

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

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

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

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

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

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

  4. UVALive - 4329 Ping pong 树状数组

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

  5. UVALive 6911 Double Swords 树状数组

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

  6. UVALive 4329 树状数组第二题

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

  7. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  8. bzoj1878--离线+树状数组

    这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...

  9. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. 关于js中闭包的理解

    1.以前很不理解js中闭包的概念及使用,下面来看一下 function foo() { var a = 123; var b = 456; return function () { return a; ...

  2. chrome 点击上传文件选择框会延迟几秒才会显示 反应很慢

    chrome52.0.2743.80以上, accept: { title: 'Images', extensions: 'jpg,jpeg,png', mimeTypes: 'image/*' } ...

  3. webservice 接口通过 HTTP 获取数据

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Ne ...

  4. Java线程的5个使用技巧

    萝卜白菜各有所爱.像小编我就喜欢Java.学无止境,这也是我喜欢它的一个原因.日常工作中你所用到的工具,通常都有些你从来没有了解过的东西,比方说某个方法或者是一些有趣的用法.比如说线程.没错,就是线程 ...

  5. 关于SharpZipLib压缩分散的文件及整理文件夹的方法

    今天为了解决压缩分散的文件时,发现想通过压缩对象直接进行文件夹整理很麻烦,因为SharpZipLib没有提供压缩进某个指定文件夹的功能,在反复分析了SharpZipLib提供的各个接口方法后,终于找到 ...

  6. position与z-index的关系

    .simulationgame .gameranking .rankinginfo{ width:140px; margin:0 auto; font-family:Arial, Microsoft ...

  7. C# 根据前台校验的值,决定是否执行后台方法

    <asp:Button ID="Add" runat="server" Text="加入" class="add" ...

  8. selenium第二课(脚本录制seleniumIDE的使用)

    一.Selenium也具有录制功能,可以web中回放,录制的脚本可以转换为java.python.ruby.php等多种脚本语言.seleniumIDE是Firefox的一个插件,依附于Firefox ...

  9. 老男孩python自动化运维作业1

    #!/usr/bin/env pthon #字典操作三级菜单 “b”返回上一级菜单,“q”退出. menu={"BJ":{"cp":{1:1,2:2,3:3}, ...

  10. Codeforces 702C Cellular Network

    题目:这里 题意:一条数轴上,有n个城市和m个塔,分别给出城市的位置和塔的位置,每个塔有个覆盖范围,问能将所有城市都覆盖的塔的最小范围是多少,一个城市只要被至少一个塔 覆盖就行. 可以利用贪心的思想模 ...