bzoj2751: [HAOI2012]容易题(easy)

 结论很简单,就是把每个位置的数相加再相乘就好了。对于限制比较少,而位置比较多,所以处理出限制的位置,剩余位置用快速幂就好了。

 1 #include<bits/stdc++.h>
 2 #define N 100005
 3 #define LL long long
 4 #define inf 0x3f3f3f3f
 5 #define ls c[x][0]
 6 #define rs c[x][1]
 7 using namespace std;
 8 inline int ra()
 9 {
10     int x=0,f=1; char ch=getchar();
11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
13     return x*f;
14 }
15 const LL mod=1000000007LL;
16 LL n,m,k;
17 struct node{
18     LL x,y;
19 }a[N];
20 bool operator == (node a, node b)
21 {
22     return a.x==b.x && a.y==b.y;
23 }
24 bool cmp(node a, node b)
25 {
26     if (a.x==b.x) return a.y<b.y;
27     return a.x<b.x;
28 }
29 LL ksm(LL x, LL p)
30 {
31     LL sum=1;
32     for (;p;p>>=1,x=x*x%mod)
33         if (p&1) sum=sum*x%mod;
34     return sum%mod; 
35 }
36 int main()
37 {
38     n=ra(); m=ra(); k=ra();
39     LL sum=(n+1)*n/2%mod;
40     for (LL i=1; i<=k; i++)
41         a[i].x=ra(),a[i].y=ra();
42     sort(a+1,a+k+1,cmp);
43     LL ans=1; LL tot=1;
44     LL del=0;
45     for (int i=1; i<=k; i++)
46         if (a[i].x!=a[i-1].x) m--;
47     for (int i=1,last; i<=k; i=last)
48     {
49         LL now=sum;
50         for (last=i;a[last].x==a[i].x;last++)
51             if (last==i || a[last].y!=a[last-1].y)
52                 now=(now-a[last].y+mod)%mod;
53         ans=ans*now%mod;
54     }
55     ans=(ans*ksm(sum,m))%mod;
56     cout<<(ans+mod)%mod;
57     return 0;
58 }

 

posted @ 2017-02-20 06:55  ws_ccd  阅读(132)  评论(0编辑  收藏  举报