hdu 4267 A Simple Problem with Integers(分类别维护多个树状数组)

原创 2013年12月04日 12:38:42

Let A1, A2, ... , AN be N elements. Youneed to deal with two kinds of operations. One type of operation is to add agiven number to a few numbers in a given interval. The other is to query thevalue of some element.

Input

There are a lot of test cases.
The first line contains an integer N. (1 <= N <= 50000)
The second line contains N numbers which are the initial values of A1, A2, ..., AN. (-10,000,000 <= the initial value of Ai <= 10,000,000)
The third line contains an integer Q. (1 <= Q <= 50000)
Each of the following Q lines represents an operation.
"1 a b k c" means adding c to each of Ai which satisfies a <= i<= b and (i - a) % k == 0. (1 <= a <= b <= N, 1 <= k <= 10,-1,000 <= c <= 1,000)
"2 a" means querying the value of Aa. (1 <= a <= N)

Output

For each test case, output several lines toanswer all query operations.

 

对数组分类,建立多个树状数组,分别保存不同类别修改的不同被别数的数值

const int MAXN = 1000000;
int s[11][11][50005];
int a[50005];
int n;
int lowbit(int x)
{
   return x & (-x);
}
int add(int a, int b, int i, int v)
{
   while (i <= n)
    {
       s[a][b][i] += v;
       i += lowbit(i);
    }
}
int sum(int a, int b, int i)
{
   int ret = 0;
   while (i > 0)
    {
       ret += s[a][b][i];
       i -= lowbit(i);
    }
   return ret;
}
 
int main ()
{
   int T;
   int op, aa, bb, v, k;
   while (RI(n) != EOF)
    {
       FE(i, 1, n) RI(a[i]);
       CLR(s, 0);
       int m;
       RI(m);
       while (m--)
       {
           RI(op);
           if (op == 1)
           {
                RIV(aa, bb, k, v);
                add(k, aa % k, aa, v);
               add(k, aa % k, (bb + 1),-v);
           }
           else
           {
                RI(aa);
                int ans = a[aa];
                FE(i, 1, 10) ans += sum(i, aa %i, aa);
                cout << ans <<endl;
           }
       }
    }
   return 0;
}


相关文章推荐

hdu 4267 A Simple Problem with Integers 线段树&树状数组

A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K...

HDU 4267 A Simple Problem with Integers 数列离散化 + 树状数组

题意:对一个长度为n(n          1:给定a,b,k,c四个整数,在[a , b] 区间满足a          2:给定整数a,求当前A[a]; 题解:想办法把间隔的数字搞到一起,...

HDU4267 A Simple Problem with Integers(树状数组)

HDU4267 A Simple Problem with Integers(树状数组) 分析:对于一个特定的k,它有可能有0到k-1 共k个余数.我们对于每条1 a b k c 命令 我们只需要再那...

HDU 4267 A Simple Problem with Integers(树状数组)

A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 ...

hdu 4267 A Simple Problem with Integers 树状数组

题目 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4267 题目来源:2016.2.26群赛 简要题意:询问某数为多少,对[l...

[POJ 2368 A Simple Problem with Integers] 树状数组区间修改、区间查询

[POJ 2368 A Simple Problem with Integers] 树状数组区间修改、区间查询知识点:data structure binary index tree1. 题目链接[P...

POJ3468 A Simple Problem with Integers 线段树|树状数组BIT(区间增减,求和)

A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Subm...

【树状数组】 HDOJ 4276 A Simple Problem with Integers

用树状数组记录所有的k的所有的yu

[POJ 3468]A Simple Problem with Integers[树状数组区间更新+求和]

题目链接:[POJ 3468]A Simple Problem with Integers[树状数组区间更新+求和] 题意分析: 对特定的连续区间进行更新值并求出特定区间的和。 解题思路: 使用树状数...

POJ 3468 A Simple Problem with Integers 树状数组 区间修改 区间查询

题目链接点这儿 给你一个数列,
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hdu 4267 A Simple Problem with Integers(分类别维护多个树状数组)
举报原因:
原因补充:

(最多只允许输入30个字)