神秘大洋梨
查看原帖
神秘大洋梨
469213
SugarKite楼主2024/12/3 17:23

重写考场的码的时候给快速幂的幂次取了个模,发现它通过了所有大洋梨。

逆天ccf

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=1e6+10;
const int mod=1e9+7;

struct nina{
    int pos,d;
    inline bool operator<(const nina &a)const{
        return pos<a.pos;
    }
}p[N];
int t,n,m,v,ans;

inline int read(){
    int res=0;bool s=0;char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')s=1;
    for(;isdigit(c);c=getchar())res=(res<<1)+(res<<3)+(c^48);
    return s?-res:res;
}
inline int q_pow(int a,int n){
    int res=1;
    while(n){
        if(n&1)res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
signed main(){
    freopen("assign.in","r",stdin);
    freopen("assign.out","w",stdout);
    t=read();
    while(t--){
        ans=1;
        n=read();m=read();v=read();
        for(int i=1;i<=m;i++){
            p[i].pos=read();p[i].d=read();
        }
        sort(p+1,p+m+1);
        ans=ans*q_pow(v,2*p[1].pos-2)%mod;
        for(int i=2;i<=m;i++){
            if(p[i].pos==p[i-1].pos){
                if(p[i].d!=p[i-1].d){ans=0;break;}
                else continue;
            }
            int len=p[i].pos-p[i-1].pos;
            ans=ans*(q_pow(v,2*len)+mod-q_pow(v,len-1)%mod*(v+mod-1)%mod)%mod;
        }
        ans=ans*q_pow(v,2*(n+mod-p[m].pos)%mod)%mod;
        printf("%lld\n",ans%mod);
    }
    return 0;
}
2024/12/3 17:23
加载中...