uva 12086 树状数组
树状数组
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 200010
#define INF 0x7fffffff
#define inf 10000000
#define ull unsigned long long
#define ll long long
using namespace std; int a[maxn], arr[maxn]; int lowbit(int x)
{
return x&(-x);
} int sum(int x)
{
int ret = 0;
while(x > 0)
ret += a[x], x -= lowbit(x);
return ret;
} void add(int x, int d)
{
while(x < maxn)
a[x] += d, x += lowbit(x);
} void init()
{
memset(arr, 0, sizeof(arr));
memset(a, 0, sizeof(a));
}
int main()
{
int n, ca = 1;
while(scanf("%d", &n) == 1 && n)
{
init();
for(int i = 1; i <= n; ++ i)
{
scanf("%d", &arr[i]);
add(i, arr[i]);
}
char s[10];
if(ca > 1) puts("");
printf("Case %d:\n", ca++);
while(scanf("%s", s))
{
if(s[0] == 'E') break;
else if(s[0] == 'S')
{
int x, r;
scanf("%d%d", &x, &r);
add(x, r-arr[x]);
arr[x] = r;
}
else
{
int le, ri;
scanf("%d%d", &le, &ri);
printf("%d\n", sum(ri) - sum(le-1));
}
}
}
return 0;
}
uva 12086 树状数组的更多相关文章
- uva 12086 线段树or树状数组练习
题目链接 https://vjudge.net/problem/34215/origin 这个题就是线段树裸题,有两种操作,实现单点更新和区间和的查找即可,这里第一次学习使用树状数组完成. 二者相 ...
- UVA 1513 - Movie collection(树状数组)
UVA 1513 - Movie collection option=com_onlinejudge&Itemid=8&page=show_problem&category=5 ...
- UVA 11990 `Dynamic'' Inversion CDQ分治, 归并排序, 树状数组, 尺取法, 三偏序统计 难度: 2
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- Permutation UVA - 11525(值域树状数组,树状数组区间第k大(离线),log方,log)(值域线段树第k大)
Permutation UVA - 11525 看康托展开 题目给出的式子(n=s[1]*(k-1)!+s[2]*(k-2)!+...+s[k]*0!)非常像逆康托展开(将n个数的所有排列按字典序排序 ...
- UVA 11423 - Cache Simulator (树状数组)
UVA 11423 - Cache Simulator (树状数组) option=com_onlinejudge&Itemid=8&category=523&page=sho ...
- UVA 1428 - Ping pong(树状数组)
UVA 1428 - Ping pong 题目链接 题意:给定一些人,从左到右,每一个人有一个技能值,如今要举办比赛,必须满足位置从左往右3个人.而且技能值从小到大或从大到小,问有几种举办形式 思路: ...
- UVA 1513 Movie collection (树状数组+反向存储)
题意:给你n盘歌碟按照(1....n)从上到下放,接着m个询问,每一次拿出x碟,输出x上方有多少碟并将此碟放到开头 直接想其实就是一线段的区间更新,单点求值,但是根据题意我们可以这样想 首先我们倒着存 ...
- UVA 11610 Reverse Prime (数论+树状数组+二分,难题)
参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...
- UVA 11525 Permutation(树状数组)
题目意思是说 给你一个数k 然后有k个si 问你1--k 的第n个全排列是多少 注意是 1 2 3...k的全排列 不是si的 N= 由观察得知(k-i)!就是k-i个数字的全排列种数 ...
随机推荐
- C#高效率导出Excel
首先,需要引用excel的库: Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Exce ...
- Revit二次开发-根据Element获取系统族信息
Element element = doc.getElement(elementId); Autodesk.Revit.DB.Parameter familyType = element.get_Pa ...
- opencv 手写选择题阅卷 (二)字符识别
opencv 手写选择题阅卷 (二)字符识别 选择题基本上只需要识别ABCD和空五个内容,理论上应该识别率比较高的,识别代码参考了网上搜索的代码,因为参考的网址比较多,现在也弄不清是参考何处的代码了, ...
- 观察者模式(Observer)
观察者模式是经常使用到的一种设计模式,在我们的生活中也经常遇到,小到学校上学让同学帮忙看着老师有没有过来,在教室里做一些与学习无关的事情,大到股市里面我们遇到的,到股票涨到或者跌到一定程度的时候通知我 ...
- C语言 电梯函数
#include <stdio.h> #include <time.h> #include <stdlib.h> void test(){//汉字输出 printf ...
- unity 多线程
对于客户端来说,好的用户体验,需要保持一个快速响应的用户界面.于是便要求:网络请求.io操作等 开销比较大的操作必须在后台线程进行,从而避免主线程的ui卡顿.(注:协程也是主线程的一部分,进行大量的i ...
- Viewport Resizer下载 谷歌前端自适应开发工具
原文链接:http://www.phpbiji.cn/article/index/id/107/cid/6.html Viewport Resizer下载 谷歌前端自适应开发工具 在前端开发过程中,随 ...
- Unity3d 动态批处理的问题
这段时间做unity3d的优化,主要的入手是减少draw call. 1.代码上主要是把一些零碎的同材质的合并成一个大的mesh. 2.减少不必要的全屏后期处理.把摄像机的renderin ...
- windows7 64bit下安装Oracle 11g R2
Win7 bit64,安装的是64位的客户端. 1.PLSql连接数据库 (1)下载 instantclient-basic-win32-11.2.0.1.0.zip解压到Oracle要目当下 ...
- 1017. Queueing at Bank (25)
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...