-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGukiZAndContest.java
More file actions
36 lines (32 loc) · 882 Bytes
/
GukiZAndContest.java
File metadata and controls
36 lines (32 loc) · 882 Bytes
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
/* https://codeforces.com/contest/551/problem/A
#implementation #sorting #binary-search
*/
import java.util.Arrays;
import java.util.Scanner;
public class GukiZAndContest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] orgArr = new int[n];
int[] sortedArr = new int[n];
for (int i = 0; i < n; i++) {
int temp = sc.nextInt();
orgArr[i] = temp;
sortedArr[i] = temp;
}
Arrays.sort(sortedArr);
for (int i = 0; i < n; i++) {
int idx = Arrays.binarySearch(sortedArr, orgArr[i]);
int lastIdx = idx;
while (idx >= 0) {
lastIdx = idx;
idx = Arrays.binarySearch(sortedArr, idx + 1, n, orgArr[i]);
}
orgArr[i] = n - lastIdx;
}
for (int i : orgArr) {
System.out.print(i + " ");
}
System.out.println();
}
}