BZOJ1227 [SDOI2009] devout tomb master "tree-shaped Array"

Source: Internet
Author: User

Topic

Little W is the manager of a newly built cemetery. A cemetery can be seen as a nxm rectangle, each square of a rectangle, planted with an evergreen tree, or a graveyard that has not yet belonged. The local residents are very devout Christians who are willing to find a suitable cemetery for themselves in advance. In order to reflect their sincerity to the Lord, they hope that their graves have a higher degree of piety. The piety of a cemetery refers to the number of crosses centered on this cemetery. A cross can be seen as a graveyard in the middle, the upper and lower of the cemetery, the right and left, and there are exactly k evergreen trees. Little W would like to know what the total devotion of all the cemeteries in the cemetery he managed

Input format

The first line contains two positive integers separated by spaces N and M, representing the width and length of the cemetery, so this rectangular cemetery has a total of (n+1) x (m+1) points, the lower left corner coordinates (0, 0), and the upper-right corner coordinates (N, M). The second line contains a positive integer w, representing the number of evergreen trees in the cemetery. The third line has a total of w lines, each containing two non-negative integers, separated by spaces, Xi and Yi, representing the coordinates of an evergreen tree. The input guarantees that no two evergreen trees have the same coordinates. The last line contains a positive integer k, meaning as shown in the title.

Output format

Contains a non-negative integer that represents the total devotion of all cemeteries in this cemetery. For the sake of convenience, the answer to 2,147,483,648 modulo.

Input sample

5 6

13

0 2

0 3

1 2

1 3

2 0

2 1

2 4

2 5

2 6

3 2

3 3

4 3

5 2

2

Output sample

6

Tips

In the figure, there are 3 crosses in the center of the cemetery (2, 2) and (2, 3), that is, their piety is 3. Other cemeteries have a 0 degree of piety.

All data meet 1≤n, m≤1,000,000,000,0≤xi≤n,0≤yi≤m,1≤w≤100,000, 1≤k≤10. There are 50% of data that meet 1≤k≤2. There are 25% of data that meet 1≤w≤10000.

Note: "There is just a K-tree", here is not exactly there and only, but from the >=k tree exactly choose K Tree

Exercises

The modulus in the title is equal to \ (2^31\), so an int natural overflow is equivalent to modulo
We remember a point up and down the number of trees is U, D, L, R, then each point contribution is \ (c_{u}^{k} * c_{d}^{k} * c_{l}^{k} * c_{r}^{k}\)
The range of points is large and we scatter them to within 100000
But a total of \ (w^2\) points, can not directly calculate, but the tree only \ (w\) , consider starting from the tree
After we have sorted all the trees, for the points between the two trees with the same horizontal axis, the \ (c_{u}^{k} * c_{d}^{k}\) in the equation is the same
We use the tree-like array maintenance \ (c_{l}^{k} * c_{r}^{k}\), we can speed up the operation of the

#include <iostream>#include <cstdio>#include <algorithm>#define LBT (x) (x & x)using namespaceStdConst intMAXN =100005, MAXM =100005, INF =1000000000;inline intRead () {intout =0, flag =1;Charc = GetChar (); while(C < -|| C > $) {if(c = ='-') flag =-1; c = GetChar ();} while(c >= -&& C <= $) {out = (out <<3) + (out <<1) + C-' 0 '; c = GetChar ();}returnOut * FLAG;}ints[maxn],c[maxn][ One],b[maxn],tot,n,k;intU[MAXN],D[MAXN],L[MAXN],R[MAXN],V[MAXN];structpoint{intx, y;} P[MAXN];intGETN (intx) {returnLower_bound (b +1, B +1+ tot,x)-B;}inline BOOL operator< (Constpoint& A,Constpoint& b) {returna.x = = b.x? A.y < b.y:a.x < b.x;}voidAddintUintV) { while(U <= tot) s[u] + = V,u + LBT (u);}voidMusintUintV) { while(U <= tot) s[u] = v,u + LBT (u);}intQueryintu) {intAns =0; while(u) ans + = s[u],u-= LBT (U);returnAns;}intSumintLintR) {returnQuery (r)-Query (L-1);}voidCal () { for(inti =0; I <= N; i++) {c[i][0] = C[i][i] =1; for(intj =1; J <= I && J <=Ten; J + +) C[i][j] = c[i-1][J] + c[i-1][j-1]; }}voidInit () {read (); Read ();    n = read (); Cal (); for(inti =1; I <= N;    i++) B[i] = p[i].x = Read (), p[i].y = Read (); Sort (b +1, B +1+ N); tot =1; for(inti =2; I <= N; i++)if(B[i]! = B[tot]) B[++tot] = B[i]; for(inti =1; I <= N; i++) p[i].x = GETN (p[i].x); for(inti =1; I <= N;    i++) B[i] = p[i].y; Sort (b +1, B +1+ N); tot =1; for(inti =2; I <= N; i++)if(B[i]! = B[tot]) B[++tot] = B[i]; for(inti =1; I <= N;    i++) P[i].y = GETN (P[I].Y); K = read ();}voidSolve () {sort (P +1, p +1+ N);intAns =0; for(inti =1; I <= N; i++) u[p[i].x]++,r[p[i].y]++; for(inti =1; I <= N; i++) {if(I >1&& P[i-1].x = = p[i].x && p[i-1].y +1< p[i].y) ans + = c[u[p[i].x]][k] * c[d[p[i].x]][k] * SUM (p[i-1].y +1, P[i].y-1); u[p[i].x]--;        d[p[i].x]++; r[p[i].y]--;        l[p[i].y]++;        Add (P[i].y,-v[p[i].y]);    Add (P[i].y,v[p[i].y] = c[l[p[i].y]][k] * c[r[p[i].y]][k]); } cout << (ans >=0? Ans:ans +2147483647+1) << Endl;}intMain () {init (); Solve ();return 0;}

BZOJ1227 [SDOI2009] devout tomb master "tree-shaped Array"

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.