社区讨论
WA on #13~#20求条
P11362[NOIP2024] 遗失的赋值参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mhj0nkqq
- 此快照首次捕获于
- 2025/11/03 18:47 4 个月前
- 此快照最后确认于
- 2025/11/03 18:47 4 个月前
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int maxm=1e5+5,mod=1e9+7;
int read(){
int f=1,x=0;
char ch=getchar();
while (ch>'9' || ch<'0'){
if (ch=='-') f*=-1;
ch=getchar();
}
while (ch>='0' && ch<='9'){
x=(x<<1)+(x<<3)+ch-'0';
ch=getchar();
}
return f*x;
}
struct node{
int c,d;
}p[maxm];
bool cmp(node a,node b){
return a.c<b.c;
}
bool operator ==(node a,node b){
return a.c==b.c && a.d==b.d;
}
int qpow(int a,int x){
int res=1;
while (x){
if (x&1) res=res*a%mod;
a=a*a%mod;x/=2;
}
return res%mod;
}
int T,n,m,v,ans;
signed main(){
T=read();
while (T--){
bool flag=false;
n=read(),m=read(),v=read();
for (int i=1;i<=m;i++)
p[i].c=read(),p[i].d=read();
sort(p+1,p+1+m,cmp);
m=unique(p+1,p+1+m)-p-1;//去重
int ans=qpow(v,2*(p[1].c-1+n-p[m].c));//两边
for (int i=2;i<=m;i++){
ans=(ans*(qpow(v,2*(p[i].c-p[i-1].c))-qpow(v,p[i].c-p[i-1].c-1)*(v-1)))%mod;//计算中间部分v^(2*(c[i]-c[i-1]))-v^(c[i]-c[i-1]-1)*(v-1)
if (p[i-1].c==p[i].c && p[i-1].d!=p[i].d){
cout/*<<"!"*/<<0<<'\n';
flag=true;break;
}
}
if (!flag) cout<<ans%mod<<'\n';
}
return 0;
}
感觉(可能)是取模问题OvO也有可能是我哪里糖了
回复
共 1 条回复,欢迎继续交流。
正在加载回复...