25pts求diao

P11362 [NOIP2024] 遗失的赋值

Ice_Fist @ 2024-12-24 19:59:40


#include<bits/stdc++.h>
using namespace std ;
const long long mod=1e9+7;
long long n,m,v,T,c[100001],d[100001];
long long ksm(long long a,long long b){
    long long x=1;
    for(long long i=1;i<=b;++i){
        x*=a;
        x%=mod;
    }
    return x%mod;
}
long long pai(){
    long long x=1;
    for(long long i=2;i<=m;++i){
        x*=ksm(v,2*(c[i]-c[i-1]))-ksm(v,c[i]-c[i-1]-1)*(v-1);
        x%=mod;
    }
    return x%mod;
}
int main(){
    freopen("assign1.in","r",stdin);
    cin>>T;
    while(T--){
        cin>>n>>m>>v;
        for(long long i=1;i<=m;++i)
            cin>>c[i]>>d[i];
        sort(c+1,c+1+m);
        cout<<abs(ksm(v,2*(c[1]-1+n-c[m]))*pai())%mod<<endl;
    }
    return 0;
}``````

by zhang_yang_alan @ 2025-01-09 19:52:52

O(tmn)


|