LA2191:Potentiometers(树状数组)
来源:互联网 发布:excel数据求和怎么用 编辑:程序博客网 时间:2024/04/28 19:41
题意:
先给出一个数组,然后有两个操作
S x y 把第x个数改成y
M x y计算x~y个数的和
思路:
普通的树状数组,但不知道为什么会莫名其妙的一直WA
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <bitset>#include <algorithm>#include <climits>using namespace std;#define LS 2*i#define RS 2*i+1#define UP(i,x,y) for(i=x;i<=y;i++)#define DOWN(i,x,y) for(i=x;i>=y;i--)#define MEM(a,x) memset(a,x,sizeof(a))#define W(a) while(a)#define gcd(a,b) __gcd(a,b)#define LL long long#define N 5000005#define MOD 1000000007#define INF 0x3f3f3f3f#define EXP 1e-8#define lowbit(x) (x&-x)LL c[N];int a[N],n;LL sum(int x){ LL ret = 0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret;}void add(int x,int d){ while(x<=n) { c[x]+=d; x+=lowbit(x); }}int main(){ int i,j,k,x,y,cas = 1; char str[10]; scanf("%d",&n); while(n) { printf("Case %d:\n",cas++); for(i = 1; i<=n; i++) { scanf("%d",&a[i]); } MEM(c,0); for(i = 1;i<=n;i++) { add(i,a[i]); } while(1) { scanf("%s",str); if(!strcmp(str,"END")) break; if(str[0]=='M') { scanf("%d%d",&x,&y); LL ans = sum(y)-sum(x-1); printf("%lld\n",ans); } else if(str[0]=='S') { scanf("%d%d",&x,&y); add(x,y-a[x]); a[x] = y; } } scanf("%d",&n); if(n) printf("\n"); } return 0;}
0 0
- LA2191:Potentiometers(树状数组)
- LA2191&UVA12086树状数组
- UVA 12086 - Potentiometers(树状数组)
- uva 12086 - Potentiometers(树状数组)
- uva 12086 - Potentiometers (树状数组)
- uva 12086 - Potentiometers--树状数组
- UVA 12086 - Potentiometers(树状数组)
- UVA 12086 Potentiometers(树状数组)
- (考前水题)LA2191 裸树状数组
- uva 12086 - Potentiometers(树状数组)
- UVa 12086 Potentiometers (树状数组&点修改)
- UVa12086 - Potentiometers(树状数组即Fenwick树)
- UVALive 2191 - Potentiometers (树状数组)
- UVA 12086 Potentiometers(树状数组|| 线段树单点更新)
- UVa 12086 Potentiometers 树状数组裸题 单点更新 区间查询
- 树状数组
- 树状数组
- 树状数组
- TCP预先派生子进程服务程序,accept无上锁保护
- 渣渣ACM日记——240-小明的调查统计(二)(NYOJ)
- 佛学大师智慧(1)
- C++double转化为string
- 习题3-32
- LA2191:Potentiometers(树状数组)
- 微信开发
- 新开的博客,希望认识更多的朋友
- IntelliJ IDEA使用技巧
- Decorator Pattern 装饰者模式(二)
- openwrt通过network文件配置多个VLAN
- 200年之内富人将有机会享受“长生不老”
- 《现代操作系统》读书笔记之——进程调度(一)
- Android与web服务器数据交互编程---2-如何实现手机与web的通信---server实现