Him_shu @ 2024-12-04 16:41:44
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-'){f=-1;}ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0',ch=getchar();}return x*f;}
void write(int x){if(x<0){putchar('-'),x=-x;}if(x>9){write(x/10);} putchar(x%10+'0');return;}
int qpow(int a,int b,int mod){
if(b==0){return 1;}
int mid=qpow(a,b/2,mod)%mod;
if(b&1){return (mid*mid%mod)*a%mod;}
return mid*mid%mod;
}
const int N=1e5+5,mod=1e9+7;
int t;
int n,m,v;
int c[N];
map<int,int>mp;
signed main(){
// freopen("assign2.in","r",stdin);
cin>>t;
while(t--){
mp.clear();
memset(c,0,sizeof(c));
cin>>n>>m>>v;
int ans=qpow(v,n*2-2,mod);
for(int i=1,d;i<=m;i++){
cin>>c[i]>>d;
if(mp[c[i]]!=0&&mp[c[i]]!=d){
ans=0;
}
mp[c[i]]=d;
}
if(!ans){
cout<<ans<<"\n";
continue;
}
sort(c+1,c+m+1);
int mm=unique(c+1,c+m+1)-c-1;
// cout<<"ANS="<<mm<<"\n";
for(int i=2;i<=mm;i++){
ans=(ans*(qpow(v,c[i]-c[i-1]+1,mod)-1+mod)%mod)*qpow(v,(c[i]-c[i-1]+1)*(mod-2),mod)%mod;
}cout<<ans<<"\n";
}
return 0;
}
by _ckx_ @ 2024-12-04 22:26:23
你这式子是什么意思