P2220 [HAOI2012]容易题

P2220 [HAOI2012]容易题

设$t=\frac{n(n+1)}{2}$

$k=0$时,显然$ans=m^t$

仅考虑一个位置$x$不可用的数$y$,$x$位置对总积的贡献即为$t-y$

此时$ans=(m-1)^t*(t-y)$

于是我们把所有位置去重一下

快速幂统计完好的位置,部分残缺的位置直接枚举统计

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int read(){
    char c=getchar(); int x=0;
    while(c<'0'||c>'9') c=getchar();
    while('0'<=c&&c<='9') x=x*10+c-48,c=getchar();
    return x;
}
const ll P=1e9+7;
int k,tk,m; ll n,t,ans;
struct Lim{int x;ll y;}a[100005];
int cmp(Lim A,Lim B){return A.x==B.x?A.y<B.y:A.x<B.x;}
ll Pow(ll x,ll y){ll re=1; for(;y;y>>=1,x=x*x%P)if(y&1)re=re*x%P; return re;}
int main(){
    n=read(); m=read(); k=read(); t=n*(n+1)/2;
    for(int i=1;i<=k;++i) a[i].x=read(),a[i].y=read();
    sort(a+1,a+k+1,cmp);
    for(ll i=1,s=0;i<=k;++i){
        if(a[i].x==a[i+1].x){
            if(a[i].y!=a[i+1].y) s+=a[i].y;
        }else a[i].y+=s,a[++tk]=a[i],s=0;
    }ans=Pow(t%P,m-tk);
    for(int i=1;i<=tk;++i) ans=(t-a[i].y)%P*ans%P;
    printf("%lld",ans);
    return 0;
}

 

转载于:https://www.cnblogs.com/kafuuchino/p/11488337.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值