1#include <iostream>2#include <cstdio>3#include <algorithm>4 #definell Long Long5 #defineP 2147483648LL6 using namespacestd;7 intn,m,w,k,h[200001];8ll c[100001][ One],tr[200001],ans;9 structdata{intx, y;} a[100005];Ten inth[200001],l[200001]; One intnow[200001]; A intFindintx) - { - intL=1, r=2*W,mid; the while(l<=R) - { - intMid= (l+r) >>1; - if(h[mid]<x) l=mid+1; + Else if(h[mid]>x) r=mid-1; - Else returnmid; + } A } at voidgetc () - { -c[0][0]=1; - for(intI=1; i<=w;i++) -{c[i][0]=1; - for(intj=1; J<=min (k,i); J + +) inC[i][j]= (c[i-1][j]+c[i-1][j-1])%P; - } to } + intLowbit (intx) {returnx& (-x);} - voidUpdateintXinty) the { * while(x<=2*W) $ {Panax Notoginsengtr[x]+=y;tr[x]%=P; -x+=lowbit (x); the } + } All Ask (intx) the { +ll s=0; - while(x) $ { $s+=tr[x];s%=P; -x-=lowbit (x); - } the returns; - }WuyiInlineBOOLCMP (data a,data B) the { - if(A.Y==B.Y)returna.x<b.x; Wu returna.y<b.y; - } About intMain () $ { -scanf"%d%d%d",&m,&n,&W); - for(intI=1; i<=w;i++) - { Ascanf"%d%d",&a[i].x,&a[i].y); +h[2*i-1]=a[i].x; theh[2*i]=a[i].y; - } $scanf"%d",&K); getc (); theSort (H +1, H +2*w+1); the for(intI=1; i<=w;i++) the { theH[find (A[I].Y)]++; -L[find (a[i].x)]++; in } theSort (A +1, a+w+1, CMP); the intLF; About for(intI=1; i<=w;i++) the { the if(i>1&&a[i].y==a[i-1].y) the { +lf++; -ll T1=ask (Find (a[i].x)-1)-ask (Find (a[i-1].x)); thell T2=c[lf][k]*c[h[find (A[I].Y)]-LF] [K];BayiAns+=t1*T2; theans%=P; the } - Elself=0; - intD=find (a[i].x); now[d]++; the intChange= (c[now[d]][k]*c[l[d]-now[d]][k]-c[now[d]-1][k]*c[l[d]-now[d]+1][K])%P; the Update (d,change); the } the if(ans<0) ans+=P; -printf"%d", ans); the return 0; the}
A tree array that preprocess the number of graves for each column of each row to sort the coordinates by x, Y. One line sweep, with a tree array to save a section of the scheme number multiplied, in order to sweep, can be in the way to find the left and right, and then multiply the interval of the tree-like array
Can. When the tree array is modified, the original value is subtracted, plus.
Bzoj 1227: [SDOI2009] the faithful tomb master