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. excel2003和excel2007文件的创建和读取

    excel2003和excel2007文件的创建和读取在项目中用的很多,首先我们要了解excel的常用组件和基本操作步骤. 常用组件如下所示: HSSFWorkbook excel的文档对象 HSSF ...

  2. JAVA_SE基础——61.字符串入门

    public class Demo1 { public static void main(String[] args) { String str1 = "hello"; Strin ...

  3. LeetCode & Q26-Remove Duplicates from Sorted Array-Easy

    Descriptions: Given a sorted array, remove the duplicates in place such that each element appear onl ...

  4. 爬虫模块BeautifulSoup

    中文文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html# 1.1      安装BeautifulSoup模块 ...

  5. es6学习笔记--Interator和Generator(以及for-of的用法)

    这几天学习了遍历器和生成器,看着资料学,有点雾里缭绕的感觉,让人忍不住放弃,还好多看了好几遍,怼着资料里的例子让自己学会了Interator和Generator.   Interator,中文简称:遍 ...

  6. unity3D 知识点随手记

    最近闲来无事,记记unity3D相关的一些知识点吧,也当作笔记存储.转载请标明出处:http://www.cnblogs.com/zblade/ 1.unity是如何调用Start/Awake等相关函 ...

  7. SpringCloud的Archaius - 动态管理属性配置

    参考链接:http://www.th7.cn/Program/java/201608/919853.shtml 一.Archaius是什么? Archaius用于动态管理属性配置文件. 参考自Gett ...

  8. js jquery 获取元素(父节点,子节点,兄弟节点),元素筛选

    转载:https://www.cnblogs.com/ooo0/p/6278102.html js jquery 获取元素(父节点,子节点,兄弟节点) 一,js 获取元素(父节点,子节点,兄弟节点) ...

  9. MySQL命令(逐步更新ing)

     启动mysql 开启: /etc/init.d/mysqld start关闭: /etc/init.d/mysqld stop重启: /etc/init.d/mysqld restart   查看m ...

  10. spring boot定制Jackson ObjectMapper,为什么不生效

    先说结论: 项目中定制了spring 的redisTemplate,而这个template没有使用我自定义的Jackson ObjectMapper.所以不生效. 下面是详细过程: 起因是spring ...