QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#824195#9776. Best Friend, Worst Enemyucup-team1004#ML 2ms12180kbC++143.5kb2024-12-21 12:59:412024-12-21 12:59:44

Judging History

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

  • [2024-12-21 12:59:44]
  • 评测
  • 测评结果:ML
  • 用时:2ms
  • 内存:12180kb
  • [2024-12-21 12:59:41]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=4e5+5,M=(1<<28)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,X[N],Y[N];
int nx[N],ny[N],xh,yh;
struct bit{
	int f[N];
	void add(int x,int y){while(x<=n) f[x]+=y,x+=x&-x;}
	int qry(int x){int ans=0;while(x) ans+=f[x],x-=x&-x;return ans;}
}f1,f2;
void work(int *A,int *ns,int &nh){
	for(int i=1;i<=n;i++) ns[++nh]=A[i];
	sort(ns+1,ns+nh+1);nh=unique(ns+1,ns+nh+1)-ns-1;
	for(int i=1;i<=n;i++) A[i]=LB(ns+1,ns+nh+1,A[i])-ns;
}
set<ll> f;
bool find(int x,int y){
	return f.find(1ll*x*INF+y)!=f.end();
}
int s1[N],h1,s2[N],h2;
void Solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&X[i],&Y[i]),X[i]*=2,Y[i]*=2;
	work(X,nx,xh);work(Y,ny,yh);
	set<int> g1,g2;
	int xm=-INF,ym=-INF,xi=INF,yi=INF;
	auto qryx=[](int l,int r){
		l=LB(nx+1,nx+xh+1,l)-nx;
		r=UB(nx+1,nx+xh+1,r)-nx-1;
		return f1.qry(r)-f1.qry(l-1);
	};
	auto qryy=[](int l,int r){
		l=LB(ny+1,ny+yh+1,l)-ny;
		r=UB(ny+1,ny+yh+1,r)-ny-1;
		return f2.qry(r)-f2.qry(l-1);
	};
	for(int i=1;i<=n;i++){
		f.insert(1ll*nx[X[i]]*INF+ny[Y[i]]);
		xm=max(xm,nx[X[i]]+ny[Y[i]]);
		xi=min(xi,nx[X[i]]+ny[Y[i]]);
		ym=max(ym,nx[X[i]]-ny[Y[i]]);
		yi=min(yi,nx[X[i]]-ny[Y[i]]);
		f1.add(X[i],1);f2.add(Y[i],1);
		g1.insert(nx[X[i]]);g2.insert(ny[Y[i]]);
		s1[++h1]=i;
		if(i==1){
			printf("0\n");
			continue;
		}
		h2=h1;copy(s1+1,s1+h1+1,s2+1);
		h1=0;
		int ps=i;
		int cnt=0;
		while(h2){
			int i=s2[h2--];
			int a=nx[X[i]],b=ny[Y[i]];
			int len=max(a+b-xi,xm-(a+b));
			len=max(len,ym-(a-b));
			len=max(len,(a-b)-yi);
			len/=2;
			int tot=0;
			tot+=qryx(-INF,nx[X[i]]-len)+qryx(nx[X[i]]+len,INF)+qryy(-INF,ny[Y[i]]-len)+qryy(ny[Y[i]]+len,INF);
			for(int x:{-len,len}) for(int y:{-len,len}) tot-=find(nx[X[i]]+x,ny[Y[i]]+y);
			gdb(ps,i,tot,len);
			if(tot^ps-1) continue;
			int ms=INF;
			auto it=g1.UB(nx[X[i]]-len);if(it!=g1.begin()) ms=min(ms,nx[X[i]]-*(--it));
			it=g1.LB(nx[X[i]]+len);if(it!=g1.end()) ms=min(ms,*it-nx[X[i]]);
			it=g2.UB(ny[Y[i]]-len);if(it!=g2.begin()) ms=min(ms,ny[Y[i]]-*(--it));
			it=g2.LB(ny[Y[i]]+len);if(it!=g2.end()) ms=min(ms,*it-ny[Y[i]]);
			if(ms^2*len) cnt+=find(a-ms,b+(2*len-ms))+find(a+ms,b+(2*len-ms));
			cnt+=find(a-ms,b-(2*len-ms));
			cnt+=find(a+ms,b-(2*len-ms));
			if(ms^len){
				cnt+=find(a-(2*len-ms),b-ms);
				cnt+=find(a-(2*len-ms),b+ms);
				if(ms^2*len) cnt+=find(a+(2*len-ms),b-ms)+find(a+(2*len-ms),b+ms);
			}
			s1[++h1]=i;
		}
		printf("%d\n",cnt);
	}
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10104kb

input:

2
1 5
1 10

output:

0
2

result:

ok 2 number(s): "0 2"

Test #2:

score: 0
Accepted
time: 2ms
memory: 12160kb

input:

4
2 5
5 3
5 7
8 5

output:

0
2
4
4

result:

ok 4 number(s): "0 2 4 4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 12180kb

input:

9
3 4
3 6
4 3
4 7
5 5
6 3
6 7
7 4
7 6

output:

0
2
1
0
4
5
6
7
8

result:

ok 9 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 12120kb

input:

13
3 5
4 4
4 5
4 6
5 3
5 4
5 5
5 6
5 7
6 4
6 5
6 6
7 5

output:

0
2
4
7
2
2
5
2
2
3
3
4
4

result:

ok 13 numbers

Test #5:

score: -100
Memory Limit Exceeded

input:

384010
200000 1000000
200000 1000001
199999 1000000
200001 1000000
200000 999999
200000 1000002
200002 1000000
200000 999998
199998 1000000
199997 1000000
200003 1000000
200000 999997
200000 1000003
199996 1000000
200004 1000000
200000 1000004
200000 999996
199995 1000000
200000 1000005
200000 99999...

output:

0
2
4
7
12
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result: