A Simple Problem with Integers

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4032    Accepted Submission(s): 1255

Problem Description
Let
A1, A2, ... , AN be N elements. You need to deal with two kinds of
operations. One type of operation is to add a given number to a few
numbers in a given interval. The other is to query the value 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 to answer all query operations.
 
Sample Input
4
1 1 1 1
14
2 1
2 2
2 3
2 4
1 2 3 1 2
2 1
2 2
2 3
2 4
1 1 4 2 1
2 1
2 2
2 3
2 4
 
Sample Output
1
1
1
1
1
3
3
1
2
3
4
1
 
(i-a)%k==0   即  i%k==a%k             分组   x%k==a%k的为一组,   参数 mod, k,x
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
using namespace std;
//#define local
typedef long long LL;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; int C[][][MS]; //C[mod][k][x]
int num[MS]; int lowbit(int x)
{
return x&(-x);
} // 修改区间,单点求职, 树状数组需要逆过来。 void updata(int mod,int k,int x,int d)
{
while(x>)
{
C[mod][k][x]+=d;
x-=lowbit(x);
}
} int getsum(int a,int x)
{
int res=;
while(x<MS) //x<=n
{
for(int k=;k<=;k++)
{
res+=C[a%k][k][x];
}
x+=lowbit(x);
}
return res;
} int main()
{
#ifdef local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // local
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d",&num[i]);
memset(C,,sizeof(C));
int m;
scanf("%d",&m);
while(m--)
{
int op,a,b,k,c;
scanf("%d",&op);
if(op==)
{
scanf("%d%d%d%d",&a,&b,&k,&c);
updata(a%k,k,b,c);
updata(a%k,k,a-,-c);
}
else
{
scanf("%d",&a);
int ans=getsum(a,a);
printf("%d\n",ans+num[a]);
}
}
}
return ;
}

A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267的更多相关文章

  1. POJ 3468 A Simple Problem with Integers(树状数组区间更新)

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

  2. POJ 3468 A Simple Problem with Integers(树状数组区间更新) 续

    这个题刚开始的时候是套模板的,并没有真的理解什么树状数组的区间更新,这几天想了一下,下面是总结: 区间更新这里引进了一个数组delta数组,delta[i]表示区间 [i, n] 的共同增量,每次你需 ...

  3. poj3468 A Simple Problem with Integers (树状数组做法)

    题目传送门 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 1 ...

  4. poj_3468: A Simple Problem with Integers (树状数组区间更新)

    题目是对一个数组,支持两种操作 操作C:对下标从a到b的每个元素,值增加c: 操作Q:对求下标从a到b的元素值之和. 这道题也可以用线段树解,本文不做描述,下面分析如何用树状数组来解决这道题. 先把问 ...

  5. HDU 4267 A Simple Problem with Integers(树状数组区间更新)

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

  6. POJ 3468 A Simple Problem with Integers 【树状数组】

    题目链接:id=3468">http://poj.org/problem?id=3468 题目大意:给出一组数组v[i],有两种操作,一种给出两个数a,b.要求输出v[a]到v[b]之 ...

  7. poj 3468: A Simple Problem with Integers (树状数组区间更新)

    题目链接: http://poj.org/problem?id=3468 题目是对一个数组,支持两种操作 操作C:对下标从a到b的每个元素,值增加c: 操作Q:对求下标从a到b的元素值之和. 这道题也 ...

  8. poj 3486 A Simple Problem with Integers(树状数组第三种模板改段求段)

    /* 树状数组第三种模板(改段求段)不解释! 不明白的点这里:here! */ #include<iostream> #include<cstring> #include< ...

  9. POJ 3468_A Simple Problem with Integers(树状数组)

    完全不知道该怎么用,看书稍微懂了点. 题意: 给定序列及操作,求区间和. 分析: 树状数组可以高效的求出连续一段元素之和或更新单个元素的值.但是无法高效的给某一个区间的所有元素同时加个值. 不能直接用 ...

随机推荐

  1. 使用aspose.word两句代码将word转换为pdf

    //Load Document Document document = new Document(@"C:\Users\Administrator\Desktop\人事---新员工转正总结( ...

  2. JavaScript神一样的变量系统

    话说上一篇介绍了JavaScript故事版的身世之谜.看官你估计也明白JavaScript出生之时,就未曾托于重任.布兰登-艾奇估计也没料到今天的JavaScript变得如此重要.要不然,当年他也不会 ...

  3. 关于request.getsession(true|false)

    request.getSession(true):若存在会话则返回该会话,否则新建一个会话.request.getSession(false):若存在会话则返回该会话,否则返回NULL

  4. gdb简单调试~core文件

    1.打开终端,进入项目目录,输入ulimit -a ,可以看core文件大小设置(第一行),若为0, 则没有打开core dump设置. 2.ulimit -c unlimited ,core文件大小 ...

  5. svn的搭建

    http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html

  6. extjs表格下的分页条——Ext.grid.Panel 的 pagingtoolbar

    两种分页条:每页固定条数的分页条 和 自定义选择每页内容条数的分页条 一.每页固定条数的分页条 这种样式的-- dockedItems: [{ xtype: 'pagingtoolbar', stor ...

  7. 分布式文件系统FastDFS设计原理

    原文地址: http://blog.chinaunix.net/uid-20196318-id-4058561.html FastDFS是一个开源的轻量级分布式文件系统,由跟踪服务器(tracker ...

  8. Flex利用titleIcon属性给Panel容器标题部添加一个ICON图标

    Flex利用titleIcon属性,给Panel容器标题部添加一个ICON图标. 让我们先来看一下Demo(可以右键View Source或点击这里察看源代码): 下面是完整代码(或点击这里察看): ...

  9. NameThreadForDebugging -- Naming threads for debugging

    http://forums.devart.com/viewtopic.php?t=16907 type tagTHREADNAME_INFO = record dwType : LongWord; / ...

  10. 手游产品经理初探(六)粗糙的logo会给产品致命一击

    假设你的游戏产品从logo的设计開始就不注重细节的话,那么你的产品将不会走多远! 我们把图片放大看: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1 ...