HDU 4456 Crowd

Source: Internet
Author: User

Crowd

Time limit:5000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1287 Accepted Submission (s): 290


problem DescriptionCity F in the southern, preparing Lanterns festival celebration along the streets to celebrate.
Since frequent accidents had happened last year when the citizens went off to admire the colorful lanterns, City F is plan Ning to develop a system to calculate the degree of congestion of the intersection of streets.
The map of City F is organized in an nxn grid (n North-south streets and N West-east Street). For each intersection of streets, we define a density value for the crowd on the intersection.
Initially, the density value of every intersection is zero. As time goes by, the density values could change frequently. A set of cameras with new graphical recognition technology can calculate the density value of the intersection easily in a Short time.
But the administrator of the Police Office was planning to develop a system to calculate the degree of congestion. For some consideration, they come up with a conception called "k-dimension congestion degree". The "K-dimension congestion degree" of intersection (X0,Y0) is represented as "C (x0,y0,k)", and it can are calculated by th E Formula below:

Here, d (x, Y) stands for the density value on intersection (x, y) and (x, y) must is in the NxN grid. The formula means that all the intersections in the range of Manhattan distance K from (x0,y0) effect the K-dimension Cong Estion degree of (x0,y0) Equally, so we just simply sum them up to get the k-dimension congestion degree of (X0,Y0).
The figure below shows a 7x7 grid, and it shows so if you want to get the 2-dimension congestion degree of intersection (4,2), you should sum up the density values of all marked intersections.

InputThese is multiple test cases.
Each of the test case begins with a line with the integers N, M, meaning, "the city was an nxn grid and there would be M queries or events as time goes by. (1≤n≤10 000, 1≤m≤80 000) Then M lines follow. Each line indicates a query or an event which are given in form of (p, x, Y, z), here P = 1 or 2, 1≤x≤n, 1≤y≤n.
The meaning of different p is shown below.
1. P = 1 The value of D (x, y) is increased by Z, here-100≤z≤100.
2. P = 2 Query the value of C (x, Y, z), here 0≤z≤2n-1.
Input is terminated by n=0.

OutputFor each query, output the value for C (x, Y, z) in a line.

Sample Input8 51 8 8 11 1 1-22 5 5 61 5 5 32 2 3 93 21 3 2-92 3 2 00

Sample Output11-9

SourceHangzhou Regional Contest Problem solving: The next door old Wang said to me, this Manhattan distance AH covered area rotated 45 degrees is a rectangular area, since it is a rectangular area, the range is so large, in fact, can be more large, just memory really stingy ... Come on, CDQ.
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const intMAXN =200010;5 structQU {6     intx1,x2,y,id,f;7QU (intA =0,intb =0,intc =0,intD =0,intE =0) {8X1 =A;9x2 =b;Teny =C; OneID =D; Af =e; -     } -     BOOL operator< (ConstQU &t)Const { the         returnY <T.y; -     } - } Q[MAXN],A[MAXN],B[MAXN]; - LL C[MAXN],ANS[MAXN]; + voidAddintIintval) { -      while(I <MAXN) { +C[i] + =Val; Ai + = i&-i; at     } - } -LL sum (intI,LL ret =0) { -      while(I >0) { -RET + =C[i]; -I-= i&-i; in     } -     returnret; to } + voidCdqintLintR) { -     if(R <= L)return; the     intMid = (L + R) >>1; * CDQ (l,mid); $CDQ (mid+1, R);Panax Notoginseng     intA =0, B =0, j =0; -      for(inti = L; I <= mid; ++i) the         if(Q[i].id = =-1) a[a++] =Q[i]; +      for(inti = mid +1; I <= R; ++i) A         if(Q[i].id! =-1) b[b++] =Q[i]; theSort (A,a +a); +Sort (b,b +b); -      for(inti =0; I < b; ++i) { $          for(; J < a && a[j].y <= b[i].y; + +)j) Add (A[J].X1,A[J].F); $Ans[b[i].id] + = b[i].f*sum (b[i].x2); -Ans[b[i].id]-= b[i].f*sum (b[i].x1); -     } the      for(inti =0; I < J; ++i) Add (a[i].x1,-a[i].f); - }Wuyi intMain () { the     intN,m,op,x,y,z,tot,ask; -      while(SCANF ("%d",&N), N) { Wuscanf"%d",&m); -ask = Tot =0; Aboutmemset (ans,0,sizeofans); $          while(m--) { -scanf"%d%d%d%d",&op,&x,&y,&z); -             if(OP = =1) q[tot++] = QU (x + y,0, y-x,-1, z); -             Else { A                 intCX = x +y; +                 intcy = y-x; the                 intX1 = CX-Z; -                 intx2 = cx +Z; $                 inty1 = cy-Z; the                 inty2 = cy +Z; theq[tot++] = QU (x1-1, X2,y2,ask,1); theq[tot++] = QU (x1-1, x2,y1-1, ask++,-1); the             } -         } inCdq0, tot-1); the          for(inti =0; i < ask; ++i) theprintf"%i64d\n", Ans[i]); About     } the     return 0; the}
View Code

HDU 4456 Crowd

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.