首页 > 其他 > 详细

UVa 12086 Potentiometers 树状数组裸题 单点更新 区间查询

时间:2014-03-29 02:40:15      阅读:427      评论:0      收藏:0      [点我收藏+]

题意:单点更新,区间查询

树状数组裸题:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define ll int
#define N 200010
int tree[N], maxn;
int lowbit(int x){return x&(-x);}
int sum(int x){
	int ans = 0;
	while(x>=1){ans+=tree[x]; x-=lowbit(x);}
	return ans;
}
void change(int x, int val){
	while(x <= maxn)
	{tree[x] += val; x+=lowbit(x);}
}
char s[3];
ll num[N];
int main(){
	ll n, u, v, Cas = 1;
	while(scanf("%d",&n),n){
		memset(tree, 0, sizeof(tree));maxn = n;
		for(int i = 1; i <= n; i++){scanf("%d",&num[i]); change(i, num[i]);}
		
		if(Cas>1)puts("");
		printf("Case %d:\n", Cas++);
		while(1){
			scanf("%s",s); if(s[0]==‘E‘)break; scanf("%d %d",&u,&v);
			if(s[0]==‘S‘){
				change(u, -num[u]);
				change(u, v);
				num[u] = v;
			}
			else printf("%d\n", sum(v)-sum(u-1));
		}		
	}
	return 0;
}


UVa 12086 Potentiometers 树状数组裸题 单点更新 区间查询,布布扣,bubuko.com

UVa 12086 Potentiometers 树状数组裸题 单点更新 区间查询

原文:http://blog.csdn.net/acmmmm/article/details/22428125

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!