QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697777#6429. Let's Play Curling552Hz#WA 0ms3852kbC++143.3kb2024-11-01 15:44:432024-11-01 15:44:43

Judging History

你现在查看的是最新测评结果

  • [2024-11-01 15:44:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2024-11-01 15:44:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=200010;
const ll mod=998244353;
int n,m;
ll a[N],b[N];
void solve(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];a[i]*=2;
	}
	std::vector<ll> q;
	for(int i=1;i<=m;i++){
		cin>>b[i];b[i]*=2;
		q.push_back(b[i]);
	}
	ll ans=0;
	sort(q.begin(),q.end());
	q.push_back(1e17);
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	for(int i=1;i<=n;i++){
		ll pos=a[i];
		ll w=lower_bound(q.begin(),q.end(),pos)-q.begin();
		ll dis=1e18;
		dis=min(dis,q[w]-pos);
		if(w!=0){
			w--;
		}
		dis=min(dis,pos-q[w]);
		//cout<<dis<<" ";
		int r=0,l=0;
		if(dis==0){
			continue;
		}
		for(int j=20;j>=0;j--){
			if((r+(1<<j))+i>n){
				continue;
			}
			if(a[(r+(1<<j))+i]-a[i]<dis){
				r+=(1<<j);
			}
		}
		for(int j=20;j>=0;j--){
			if(i-(l+(1<<j))<1){
				continue;
			}
			if(a[i]-a[i-(l+(1<<j))]<dis){
				l+=(1<<j);
			}
		}
		r=r+i;
		l=i-l;
		ans=max(ans,1ll*(r-l+1));
	}
	for(int i=1;i<n;i++){
		ll pos=(a[i]+a[i+1])/2;
		ll w=lower_bound(q.begin(),q.end(),pos)-q.begin();
		ll dis=1e18;
		dis=min(dis,q[w]-pos);
		if(w!=0){
			w--;
		}
		dis=min(dis,pos-q[w]);
		//cout<<dis<<" ";
		int r=0,l=0;
		if(dis==0){
			continue;
		}
		for(int j=20;j>=0;j--){
			if((r+(1<<j))+i>n){
				continue;
			}
			if(a[(r+(1<<j))+i]-pos<dis){
				r+=(1<<j);
			}
		}
		for(int j=20;j>=0;j--){
			if(i-(l+(1<<j))<1){
				continue;
			}
			if(a[i]-a[i-(l+(1<<j))]<dis){
				l+=(1<<j);
			}
		}
		r=r+i;
		l=i-l;
		ans=max(ans,1ll*(r-l+1));
	}
	for(int i=1;i<m;i++){
		ll pos=(b[i]+b[i+1])/2;
		ll w=lower_bound(q.begin(),q.end(),pos)-q.begin();
		ll dis=1e18;
		dis=min(dis,q[w]-pos);
		if(w!=0){
			w--;
		}
		dis=min(dis,pos-q[w]);
		//cout<<dis<<" ";
		int r=0,l=(1<<21)-1;
		if(dis==0){
			continue;
		}
		for(int j=20;j>=0;j--){
			if((r+(1<<j))>n){
				continue;
			}
			if(a[r+(1<<j)]-pos<dis){
				r=(r+(1<<j));
			}
		}
		for(int j=20;j>=0;j--){
			if((l)>n){
				l-=(1<<j);
				continue;
			}
			if(pos-a[l]<=dis){
				l=(l-(1<<j));
			}
		}
		ans=max(ans,1ll*(r-l));
	}
	ll pos=(-1e9)/2;
		ll w=lower_bound(q.begin(),q.end(),pos)-q.begin();
		ll dis=1e18;
		dis=min(dis,q[w]-pos);
		if(w!=0){
			w--;
		}
		dis=min(dis,pos-q[w]);
		//cout<<dis<<" ";
		int r=0,l=(1<<21)-1;
		
		for(int j=20;j>=0;j--){
			if((r+(1<<j))>n){
				continue;
			}
			if(a[r+(1<<j)]-pos<dis){
				r=(r+(1<<j));
			}
		}
		for(int j=20;j>=0;j--){
			if((l)>n){
				l-=(1<<j);
				continue;
			}
			if(pos-a[l]<=dis){
				l=(l-(1<<j));
			}
		}
		ans=max(ans,1ll*(r-l));

	pos=(1ll*10000000000)/2;
		w=lower_bound(q.begin(),q.end(),pos)-q.begin();
		dis=1e18;
		dis=min(dis,q[w]-pos);
		if(w!=0){
			w--;
		}
		dis=min(dis,pos-q[w]);
		//cout<<dis<<" ";
		r=0,l=(1<<21)-1;
		
		for(int j=20;j>=0;j--){
			if((r+(1<<j))>n){
				continue;
			}
			if(a[r+(1<<j)]-pos<dis){
				r=(r+(1<<j));
			}
		}
		for(int j=20;j>=0;j--){
			if((l)>n){
				l-=(1<<j);
				continue;
			}
			if(pos-a[l]<=dis){
				l=(l-(1<<j));
			}
		}
		ans=max(ans,1ll*(r-l));
	if(ans==0){
		cout<<"Impossible"<<endl;
	}else{
		cout<<ans<<endl;
	}
	//cout<<ans<<endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _=1;
	cin>>_;
	while(_--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3852kb

input:

3
2 2
2 3
1 4
6 5
2 5 3 7 1 7
3 4 3 1 10
1 1
7
7

output:

2
3
1

result:

wrong answer 3rd lines differ - expected: 'Impossible', found: '1'