🤠 原题地址
🥚 输入样例
5
1 1
5 1
7 1
3 3
5 5
🥚 输出样例
1
2
1
1
0
⭐ 缓冲流解决输入输出慢的问题
⭐ 由于单调输入,二维可转一维,降维打击
👨🏫 题目的 x 是从 0 开始的,但数组数组的下标得从 1 开始!安排:每个 x + 1
import java.util.*;
import java.io.*;
public class Main
{
static int N = 32010;
static int[] a = new int[N];
static int[] tr = new int[N];
static int[] level = new int[N];
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
static int lowbit(int x)
{
return x & -x;
}
static void add(int x, int v)
{
for (int i = x; i < N; i += lowbit(i))
{
tr[i] += v;
}
}
static int query(int x)
{
int res = 0;
for (int i = x; i > 0; i -= lowbit(i))
res += tr[i];
return res;
}
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(in.readLine());
for (int i = 0; i < n; i++)
{
// 题目保证了星星的坐标是按 x、y 轴增序输入的,所以在 x 左方的一定是在 y 轴下方的
String[] ss = in.readLine().split(" ");
int x = Integer.parseInt(ss[0])+1;
int y = Integer.parseInt(ss[1]);
level[query(x)]++;
add(x, 1);
}
for (int i = 0; i < n; i++)
out.write(level[i]+"\n");
out.flush();
}
}