A simple problem with integers
Time limit:5000/1500 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4032 Accepted Submission (s): 1255
Problem Descriptionlet A1, A2, ..., an is N elements. You need to deal with both kinds of operations. One type of operation is to add a given number to a few numbers in a given interval. The other are to query the value of some element.
Inputthere is a lot of test cases.
The first line contains an integer n. (1 <= N <= 50000)
The second line contains N numbers which is 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 the Ai which satisfies a <= I <= B and (i-a)% k = = 0. (1 <= a <= b <= N, 1 <= k <=, -1,000 <= c <= 1,000)
"2 A" means querying the value of Aa. (1 <= a <= N)
Outputfor Each test case, the output several lines to answer all query operations.
Sample INPUT4 1 1 1 1142 12 22 32 41 2 3 1 22 1 2 22 32 41 1 4 2 12 12 22 32 4
Sample Output111113312341 (i-a)%k==0 is a group of i%k==a%k grouping x%k==a%k, parameter mod, k,x
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <Set>7#include <map>8#include <string>9#include <vector>Ten#include <queue> One#include <stack> A#include <iomanip> -#include <sstream> - using namespacestd; the //#define LOCAL -typedefLong LongLL; - Const intinf=0x4fffffff; - Const intexp=1e-5; + Const intms=50005; - + intc[ One][ One][MS];//C[mod][k][x] A intNum[ms]; at - intLowbit (intx) - { - returnx& (-x); - } - in //Modify the interval, a single point of employment, the tree array needs to reverse over. - to voidUpdata (intMoDintKintXintd) + { - while(x>0) the { *c[mod][k][x]+=D; $x-=lowbit (x);Panax Notoginseng } - } the + intGetsum (intAintx) A { the intres=0; + while(X<MS)//x<=n - { $ for(intk=1; k<=Ten; k++) $ { -res+=c[a%K] K [x]; - } thex+=lowbit (x); - }Wuyi returnRes; the } - Wu intMain () - { About #ifdef Local $Freopen ("In.txt","R", stdin); -Freopen ("OUT.txt","W", stdout); - #endif //Local - intN; A while(SCANF ("%d", &n)! =EOF) + { the for(intI=1; i<=n;i++) -scanf"%d",&num[i]); $memset (C,0,sizeof(C)); the intm; thescanf"%d",&m); the while(m--) the { - intop,a,b,k,c; inscanf"%d",&op); the if(op==1) the { Aboutscanf"%d%d%d%d",&a,&b,&k,&c); theUpdata (a%k,k,b,c); theUpdata (a%k,k,a-1,-c); the } + Else - { thescanf"%d",&a);Bayi intans=getsum (a,a); theprintf"%d\n", ans+Num[a]); the } - } - } the return 0; the}
A simple problem with integers multi-tree array segmentation, interval modification, single point of employment. HDU 4267