A Simple Problem with Integers

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

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
/*
hdu 4267 线段树间隔更新
A Simple Problem with Integers 给你两个操作:
1.在[l,r]中(i-l)%k==0的数加上val
2.单点求值 看到题想到的是做过的一个间隔求和的题目,但是这题的k是不固定的
所以并不适用 对于每个数,如果用k的余数将它们标记,可以分成k组,所有k的情况总共55种,
所以用add[55]来保存新添加的值.
然后在查找pos的时候,加上对于每个k而言pos所属组的值即可 hhh-2016-03-26 13:47:26
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
int n,qw;
int k;
const int maxn = 50050;
int po[15][15];
int a[maxn];
struct node
{
int l,r;
int sum;
int add[56];
int mid()
{
return (l+r)>>1;
}
} tree[maxn*5]; void push_up(int i)
{ } void build(int l,int r,int i)
{
tree[i].l = l;
tree[i].r = r;
tree[i].sum = 0;
memset(tree[i].add,0,sizeof(tree[i].add));
if(l == r)
return ; int mid = tree[i].mid();
build(l,mid,lson);
build(mid+1,r,rson);
push_up(i);
} void push_down(int i)
{
if(tree[i].sum)
{
tree[lson].sum += tree[i].sum;
tree[rson].sum += tree[i].sum; for(int j = 0; j < 55; j++)
{
tree[lson].add[j]+= tree[i].add[j];
tree[rson].add[j]+= tree[i].add[j];
tree[i].add[j] = 0;
}
tree[i].sum = 0;
}
}
void Insert(int i,int l,int r,int val,int k,int t)
{
if(tree[i].l >= l && tree[i].r <=r )
{
tree[i].sum += val;
tree[i].add[po[k][t]] += val;
return ;
}
int mid = tree[i].mid();
push_down(i);
if(l <= mid)
Insert(lson,l,r,val,k,t);
if(r > mid)
Insert(rson,l,r,val,k,t);
push_up(i);
} int query(int i,int pos)
{
//if(tree[i].l >= l && tree[i].r <= r)
if(tree[i].l == tree[i].r)
{
int tmp = 0;
for(int j = 1;j <= 10;j++)
tmp += tree[i].add[po[j][pos%j]];
return tmp;
}
push_down(i);
int mid = tree[i].mid(); if(pos <= mid)
return query(lson,pos);
if(pos > mid)
return query(rson,pos);
} int main()
{
int T,cas = 1,cnt = 0;
for(int i = 1; i <= 10; i++)
{
for(int j = 0; j < i; j++)
po[i][j] = cnt++;
} while(scanf("%d",&n) != EOF)
{
for(int i = 1;i <= n;i++)
scanf("%d",&a[i]);
build(1,n,1); int l,r,q;
int val,k;
scanf("%d",&q);
for(int i = 1; i <=q; i++)
{
int op;
scanf("%d",&op);
if(op == 1)
{
scanf("%d%d%d%d",&l,&r,&k,&val);
Insert(1,l,r,val,k,l%k);
}
else
{
scanf("%d",&l);
printf("%d\n",query(1,l)+a[l]);
}
}
}
return 0;
}

  

hdu 4267 线段树间隔更新的更多相关文章

  1. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  2. hdu 1698 线段树 区间更新 区间求和

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. hdu 5023 线段树延迟更新+状态压缩

    /* 线段树延迟更新+状态压缩 */ #include<stdio.h> #define N 1100000 struct node { int x,y,yanchi,sum; }a[N* ...

  5. HDU 2795 线段树单点更新

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. hdu 1166 线段树单点更新

    等线段树复习完再做个总结 1101 2 3 4 5 6 7 8 9 10Query 1 3Add 3 6Query 2 7Sub 10 2Add 6 3Query 3 10End Case 1:633 ...

  7. HDU 3308 线段树单点更新+区间查找最长连续子序列

    LCIS                                                              Time Limit: 6000/2000 MS (Java/Oth ...

  8. HDU 4267 线段树 离散点区间更新, 自叶子节点至根单点查询

    题意: n个数字 下面n个数字表示数列 2个操作 1 [u, v]  k  add [u,v ]区间 (u点要计算)每隔k个位置,该数字+add 2 pos 询问 pos下标的值(下标从1开始) 思路 ...

  9. HDU(1698),线段树区间更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...

随机推荐

  1. Faster R-CNN 的 RPN 是啥子?

     Faster R-CNN,由两个模块组成: 第一个模块是深度全卷积网络 RPN,用于 region proposal; 第二个模块是Fast R-CNN检测器,它使用了RPN产生的region p ...

  2. c# 运算符:? ,??

    参考微软帮助 1  ?  空值条件运算符,用于在执行成员访问 (?.) 或索引 (?[) 操作之前,测试是否存在 NULL. // ? 空值条件运算符 string str = null; Conso ...

  3. 纯CSS垂直居中的四种解决方案

    总结了几种解决方法 但也不是说除了我说的就没有其他方法了 第一个.利用flex布局 代码: 效果: 第二个.利用transform 的 translate属性 代码: 效果: 第三个.使用伪类::af ...

  4. python之路--day13-模块

    1,什么是模块 模块就是系统功能的集合体,在python中,一个py文件就是一个模块, 例如:module.py 其中module叫做模块名 2,使用模块 2.1 import导入模块 首次带入模块发 ...

  5. django启动uwsgi报错

    查看uwsgi.log *** Starting uWSGI 2.0.17 (64bit) on [Thu Apr 5 17:46:15 2018] *** compiled with version ...

  6. appiun滑动的简单封装

    import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.test ...

  7. PHP模式设计之单例模式、工厂模式、注册树模式、适配器模式、观察者模式

    php模式设计之单例模式 什么是单例模式? 单例模式是指在整个应用中只有一个实例对象的设计模式 为什么要用单例模式? php经常要链接数据库,如果在一个项目中频繁建立连接数据库,会造成服务器资源的很大 ...

  8. SpringCloud的EurekaClient : 客户端应用访问注册的微服务(无断路器场景)

    演示客户端应用如何访问注册在EurekaServer里的微服务 一.概念和定义 采用Ribbon或Feign方式访问注册到EurekaServer中的微服务.1.Ribbon实现了客户端负载均衡,2. ...

  9. python网络爬虫与信息提取 学习笔记day1

    Day1: 安装python之后,为其配置requests第三方库,并爬取百度主页内容. 语句解释: r.status_code检测请求的状态码,如果状态码为200,则说明访问成功,否则,则说明访问失 ...

  10. Error loading MySQLdb module: No module named 'MySQLdb'----------- django成功连接mysql数据库的方法

    在进行django学习过程中,尝试使用框架连接mysql数据库,启动服务器的时候经常遇到Error loading MySQLdb module: No module named 'MySQLdb' ...