AcWing 1265. 数星星——java
原题链接
中等
作者:
大猩猩吃月亮
,
2025-04-04 11:53:48
· 河北
,
所有人可见
,
阅读 1
import java.util.*;
import java.io.*;
public class Main {
static final int N = 32010;
static int[] tr = new int[N];
static int[] ans = new int[N];
static int n;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
n = Integer.valueOf(br.readLine());
for(int i = 0; i < n; i++) {
String[] s = br.readLine().split(" ");
int x = Integer.valueOf(s[0]);
int y = Integer.valueOf(s[1]);
x++;
ans[query(x)]++;
add(x);
}
for(int i = 0; i < n; i++) {
bw.write(ans[i] + "\n");
}
br.close();
bw.flush();
bw.close();
}
public static int lowbit(int x) {
return x & (-x);
}
public static void add(int x) {
for(int i = x; i < N; i += lowbit(i)) {
tr[i]++;
}
}
public static int query(int x) {
int res = 0;
for(int i = x; i > 0; i -= lowbit(i)) {
res += tr[i];
}
return res;
}
}