Fenwick

 

Potentiometers

 UVALive - 2191 

题意:两种操作,一是把第x个数改成y,而是求x到y的和。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int maxn=200010;
 5 int a[maxn],c[maxn];
 6 int n;
 7 int lowbit(int x){
 8     return x&(-x);
 9 }
10 
11 void add(int x,int d){
12     while(x<=n){
13         c[x]+=d;
14         x+=lowbit(x);
15     }
16 }
17 
18 ll sum(int x){
19     ll ans=0;
20     while(x>0){
21         ans+=c[x];
22         x-=lowbit(x);
23     }
24     return ans;
25 }
26 
27 int main(){
28     int kase=0;
29     while(scanf("%d",&n)&&n){
30         memset(c,0,sizeof(c));
31         for(int i=1;i<=n;i++) {
32             scanf("%d",&a[i]);
33             add(i,a[i]);                   //for(int j=i-lowbit(i)+1;j<=i;j++) c[i]+=a[j];
34         }
35         if(kase) puts("");
36         printf("Case %d:\n",++kase);
37         char s[5];
38         int x,y;
39         while(scanf("%s",s)){
40             if(strcmp(s,"END")==0) break;;
41             scanf("%d%d",&x,&y);
42             if(s[0]=='S'){
43                 int d=y-a[x];
44                 add(x,d);
45                 a[x]=y;  //!!!
46             }else{
47                 printf("%lld\n",sum(y)-sum(x-1));
48             }
49         }
50     }
51     return 0;
52 }
View Code

 

Rabbit Kingdom

 HDU - 4777 

题意:给N个数,有M个查询,问区间[L,R]之间有多少个数与这个区间内的其他数都互质。

待补题~~

 

Magic Ball Game

 HDU - 4605

题意:一个权值为X球从根节点开始下落,每落到一个节点的时候,1.如果X=W[i],或者没有儿子节点了,球停止下落。2.如果X<W[i],球各有1/2的概率落到左右儿子节点。3.如果X>W[i],球有1/8的概率落到左儿子,有7/8的概率落到右儿子。问球落到点v的概率是多少(概率用7^x/2^y表示,即输出x和y就可以)。

待补题~~

posted @ 2017-08-01 14:37  yijiull  阅读(202)  评论(0编辑  收藏  举报