题意:

2种操作

1 a b k c 在区间[a,b]中的(i-a)%k==0的位置i上的数+c

2 a 查询位置a的值

输出每次查询的值

分析:

开始想到多维的线段树,但比较麻烦,看了题解才知道,用BIT实现区间更新,单点查询,若在区间[a,b]上的数加c

就在a位置加c ,b+1位置加-c 这样在查询时sum(i),(i>=a&&i<=b)就是当前i位置的值

维护多个BIT即可

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 50010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int bit[][][N],a[N],n,m;
int lowbit(int x){
return x&(-x);
}
void add(int i,int j,int x,int d){
while(x<=n){
bit[i][j][x]+=d;
x+=lowbit(x);
}
}
int sum(int i,int j,int x){
int num=;
while(x>){
num+=bit[i][j][x];
x-=lowbit(x);
}
return num;
}
int main()
{
while(~scanf("%d",&n)){
for(int i=;i<=n;++i)
scanf("%d",&a[i]);
scanf("%d",&m);
memset(bit,,sizeof(bit));
int s,e,k,c,op,pos;
while(m--){
scanf("%d",&op);
if(op==){
scanf("%d%d%d%d",&s,&e,&k,&c);
add(k,s%k,s,c);
add(k,s%k,e+,-c);
}
else if(op==){
scanf("%d",&pos);
int total=a[pos];
for(int i=;i<=;++i)
total+=sum(i,pos%i,pos);
printf("%d\n",total);
}
}
}
return ;
}

HDU 4267-A Simple Problem with Integers(多个BIT)的更多相关文章

  1. HDU 4267 A Simple Problem with Integers

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

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

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

  3. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

  4. HDU 4267 A Simple Problem with Integers --树状数组

    题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val  操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...

  5. HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)

    以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: &qu ...

  6. 【HDOJ】4267 A Simple Problem with Integers

    树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...

  7. HDOJ 4267 A Simple Problem with Integers (线段树)

    题目: Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...

  8. A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267

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

  9. HDU 4267 A Simple Problem with Integers 多个树状数组

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

  10. HDU 3468:A Simple Problem with Integers(线段树+延迟标记)

    A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...

随机推荐

  1. SDUT2241计算组合数C(n,m)(组合数)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2241 这个题的代码适应性也挺强,但这个题倒不适 ...

  2. selenium2 安装、简单使用及浏览器启动问题解决汇总

    一.selenium2 安装 1.安装jdk并配置环境变量 jdk需要1.6版本及以上的,这个从网上下载就可以,环境变量的配置前边的随笔整理过就不多说了. 2.安装Firefox,Selenium I ...

  3. 【转】Dr.com 5.20破解教程

    Dr.com 5.20破解教程 方法一  1.首先下载相关工具 Process Explorer(大家可以自行百度 一般绿色汉化版就可以)右键选择以管理员权限运行process的主程序 然后运行drc ...

  4. cojs 简单的区间问题 解题报告

    新学了些弦图和区间图的新玩意,于是就想着出一道题目 其实这道题不用弦图和区间图的理论也是可以做的 首先考虑第一问,第一问是一个NOIP普及组水平的贪心 我们把区间按照右端点从小到大排序,之后从头到尾扫 ...

  5. 对cost函数的概率解释

    Likehood函数即似然函数,是概率统计中经常用到的一种函数,其原理网上很容易找到,这里就不讲了.这篇博文主要讲解Likelihood对回归模型的Probabilistic interpretati ...

  6. 自旋锁spin_lock和raw_spin_lock

    自旋锁spin_lock和raw_spin_lock Linux内核spin_lock.spin_lock_irq 和 spin_lock_irqsave 分析 http://blog.csdn.ne ...

  7. python 时间处理(time和datetime介绍)

    python的有关时间的有哪几种呢?今天我们介绍两个:time和datetime time模块提供各种操作时间的函数 datetime模块定义了下面这几个类: datetime.date:表示日期的类 ...

  8. iOS iOS7越狱

    1.使用盘古越狱工具 (或者PP助手) 2.越狱成功后需要安装Apple File Conduit “2”,用于替代afc2add插件 3.安装AppSync插件 (绕过系统验证,随意安装.运行破解的 ...

  9. Struts2 Package

    package 元素的所有属性及对应功能: Attribute Required Description name yes key to for other packages to reference ...

  10. Django 大文件下载

    django提供文件下载时,若果文件较小,解决办法是先将要传送的内容全生成在内存中,然后再一次性传入Response对象中: def simple_file_download(request): # ...