Repository navigation
Expand file tree
/
Copy pathStars.java
More file actions
53 lines (48 loc) · 1.32 KB
/
Copy pathStars.java
File metadata and controls
53 lines (48 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.text.*;
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;
import java.lang.reflect.Array;
public class Stars {
public static int[] table;
public static int sumQuery(int a, int b) {
return sumQuery(b) - sumQuery(a - 1);
}
public static int sumQuery(int k) {
int ret = 0;
while (k > 0) {
ret += table[k];
k &= k - 1;
}
return ret;
}
public static void adjust(int i) {
while (i < table.length) {
table[i] ++;
i += (i & (-i));
}
}
public static void main (String[] args)
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try
{
table = new int[32010];
int[] level = new int[32010];
int num = Integer.parseInt(in.readLine());
String[] some = null;
int x;
for(int i = 0; i < num; i++) {
some = in.readLine().split("\\s");
x = Integer.parseInt(some[0]) + 1;
level[sumQuery(x)]++;
adjust(x);
}
for(int i = 0; i < num; i++) {
System.out.println(level[i]);
}
} catch (IOException e)
{ e.printStackTrace(); }
}
}