容易题的确很容易,公式一推就出来了。
详见代码:
#include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<string> #include<map> #include<cstdlib> #include<cmath> #include<cstdio> #include<ctime> #include<queue> using namespace std; #define LL long long #define FILE "dealing" #define eps 1e-10 #define db double #define pii pair<LL,LL> #define up(i,j,n) for(int i=j;i<=n;i++) int read(){ int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar(); return x*f; } const LL maxn=200000,mod=1000000007,inf=1000000007; bool cmin(int& a,int b){return a>b?a=b,true:false;} bool cmax(int& a,int b){return a<b?a=b,true:false;} LL n,m,k,top=0; pii t[maxn],d[maxn]; LL fast(LL a,LL b){ LL ans=1; for(;b;b>>=1,a=(a*a)%mod)if(b&1)ans=(ans*a)%mod; return ans; } int main(){ freopen(FILE".in","r",stdin); freopen(FILE".out","w",stdout); n=read(),m=read(),k=read(); LL p=(n+1)*n/2%mod; if(!k){ cout<<fast(p,m)<<endl; return 0; } up(i,1,k)t[i].first=read(),t[i].second=read(); sort(t+1,t+k+1); top=0; up(i,1,k)if(d[top]!=t[i])d[++top]=t[i]; k=top;top=1; t[1]=d[1]; up(i,2,k){ if(t[top].first==d[i].first)t[top].second=(t[top].second+d[i].second)%mod; else t[++top]=d[i]; } k=top; LL ans=1; if(t[1].first!=1){ans=(ans*fast(p,t[1].first-1))%mod;} t[k+1].first=m+1; up(i,1,k){ ans=(ans*((p-t[i].second+mod)%mod))%mod; ans=(ans*fast(p,t[i+1].first-t[i].first-1)%mod); } cout<<ans<<endl; return 0; }