Jam's problem again (找比点少的值)

Problem Description
Jam like to solve the problem which on the 3D-axis,given  N(1N100000)  points  (x,y,z)(1x,y,z100000)

If two point such as  (xi,yi,zi)  and  (xj,yj,zj) xixj yiyj zizj , the bigger one level add  1

Ask for the each level of the point.
 

Input
The first line is  T(1T15)  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)
 

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;
}























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值