本地AC提交WA是什么原因?
查看原帖
本地AC提交WA是什么原因?
627307
zing_Sing楼主2023/7/19 21:01

为什么我的代码本地下载数据 AC 但是交上去 WA?

是不是因为评测环境不同?有哪些不同呢?

附上代码:

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
const double eps=1e-8;
struct noi{
	double k,b;
	int id;
	noi(double m=0,double a=0,int i=0){k=m,b=a,id=i;}
	double calcy(int pos){
		return k*pos+b;
	}
	double calccx(const noi &l){
		return (b-l.b)/(l.k-k);
	}
}line[N];
struct ioi{
	int l,r;
	noi ln;
	int f;
}a[N*4];
void build(int now,int l,int r){
	a[now].l=l,a[now].r=r;
	if(l==r)return;
	int mid=l+r>>1;
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
}
void update(int now,int ll,int lr,noi lin){
	if(a[now].l>=ll&&a[now].r<=lr){
		double lp=a[now].ln.calcy(a[now].l),rp=a[now].ln.calcy(a[now].r);
		double lq=lin.calcy(a[now].l),rq=lin.calcy(a[now].r);
		if(!a[now].f)
			a[now].f=1,a[now].ln=lin;
		else if(lq-lp>eps&&rq-rp>eps)
			a[now].ln=lin;
		else if(lq-lp>eps||rq-rp>eps){
			int mid=a[now].l+a[now].r>>1;
			if(lin.calcy(mid)-a[now].ln.calcy(mid)>eps)swap(lin,a[now].ln);
			if(lin.calcy(a[now].l)>a[now].ln.calcy(a[now].l))
				update(now*2,ll,lr,lin);
			else update(now*2+1,ll,lr,lin);
		}
	}
	else{
		int mid=a[now].l+a[now].r>>1;
		if(mid>=ll)update(now*2,ll,lr,lin);
		if(mid<lr)update(now*2+1,ll,lr,lin);
	}
}
typedef pair<double,int>pii;
pii query(int now,int pos){
	double ans=a[now].ln.calcy(pos);
	int id=a[now].ln.id;
	if(a[now].l==a[now].r)return make_pair(ans,id);
	int mid=a[now].l+a[now].r>>1;
	if(pos<=mid){
		pii res=query(now*2,pos);
		if(res.first>ans||fabs(res.first-ans)<eps&&res.second<id)
			ans=res.first,id=res.second;
	}
	else{
		pii res=query(now*2+1,pos);
		if(res.first>ans||fabs(res.first-ans)<eps&&res.second<id)
			ans=res.first,id=res.second;
	}
	return make_pair(ans,id);
}
int res;
void turn(int &x){
	x=(x+res-1)%39989+1;
}
void turn_(int &x){
	x=(x+res-1)%39989+1;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	build(1,1,39989);
	int cnt=0;
	while(n--){
		int f;
		cin>>f;
		if(f){
			int x,y,x_,y_;
			cin>>x>>y>>x_>>y_;
			turn(x),turn_(y),turn(x_),turn_(y_); 
			if(x>x_)swap(x,x_),swap(y,y_);
			line[++cnt]=noi(1.0*(y-y_)/(x-x_),1.0*(x*y_-x_*y)/(x-x_),cnt);//k=(y1-y2)/(x1-x2),b=(x1y2-x2y1)/(x1-x2)
			update(1,x,x_,line[cnt]);
		}
		else{
			int k;
			cin>>k;
			turn(k);
			cout<<(res=query(1,k).second)<<"\n";
		}
	}
	return 0;
}

下载数据:

in:
3
1 1 2 2 1
1 1 1 1 2
0 1
out:
1

本地结果1,IDE 结果2

2023/7/19 21:01
加载中...