# 洛谷2220 [haoi2012]容易题

## 容易题果然很easy

Posted by yjjr's blog on November 2, 2018

# 题目

## 输入输出样例

### 输入样例#1

3 4 5
1 1
1 1
2 2
2 3
4 3


### 输出样例#1

90


## 说明

A[1]不能取1

A[2]不能去2、3

A[4]不能取3

2 1 1 1 2

2 1 1 2 4

2 1 2 1 4

2 1 2 2 8

2 1 3 1 6

2 1 3 2 12

3 1 1 1 3

3 1 1 2 6

3 1 2 1 6

3 1 2 2 12

3 1 3 1 9

3 1 3 2 18

30%的数据n<=4,m<=10,k<=10

70%的数据n<=1000,m<=1000,k<=1000

100%的数据 $% $

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e6+5,mod=1e9+7;
ll ans=1;
int n,m,k,sum;
struct node{int pos,val;}a[maxn];
inline bool cmp(node a,node b){return a.pos==b.pos?a.val<b.val:a.pos<b.pos;}
inline int qpow(ll a,ll b){
ll re=1;
while(b){
if(b&1)re=re*a%mod;
b>>=1,a=(a*a)%mod;
}
return re;
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
sort(a+1,a+1+k,cmp);
int tot=m,sum=(ll)n*(n+1)/2%mod,tmp=sum;
rep(i,1,k){
if(a[i].pos!=a[i-1].pos&&i!=1)ans=ans*tmp%mod,tmp=sum,tot--;
if(a[i].pos!=a[i-1].pos||a[i].val!=a[i-1].val){
tmp-=a[i].val;
if(tmp<0)tmp+=mod;
}
}
tot--;ans=ans*tmp%mod;
printf("%lld\n",ans*qpow(sum,tot)%mod);
return 0;
}