求调
查看原帖
求调
595098
weiyiqian楼主2024/12/2 17:42

按第一篇题解写的代码,这个样例过不去

1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2

输出:

82944

答案:

129600

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100010,mod=1e9+7;
int v,n,m,c[N],d[N];
int qmi(int a,int b){
    LL res=1;
    while(b){
        if(b&1) res=(LL)res*a%mod;
        a=(LL)a*a%mod;
        b>>=1;
    }
    return res%mod;
}
unordered_map<int,int> S;
int main(){
//	freopen("assign2.in","r",stdin);
//	freopen("assign2.out","w",stdout);
    int t1;
    cin>>t1;
    while(t1--){
        cin>>n>>m>>v;
        int p=0;
        int x[N];
        memset(x,0,sizeof x);
        memset(c,0,sizeof c);
        bool flag=0;
        S.clear();
        for(int i=1;i<=m;i++){
            cin>>c[i]>>d[i];
            if(!S.count(c[i])) S[c[i]]=++p;
            if(x[S[c[i]]]&&x[S[c[i]]]!=d[i]) flag=1;
            x[S[c[i]]]=d[i];
        }
        sort(c+1,c+1+m);
        for(int i=1;i<=m;i++) cout<<c[i]<<" ";
        cout<<endl;
        if(flag) cout<<0<<endl;
        else{
            LL ans=1;
            ans=(LL)ans*(qmi(v,2*(c[1]-1)))%mod;
            for(int i=2;i<=m;i++){
                if(c[i]!=c[i-1]) ans=(LL)ans*(qmi(v,2*(c[i]-c[i-1]))%mod-(LL)qmi(v,2*(c[i]-c[i-1]-1))*(v-1)%mod+mod)%mod;
            }
            ans=(LL)ans*qmi(v,2*n-2*c[m])%mod;
            cout<<ans<<endl;
        }
    }
	return 0;
}
/*
1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2
*/
2024/12/2 17:42
加载中...