zoukankan      html  css  js  c++  java
  • HDU 4267 A Simple Problem with Integers [树状数组]

      根据%k=a中a和k的不同组合建立55棵树状数组,每次修改操作只对其中1棵树状数组进行操作,每次查询对其中10棵树状数组统计增量和。

     1 #include <string.h>
     2 #include <stdio.h>
     3 #define MAXN 50005
     4 int n,q,x[MAXN];
     5 int ta,tb,cc,k,op;
     6 int c[55][MAXN];
     7 inline void update(int *c,int x,int d){while(x<=n)c[x]+=d,x+=x&-x;}
     8 inline int query(int *c,int x){int ret=0;while(x)ret+=c[x],x-=x&-x;return ret;}
     9 int main(){
    10     while(scanf("%d",&n)!=EOF){
    11         for(int i=1;i<=n;i++)scanf("%d",&x[i]);
    12         for(int i=0;i<55;i++)memset(c[i],0,4*n+4);
    13         scanf("%d",&q);
    14         while(q--){
    15             scanf("%d",&op);
    16             if(op==1){
    17                 scanf("%d%d%d%d",&ta,&tb,&k,&cc);
    18                 update(c[(k*(k-1)>>1)+ta%k],ta,cc);
    19                 update(c[(k*(k-1)>>1)+ta%k],tb+1,-cc);
    20             }else{
    21                 scanf("%d",&cc);
    22                 int ans=0;
    23                 for(int i=1;i<=10;i++)ans+=query(c[(i*(i-1)>>1)+cc%i],cc);
    24                 printf("%d\n",x[cc]+ans);
    25             }
    26         }
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    台州 OJ 3847 Mowing the Lawn 线性DP 单调队列
    洛谷 OJ P1417 烹调方案 01背包
    快速幂取模
    台州 OJ 2649 More is better 并查集
    UVa 1640
    UVa 11971
    UVa 10900
    UVa 11346
    UVa 10288
    UVa 1639
  • 原文地址:https://www.cnblogs.com/swm8023/p/2679404.html
Copyright © 2011-2022 走看看