QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454156#5463. Range Closest Pair of Points QueryN_z_WA 1ms3840kbC++146.3kb2024-06-24 16:56:512024-06-24 16:56:52

Judging History

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

  • [2024-06-24 16:56:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2024-06-24 16:56:51]
  • 提交

answer

#define LUOGU
#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include<bits/stdc++.h>
using namespace std;
struct time_helper
{
#ifdef LOCAL
	clock_t time_last;
#endif
	time_helper()
	{
#ifdef LOCAL
		time_last=clock();
#endif
	}
	void test()
	{
#ifdef LOCAL
		auto time_now=clock();
		std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;
		time_last=time_now;
#endif
	}
	~time_helper()
	{
		test();
	}
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 10
#define between '\n'
#define __int128 long long
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl

void solve();
main()
{
	int t=1;
	// cin>>t;
	while(t--)solve();
}
constexpr int B=500,V=1e8;
void solve()
{
	int n,q;
	cin>>n>>q;
	vector<int>u(n+1),v(n+1);
	for(int x=1;x<=n;x++)
	cin>>u[x]>>v[x];
	auto calcdis=[&](int x,int y)
	{
		return 1ll*(u[x]-u[y])*(u[x]-u[y])+1ll*(v[x]-v[y])*(v[x]-v[y]);
	};
	vector<long long>ans(q+1);
	vector<vector<pair<int,int>>>qs(n+1);
	for(int x=1;x<=q;x++)
	{
		int l,r;
		cin>>l>>r;
		qs[r].emplace_back(l,x);
	}
	vector<int>bl(n+1),bll((n-1)/B+2),blr((n-1)/B+2);
	for(int x=1;x<=n;x++)
	bl[x]=(x-1)/B+1,bll[bl[x]]=(bll[bl[x]]==0?x:bll[bl[x]]),blr[bl[x]]=x;
	vector<long long>val(n+1,1e18),vf(bl[n]+1,1e18);
	auto add=[&](int x,int y)
	{
		long long dis=calcdis(x,y);
		val[x]=min(val[x],dis);
		vf[bl[x]]=min(vf[bl[x]],dis);
		return dis;
	};
	auto query=[&](int l,int r)
	{
		long long ans=1e18;
		if(bl[l]==bl[r])
		{
			for(int x=l;x<=r;x++)
			ans=min(ans,val[x]);
			return ans;
		}
		for(int x=l;x<=blr[bl[l]];x++)
		ans=min(ans,val[x]);
		for(int x=bl[l]+1;x<=bl[r]-1;x++)
		ans=min(ans,vf[x]);
		for(int x=bll[bl[r]];x<=r;x++)
		ans=min(ans,val[x]);
		return ans;
	};
	vector<unordered_map<long long,int>>tb(31);
	vector<vector<int>>a(n*30+1);
	int cnt=0;
	for(int x=1;x<=n;x++)
	{
		for(int y=1;(1<<y)<=V;y+=2)
		{
			long long uuu=u[x]>>y,vvv=v[x]>>y;
			int lim=V>>y;
			long long id=uuu<<32|vvv;
			if(tb[y].find(id)==tb[y].end())
			tb[y][id]=++cnt;
			for(long long uu=uuu-1;uu<=uuu+1;uu++)
			for(long long vv=vvv-1;vv<=vvv+1;vv++)
			{
				if(uu<0||uu>lim||vv<0||vv>lim)continue;
				long long iid=uu<<32|vv;
				if(tb[y].find(iid)==tb[y].end())continue;
				vector<int>G;
				for(auto q:a[tb[y][iid]])
				{
					long long dis=add(q,x);
					if(dis>=(1ll<<y+y-2))G.emplace_back(q);
				}
				if(uu==uuu&&vv==vvv)G.emplace_back(x);
				a[tb[y][iid]]=move(G);
			}
		}
		for(auto [l,id]:qs[x])
		ans[id]=query(l,x);
	}
	for(int x=1;x<=q;x++)
	cout<<ans[x]<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3528kb

input:

5 5
2 4
1 1
3 3
5 1
4 2
1 5
2 3
2 4
3 5
1 3

output:

2
8
8
2
2

result:

ok 5 number(s): "2 8 8 2 2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

2 1
1 1
1 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

2 1
1 100000000
100000000 1
1 2

output:

1000000000000000000

result:

wrong answer 1st numbers differ - expected: '19999999600000002', found: '1000000000000000000'