HDU4267 tree-like array with discontinuous interval modification

Source: Internet
Author: User

A simple problem with integers

Time limit:5000/1500 MS (java/others) Memory limit:32768/32768 K (java/others)


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

Source2012 ACM/ICPC Asia Regional Changchun Online test instructions: Puzzle: Interval modification of tree arrays, single-point query, notice the discontinuous interval modification here
///1085422276#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<cmath>#include<map>#include<bitset>#include<Set>#include<vector>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#defineMeminf (a) memset (A,127,sizeof (a));#defineTS printf ("111111\n");#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (a) scanf ("%d", &a)#defineG 9.8#defineMoD 100000000#defineEPS 0.0000001#defineMAXN 50000+1inline ll read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//****************************************intc[maxn][ One][ One],s[maxn],n;intLowbit (intx) {returnx& (-x);}voidUpdateintAintBintXintv) {     while(x<=N) {c[x][a][b]+=v; X+=lowbit (x); }}int Get(intXinta) {    intsum=0;  while(x>0) {for (I,1,Ten) Sum+=c[x][i][a%i]; X-=lowbit (x); }    returnsum;}intMain () { while(READ (n)! =EOF)        {mem (c); For (I,1, N) {scanf ("%d",&S[i]); }        intq=read (); intT,a,b,k,add; For (I,1, Q) {scanf ("%d",&t); if(t==1) {scanf ("%d%d%d%d",&a,&b,&k,&add); Update (K,a%K,a,add); Update (K,a%k,b+1,-add); }            Else{scanf ("%d",&a); printf ("%d\n",Get(a,a) +S[a]); }       }    }    return 0;}
Code

HDU4267 tree-like array with discontinuous interval modification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.