# 10114 "through a 2 4.1 cases of" Number the Stars Stars

1536: [Example 2] Number of stars Stars


Time limit: 256 ms Memory Limit: 65536 KB
Submissions: 630 number by: 282 

Description [title]

From the original title: Ural 1028

There are some stars in the sky, the stars were in different positions, each star has a coordinate. If a lower left star (comprising positive and positive at left) with a  K K stars, this star is said  K K level.

For example, the figure above the stars  . 53 3 levels ( 1 , 2 , 4 , 2,4 at its lower left), stars  2 , 4 , 4 is  a stage 1. FIG embodiment there are  10 0, 21 Level 1, 12 level 2, 13 3 level stars.

Position of a given star, the number of output levels of stars.

A topic meaning: Given  the n- the n-points, the definition of each rating point is the point at the bottom left (including being left, directly below) the number of points, the test statistics for each level the number of points.

[Enter]

A first line integer  N N, represents the number of stars;

Next  N N gives the coordinates of each line of stars, with the coordinates of two integers  X , Y X, Y represents;

There will be no overlap stars. Star Press  Y Y coordinate increasing order given, Y Y coordinate of the same according to  x are given in order of increasing x-coordinate.

[Output]

N N lines, each an integer, respectively,  0 0, 1 Level 1, 2 stage 2, ......, N - 1 number of stars in the level N-1.

[Sample input]

5
1 1
5 1
7 1
3 3
5 5

[Sample Output]

1
2
1
1
0

【prompt】

Data range and tips:

For all data, . 1 N for 1.5 × 10 . 4 , 0 X , Y 3.2 × 10 . 4 1≤N≤1.5 104,0≤x ×, 104 × y≤3.2.

【source】


no

 

#include<bits/stdc++.h>
using namespace std;
int a[15005],sum[32005];
int n,m=32001;
int lowbit(int x){return x&(-x);}
void update(int x){
    for(;x<=m;x+=lowbit(x))sum[x]++;
}
void to(int x){
    int res=0;
    for(;x>0;x-=lowbit(x))res+=sum[x];
    a[res]++;
}
int main(){
    //freopen("test.in","r",stdin);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        to(x+1);update(x+1);
    }
    for(int i=0;i<n;i++)printf("%d\n",a[i]);
    return 0;
}

 

 

 

Guess you like

Origin www.cnblogs.com/fdezlsq/p/11432274.html