60pts求调,样例已过

P11362 [NOIP2024] 遗失的赋值

woyaoxiaban @ 2024-12-03 15:38:15

测评记录

#include <bits/stdc++.h>
using namespace std;
const int p=1e9+7;
int n,m,v;
map<int,int> mp;
long long ans;
long long fast(long long a1,long long b1){
    long long res=1,a=a1,b=b1;
    while(b){
        if(b&1) res=(res%p*a%p)%p;
        a=(a%p*a%p)%p;
        b=b>>1;
    }
    return res%p;
} 
int main(){
//  freopen("assign3.in","r",stdin);
//  freopen("assign333.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        mp.clear();
        ans=1;
        cin>>n>>m>>v;
        if(n==1) {
            cout<<0<<endl;
            continue;
        }
        int f1=0,f2=0,k=0;
        if(m==n) f2=1;
        for(int i=1;i<=m;i++)
        {
            int id,val;
            cin>>id>>val;
            if(id!=i) f2=0;
            if(mp[id]&&mp[id]!=val) {
                f1=1;break;
            }
            mp[id]=val;
        }
        if(f1){
            cout<<0<<endl;
            continue;
        }
        if(f2){
            ans=1ll*v*(v-1)%p;
            cout<<fast(ans+1,n-1)%p<<endl;
            continue;
        }
        int pos;
        for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
        {
            if(it==mp.begin()){
                pos=(*mp.begin()).first;
                ans*=fast(v,2*(pos-1));
            }
            else{
                int d=(*it).first-pos;
                ans=ans*(((fast(v,2*d)-fast(v,d))%p+fast(v,d-1))%p)%p;
                pos=(*it).first;
            }
        }
        pos=(*mp.rbegin()).first;
        ans=ans*fast(v,2*(n-pos))%p;
        cout<<ans<<endl;
    }
}

by HKW0202 @ 2024-12-03 22:48:37

没输入完数据就continue和break了当然没分


by HKW0202 @ 2024-12-03 22:49:12

我赛场上也被大样例骗了非常气愤


by woyaoxiaban @ 2024-12-04 08:32:34

@HKW0202 感谢TUT


|