题目:
题解:
首先我们可以发现答案就是所有位能取的数的和的积
然后对读入 一顿去重 求一下就好了
吐槽:
内心OS:天啦噜这个1e9的n我怎么求个和呢?然后还考虑是不是要打个表。。。
过了一会:我是不是学过等差数列求和的公式。。。
数体教啊!真的要被自己蠢哭了
代码:
#include <cstdio>
#include <map>
#include <algorithm>
#include <iostream>
#define LL long long
using namespace std;
const int mod=1e9+7;
const int K=1e5;
struct hh
{
int x,y;
bool operator <(const hh &a) const
{
if (x==a.x) return y<a.y;else return x<a.x;
}
bool operator ==(const hh &a) const
{
return x==a.x&&y==a.y;
}
}limit[K+5];
LL ans=1,sum[K+5];
map<int,bool>vis;
void ksm(LL a,LL k)
{
for (;k;k>>=1,a=a*a%mod)
if (k&1) ans=ans*a%mod;
}
int main()
{
int n,m,k,i;
scanf("%d%d%d",&n,&m,&k);
for (i=1;i<=k;i++) scanf("%d%d",&limit[i].x,&limit[i].y);
sort(limit+1,limit+k+1);
k=unique(limit+1,limit+k+1)-limit-1;
int cnt=0;
for (i=1;i<=k;i++)
{
int x=limit[i].x,y=limit[i].y;
if (!vis[x])
{
vis[x]=1;
if (cnt) ans=((LL)ans*sum[cnt])%mod;
sum[++cnt]=(LL)n*(n+1)/2%mod;
}
sum[cnt]=(sum[cnt]-y+mod)%mod;
}
if (sum[cnt]) ans=(ans*sum[cnt])%mod;
ksm((LL)n*(n+1)/2%mod,m-cnt);
printf("%lld",ans);
}