社区讨论

超时怎么改

P11362[NOIP2024] 遗失的赋值参与者 3已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m48jgpp4
此快照首次捕获于
2024/12/03 22:12
去年
此快照最后确认于
2025/11/04 13:23
4 个月前
查看原帖
不知道为什么 O(q×mlogn)O(q\times mlogn) 会超时
CPP
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*f;
}
const int mod=1e9+7;
const int N=1e5+500;
map<int,int>a;
int T,n,m,v,x,y;
int c[N];
int ans;
inline int qpow(int a,int b){
	int t=1;
	while(b){
		if(b&1) t=(t*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return t;
}
signed main(){
	T=read();
	while(T--){
		n=read();
		m=read();
		v=read();
		a.clear();
		bool f=0;
		for(int i=1;i<=m;i++){
			c[i]=read();
			y=read();
			if(a[c[i]]!=0){
				if(a[c[i]]!=y){
					printf("0\n");
					f=1;
					break;
				}
				
			}
			a[c[i]]=y;
		}
		if(f) continue;
		sort(c+1,c+m+1);
		ans=qpow(v,(c[1]-1)<<1);
		for(int i=2;i<=m;i++){
			ans*=(qpow(v,(c[i]-c[i-1])<<1)-((qpow(v,c[i]-c[i-1]-1)*(v-1))%mod));
			ans%=mod;
		}
		ans*=(qpow(v,(n-c[m])<<1));
		ans%=mod;
		printf("%lld\n",ans);
	}
	return 0;
}


回复

2 条回复,欢迎继续交流。

正在加载回复...