CF576C Points on Plane

IV.CF576C Points on Plane

实际上跟莫队关系不大,但是注意到平面上两点间曼哈顿距离就等价于莫队上从一个状态到另一个状态时左右端点移动次数。于是直接莫队式排序即可。

代码:

#include<bits/stdc++.h>
using namespace std;
const int BBB=1000;
int n;
struct node{
	int x,y,id;
	friend bool operator<(const node&u,const node&v){
		if(u.x/BBB!=v.x/BBB)return u.x<v.x;
		return (u.x/BBB)&1?u.y<v.y:u.y>v.y;
	}
}p[1001000];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y),p[i].id=i;
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++)printf("%d ",p[i].id);
	return 0;
}

posted @ 2021-04-06 10:05  Troverld  阅读(43)  评论(0编辑  收藏  举报