Problem Description
Jam like to solve the problem which on the 3D-axis,given
N(1≤N≤100000)
points
(x,y,z)(1≤x,y,z≤100000)
If two point such as (xi,yi,zi) and (xj,yj,zj) xi≥xj yi≥yj zi≥zj , the bigger one level add 1
Ask for the each level of the point.
If two point such as (xi,yi,zi) and (xj,yj,zj) xi≥xj yi≥yj zi≥zj , the bigger one level add 1
Ask for the each level of the point.
Input
The first line is
T(1≤T≤15)
means
T
Case
For each case
The first line is N means the number of Point and next there are N line, each line has (x,y,z)
For each case
The first line is N means the number of Point and next there are N line, each line has (x,y,z)
Output
Output with N line,each line has one number means the lever of point
Sample Input
1 4 10 4 7 10 6 6 8 2 5 7 3 10
Sample Output
1 1 0 0
省赛的一道题 二维的。
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 10010
#define MOD 1000000007
const int mod = 998244353;
int T,n,m,kk,q;
int a,b;
struct Node
{
int x,y,z;
int id;
} node[120000];
struct CC
{
int y,z,id;
CC() {}
CC(int y,int z,int id):y(y),z(z),id(id) {}
} tmp[120000];
int ans[120000];
bool cmp3(Node a,Node b)
{
if(a.x!=b.x) return a.x<b.x;
if(a.y!=b.y) return a.y<b.y;
return a.z<b.z;
}
bool cmp(int i,int j)
{
if(node[i].x!=node[j].x) return 0;
if(node[i].y!=node[j].y) return 0;
if(node[i].z!=node[j].z) return 0;
return 1;
}
bool cmp2(CC a,CC b)
{
if(a.y!=b.y) return a.y<b.y;
else return a.id<b.id;
}
int nn;
int c[120000];
int lowbit(int x){return x&(-x);}
void add(int x,int val)
{
while(x<=nn)
{
c[x] += val;
x +=lowbit(x);
}
}
int sum(int x)
{
int re=0;
while(x)
{
re+=c[x];
x -=lowbit(x);
}
return re;
}
void cdq(int l,int r)
{
if(l==r) return ;
int mid = (l+r)/2;
int cnt=0;
for(int i=l; i<=mid; i++) tmp[cnt++] = CC(node[i].y,node[i].z,0);
for(int i=mid+1; i<=r; i++) tmp[cnt++] = CC(node[i].y,node[i].z,node[i].id);
sort(tmp,tmp+cnt,cmp2);
for(int i=0; i<cnt; i++)
{
if(tmp[i].id==0)
{
add(tmp[i].z,1);
}
else ans[tmp[i].id] += sum(tmp[i].z);
}
for(int i=0; i<cnt; i++)
if(tmp[i].id==0) add(tmp[i].z,-1);
cdq(l,mid);
cdq(mid+1,r);
}
int main()
{
memset(c,0,sizeof(c));
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
nn=0;
for(int i=1; i<=n; i++)
{
scanf("%d%d%d",&node[i].x,&node[i].y,&node[i].z);
node[i].id=i;
nn = max(nn,node[i].z);
}
nn++;
sort(node+1,node+1+n,cmp3);
int cnt=0;
ans[node[n].id]=0;
for(int i=n-1; i>=1; i--)
{
if(cmp(i,i+1)) cnt++;
else cnt=0;
ans[node[i].id]=cnt;
}
cdq(1,n);
for(int i=1; i<=n; i++)
printf("%d\n",ans[i]);
}
return 0;
}