Link: HDU 4267 a simple problem with Integers
Similar to the question: HDU 1556 color the ball technique for querying segment update points in a tree array.
Because the segment Update Is Not consecutive, multiple tree Arrays can be constructed. Because $ k \ in [] $, update can be divided into the following types:
1, 2, 3, 4, 5...
-------------
1, 3, 5, 7, 9...
2, 4, 6, 8, 10...
-------------
1, 4, 7, 10, 13...
2, 5, 8, 11, 14...
3, 6, 9, 12, 15...
-------------
...
A total of 55 tree arrays. For each update, the corresponding tree array is updated accordingly.
During the query, you can also find a tree array that matches the query type and add the initial value.
The Code is as follows:
1 #include <cstdlib> 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #define MAXN 50005 6 using namespace std; 7 int bit[12][12][MAXN]; 8 int arr[MAXN]; 9 int N;10 int lowbit(int x)11 {12 return x&(-x);13 }14 int query(int a, int b, int l)15 {16 int sum = 0; 17 while( l > 0 )18 {19 sum += bit[a][b][l];20 l -= lowbit(l);21 }22 return sum;23 }24 void add(int a, int b, int l, int x)25 {26 while( l <= N )27 {28 bit[a][b][l] += x;29 l += lowbit(l);30 }31 }32 int main(int argc, char *argv[])33 {34 while(scanf("%d", &N)!= EOF)35 {36 memset(bit, 0, sizeof(bit));37 for( int i = 1 ; i <= N ; i++ )38 {39 scanf("%d", &arr[i]);40 }41 int Q;42 scanf("%d", &Q);43 for( int i = 0 ; i < Q ; i++ )44 {45 int ty;46 scanf("%d", &ty);47 if( ty == 1 )48 {49 int a, b, k, c;50 scanf("%d%d%d%d", &a, &b, &k, &c);51 add(k, a%k, a, c);52 add(k, a%k, b+1, -c);53 }54 if( ty == 2 )55 {56 int l;57 scanf("%d", &l);58 int ans = arr[l];59 for( int i = 1 ; i <= 10 ; i++ )60 {61 ans += query(i, l%i, l);62 }63 printf ( "%d\n", ans ); 64 }65 }66 }67 return 0;68 }
HDU 4267 a simple problem with Integers