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. 201621123043 《Java程序设计》第7周学习总结

    1. 本周学习总结 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最重要的几个关键词. 事件:用户的操作. 事件源:产生事件的组件. 事件监听程序:对事件进行处理的操作所引发的相关 ...

  2. DML数据操作语言之复杂查询

    1.视图(View) 我们知道,在关系型数据库中,用来保存实际数据记录的是数据表.和表同等概念也是用来保存东西是:视图. 但是数据表是用来保存实际数据记录的,而视图是用来保存常用select语句的. ...

  3. python之路--day15--常用模块之logging模块

    常用模块 1 logging模块 日志级别:Noset (不设置) Debug---(调试信息)----也可用10表示 Info--(消息信息)----也可用20表示 Warning---(警告信息) ...

  4. 【bug清除】新Surface Pro使用OneNote出现毛刺现象的解决方案

    在写字的时候,左手触摸Surface的金属外壳背面,大概两个手指指肚大小.问题亲测可以得到解决. 推测是设备使用时接地没有做好,导致电磁笔出现偏移.问题初步锁定在新笔的倾斜感应上. 参考资料: htt ...

  5. JAVA_SE基础——45.基本类型变量.值交换[独家深入解析]

    需求:定义一个函数交换两个基本类型变量的值. 相信看过我前面的文章的同学都应该看的懂我以下的代码: class Demo2 { public static void main(String[] arg ...

  6. JAVA_SE基础——31.this关键字

    黑马程序员入学blog... 也算是学习笔记体会. this的通俗解释: 有一个A类,一个B方法,一个C变量,其中B和C都在类A中 this.B()就是调用A类中的B方法 this.C=1(假设C是一 ...

  7. http缓存浅谈

    我们在访问百度首页的时候,会发现不管怎么刷新页面,静态资源基本都是返回 200(from cache): 随便点开一个静态资源是酱的: 哎哟有Response报头数据呢,看来服务器也正常返回了etag ...

  8. Tess4J OCR简单使用教程

    Tess4J简介 Tesseract-OCR支持中文识别,并且开源和提供全套的训练工具,是快速低成本开发的首选.而Tess4J则是Tesseract在Java PC上的应用.在英文和数字识别中性能还是 ...

  9. IDEA里面创建maven项目,依赖

    在IDEA里面创建一个简单的Maven项目: 在file-->new-->project ,选择maven,点击next 里面的一些简单参数的定义(第一次使用的话可以使用默认的值进行后面的 ...

  10. apache修改最大连接数报错

    报错的内容: AH00180: WARNING: MaxRequestWorkers of 2500 exceeds ServerLimit value of 256 servers, decreas ...