得了88分,WA了3个点。跟第一个题解拍了一个小时,没有一组错误数据。
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define getchar() ((p1==p2&&(p2=(p1=io)+fread(io,1,MAXR,stdin))),p1==p2 ? EOF : *p1++)
#define MAXR 10000000
#define MAX (1000000+10)
#define long long long
using namespace std;
using namespace tr1;
struct Node
{
int x,y;
}d[MAX];
char io[MAXR],*p1=io,*p2=io;
int N,M,W,K,U[MAX],D[MAX],L[MAX],R[MAX];
long ans,C[MAX],BT[MAX];
unordered_map <int,int> HASH;
inline bool cmp1(const Node &a,const Node &b){return a.x==b.x ? a.y<b.y : a.x<b.x;}
inline bool cmp2(const Node &a,const Node &b){return a.y==b.y ? a.x<b.x : a.y<b.y;}
inline void add(int x,const long v){while (x <= N) BT[x] += v, x += x&-x;}
inline void read(int &a)
{
register char c = getchar();
for (a=0; c<'0'||'9'<c; c=getchar());
for (; '0'<=c && c<='9'; c=getchar())
a *= 10, a += c ^ 48;
}
inline long sum(int x)
{
register long ans = 0;
while (x)
{
ans += BT[x];
x -= x&-x;
}return ans;
}
int main()
{
freopen("testdata.in","r",stdin);
freopen("testdata.out","w",stdout);
read(N); read(M); read(W);
for (register int i=0; i<W; i++)
read(d[i].x), read(d[i].y);
read(K); C[K] = 1;
for (register int i=K; i<W; i++)
C[i+1] = (C[i] * (i+1) / (i-K+1)) & 0x7fffffff;
sort(d,d+W,cmp2); N = M = 0;
for (register int i=0; i<W; i++)
{
if (!HASH.count(d[i].y))
HASH[d[i].y] = ++N;
d[i].y = HASH[d[i].y];
R[d[i].y]++;
}
sort(d,d+W,cmp1); HASH.clear();
for (register int i=0; i<W; i++)
{
if (!HASH[d[i].x])
HASH[d[i].x] = ++M;
d[i].x = HASH[d[i].x];
U[d[i].x]++;
}M = 0;
for (register int i=0; i<W; i++)
{
if (!i || d[i].x != d[i-1].x)
M++;
else {
U[M]--, D[M]++;
ans += (sum(d[i].y-1)-sum(d[i-1].y)) * C[U[M]] * C[D[M]];
ans &= 0x7fffffff;
}
int &LL = L[d[i].y], &RR = R[d[i].y];
add(d[i].y,C[LL+1]*C[RR-1]-C[LL]*C[RR]);
LL++; RR--;
}printf("%lld\n",ans);
}