zoukankan      html  css  js  c++  java
  • 【Luogu】P2220容易题(快速幂)

      这题真是“容易”。呵呵呵。

      参考题解:xyz32768

      代码

      

    #include<cstdio>
    #include<map>
    #include<algorithm>
    #include<cctype>
    #define mod 1000000007
    using namespace std;
    map<long long,bool> vis;
    inline long long read(){
        long long num=0,f=1;
        char ch=getchar();
        while(!isdigit(ch)){
            if(ch=='-')    f=-1;
            ch=getchar();
        }
        while(isdigit(ch)){
            num=num*10+ch-'0';
            ch=getchar();
        }
        return num*f;
    }
    
    inline long long mul(long long a,long long b){
        long long ret=0;
        if(b==1)    return a;
        while(b){
            if(b&1)    ret=(ret+a)%mod;
            a=(a+a)%mod;
            b>>=1;
        }
        return ret;
    }
    
    inline long long Pow(long long a,long long b){
        long long ret=1;
        if(b==1)    return a;
        while(b){
            if(b&1)    ret=mul(ret,a);
            a=mul(a,a);
            b>>=1;
        }
        return ret;
    }
    
    long long s[1000010];
    
    struct Line{
        long long x,y;
        bool operator <(const Line &a)const{
            if(x!=a.x)    return x<a.x;
            return y<a.y;
        }
    }w[1000010];
    long long tot;
    int main(){
        freopen("in.txt","r",stdin);
        freopen("out1.txt","w",stdout);
        long long n=read(),m=read(),q=read();
        long long sum;
        if(n&1)    sum=mul((1+n)>>1,n);
        else    sum=mul(1+n,n>>1);
        for(long long i=1;i<=q;++i)    s[i]=sum;
        for(long long i=1;i<=q;++i)    w[i]=(Line){read(),read()};
        sort(w+1,w+q+1);
        for(long long i=1;i<=q;++i){
            long long x=w[i].x;
            if(!vis[x]){
                vis[x]=1;
                tot++;
            }
        }
        long long ans=Pow(sum,m-tot);
        for(long long i=1;i<=q;++i){
            long long d=sum;
            long long j;
            d-=w[i].y;
            for(j=i+1;w[j].x==w[j-1].x;j++){
                if(w[j].y==w[j-1].y)    continue;
                d-=w[j].y;
            }
            d=(d%mod+mod)%mod;
            ans=(ans*d)%mod;
            i=j-1;
        }
        printf("%lld",ans);
        return 0;
    }
  • 相关阅读:
    CentOS + java
    在 Centos7 用Jexus服务器 运行.Net Core 只需几部
    dotnet core 开发中遇到的问题
    Scratch3.0设计的插件系统(上篇)
    ASP.NET的编译原理
    搭建git服务器
    ubuntu安装Pillow
    MIT线性代数课程总结与理解-第三部分
    关于在ubuntu系统下显卡为goforce1060安装tensorflow(gpu)
    关于Clion中添加makefile相关参数
  • 原文地址:https://www.cnblogs.com/cellular-automaton/p/7669954.html
Copyright © 2011-2022 走看看