题解:P11362 [NOIP2024] 遗失的赋值
wenhaoran11 · · 题解
题解
先说部分分。
如果
再看
接下来就可以考虑正解了。我们考虑每一个区间有多少种选法,乘起来就是答案了。
发现正着做不好做,我们反着做。考虑不行的情况。
只有一种就是
前面有
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5,mod=1e9+7;
int T,n,m,v;
struct node{
int c,d;
};
node p[N];
bool cmp(node x,node y){
if(x.c==y.c) return x.d<y.d;
return x.c<y.c;
}
int qpow(int a,int b){
int res=1;
while(b){
if(b&1){
res=(res*a)%mod;
}
a=(a*a)%mod;
b>>=1;
}
return res;
}
signed main(){
scanf("%lld",&T);
while(T--){
scanf("%lld%lld%lld",&n,&m,&v);
bool flagA=true;
if(n!=m){
flagA=false;
}
for(int i=1;i<=m;i++){
scanf("%lld%lld",&p[i].c,&p[i].d);
if(p[i].c!=i){
flagA=false;
}
}
sort(p+1,p+m+1,cmp);
bool kkk=true;
for(int i=2;i<=m;i++){
if(p[i].c==p[i-1].c&&p[i].d!=p[i-1].d){
kkk=false;
break;
}
}
if(kkk==false){
printf("0\n");
continue;
}
int ans=qpow(v,2*(p[1].c-1));
for(int i=1;i<m;i++){
if(p[i].c==p[i+1].c) continue;
int len=p[i+1].c-p[i].c;
ans=(ans*(qpow(v,2*len)-qpow(v,len-1)*(v-1)%mod)%mod+mod)%mod;
}
ans=(ans*qpow(v,(n-p[m].c)*2))%mod;
printf("%lld\n",ans);
//部分分: if(m==1){
// int ans=(qpow(v,2*(n-1))+mod)%mod;
// printf("%lld\n",ans);
// continue;
// }
// if(flagA=true){
// int cnt=1+(v-1)*v;
// cnt%=mod;
// int ans=qpow(cnt,n-1);
// printf("%lld\n",ans);
// continue;
// }
}
return ~(-1);
}