玄学错误求助
查看原帖
玄学错误求助
320449
forest114514楼主2023/7/24 15:53

这是两份代码

AC:
//蒟蒻一枚
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=80005;
LL n,opt,mod,minn,maxx;
LL ch[N],cnt[N],num[N];
int main(){
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>opt>>mod>>minn>>maxx;
	string s;
	LL l,r,x;
	for(LL k=1;k<=opt;k++){
		cin>>s>>l>>r;
		if(s[0]=='A'){
			cin>>x;
			ch[l]+=x,ch[r+1]-=x;
		}
		else if(s[0]=='Q'){
			LL tot=0,sum=0;
			for(LL i=1;i<=r;i++){
				sum+=ch[i];
				LL t=(sum*i)%mod;
				if(t>=minn&&t<=maxx&&i>=l) tot++;
			}
			cout<<tot<<endl;
		}
	}
	
	LL f;
	cin>>f;
	num[0]=0;
	for(LL i=1;i<=n;i++){
		cnt[i]=cnt[i-1]+ch[i];
		num[i]=num[i-1];
		LL t=(cnt[i]*i)%mod;
		if(t>=minn&&t<=maxx) num[i]++;
	}
	
	for(LL i=1;i<=f;i++){
		cin>>l>>r;
		cout<<num[r]-num[l-1]<<endl;
	}
	return 0;
}
WA 12分:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=80005;
LL n,opt,mod,minn,maxx;
LL ch[N],cnt[N]={0},num[N];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>opt>>mod>>minn>>maxx;
	string s;
	LL l,r,x;
	for(int k=1;k<=opt;k++){
		cin>>s;
		if(s[0]=='A'){
			cin>>l>>r>>x;
			ch[l]+=x,ch[r+1]-=x;
		}
		else if(s[0]=='Q'){
			cin>>l>>r;
			LL tot=0,sum=0;
			for(int i=1;i<=r;i++){
				sum+=ch[i];
				sum=(sum*i)%mod;
				if(sum>=minn&&sum<=maxx&&i>=l) tot++;
			}
			cout<<tot<<endl;
		}
	}
	
	int f;
	cin>>f;
	num[0]=0;
	for(LL i=1;i<=n;i++){
		cnt[i]=cnt[i-1]+ch[i];
		num[i]=num[i-1];
		LL t=(cnt[i]*i)%mod;
		if(t>=minn&&t<=maxx) num[i]++;
	}
	
	for(int i=1;i<=f;i++){
		cin>>l>>r;
		cout<<num[r]-num[l-1]<<endl;
	}
	return 0;
}

所以第二份代码哪里有问题吗,有没有大佬能解答一下

2023/7/24 15:53
加载中...