A Simple Problem with Integers
time limit per test 1.5 second memory limit per test 256 megabytes
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.

传送门:HDU4267

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
2
3
4
5
6
7
8
9
10
11
12
1
1
1
1
1
3
3
1
2
3
4
1

题解

题意:满足 a<=i<=b 且(i-a)%k==0 的i加上c 区间更新最后单点查询 注意一个非常重要的条件(i-a)%k==0 -> i%k==a%k 那么更新的每个点的性质就很清楚了 就是%k的余数 而k的范围又只有1-10 而又是单点查询 只要一个lazy数组就够了 所以开55个延迟标记表示模k的余数(单点查询时需要用到这55个中的10个) 考虑用线段树或树状数组做 但这题内存卡得有点僵 线段树各种MLE 学习一波树状数组
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.io.*;  
import java.util.*;
public class Main {
static int[]shu=new int[50050];
public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
while(sc.hasNext()){
int n=sc.nextInt();
for(int i=1;i<=n;i++)shu[i]=sc.nextInt();
//SegTree[] tree=new SegTree[55]; 超内存
//Bit[]bit=new Bit[55]; 超内存
//for(int i=0;i<55;i++)bit[i]=new Bit(); 超内存
Bit bit=new Bit();
int q=sc.nextInt();
for(int i=1;i<=q;i++){
int z=sc.nextInt();
if(z==1){
int a=sc.nextInt();
int b=sc.nextInt();
int k=sc.nextInt();
int c=sc.nextInt();
//tree.regupdate(a, b+1, c, index(k,a%k));
//bit[index(k,a%k)].update(a, b, c);
bit.update(a, b, c, index(k,a%k));
}else{
int a=sc.nextInt();
int sum=0;
for(int k=1;k<=10;k++){
sum+=bit.sum(a, index(k,a%k));
//sum+=tree[index(k,a%k)].regquery(a, a+1);
//sum+=bit[index(k,a%k)].sum(a);
}
pw.println(sum+shu[a]);
}
}
pw.flush();
}

}
static int index(int k,int mod){
return k*(k-1)/2+mod;
}
}
class Bit{
static int MAXN=50050;
static int arr[][]=new int[MAXN][55];//不static超内存
Bit(){
for(int i=0;i<50050;i++){
for(int j=0;j<55;j++){
arr[i][j]=0;
}
}
}
int lowbit(int v){return v&-v;}
int sum(int x,int bj){int res=0;while(x!=0){res+=arr[x][bj];x-=lowbit(x);}return res;} //单点查询
void add(int x,int n,int bj){while(x<MAXN){arr[x][bj]+=n;x+=lowbit(x);}}
void update(int x,int y,int n,int bj){add(x,n,bj);add(y+1,-n,bj);} //区间查询

}
/*class SegTree{
//long[]tree=new long[200050];
int[]lazy=new int[200050];
int n;
SegTree(int n_){
this.n=1;
while(n<n_){
n*=2;
}
}
int index(int k,int mod){
return k*(k-1)/2+mod;
}
void pushdown(int num,int l,int r){
if(lazy[num]!=0){
lazy[num*2+1]+=lazy[num];
lazy[num*2+2]+=lazy[num];
lazy[num]=0;
}
}
void update(int num,int l,int r,long add,int x,int y){
if(r<=x||l>=y)return;
if(l<=x&&r>=y){
lazy[num]+=add;
return;
}
pushdown(num,x,y);
update(num*2+1,l,r,add,x,(x+y)/2);
update(num*2+2,l,r,add,(x+y)/2,y);
}
void regupdate(int l,int r,int add){
update(0,l,r,add,0,n);
}
long regquery(int l,int r){
return query(0,l,r,0,n);
}
long query(int num,int l,int r,int x,int y){
if(r<=x||l>=y)return 0;
if(l<=x&&r>=y){
return lazy[num];
}
pushdown(num,x,y);
long left=query(num*2+1,l,r,x,(x+y)/2);
long right=query(num*2+2,l,r,(x+y)/2,y);
if(left!=0)return left;
else return right;
}
}*/