git reimport
This commit is contained in:
79
archive/2017.09/2017.09.18 - unsorted/B.java
Normal file
79
archive/2017.09/2017.09.18 - unsorted/B.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class B extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
// int[] a = in.nextIntArray(n);
|
||||
|
||||
List<int[]> a = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int t = in.nextInt();
|
||||
|
||||
a.add(new int[]{t, i});
|
||||
}
|
||||
|
||||
a.sort((o1, o2) -> Integer.compare(o1[0], o2[0]));
|
||||
Collections.reverse(a);
|
||||
|
||||
int max = -1;
|
||||
int c = 0;
|
||||
|
||||
TreeMap<Integer, Integer> map = new TreeMap<>();
|
||||
int[] b = new int[n];
|
||||
|
||||
List<List<Integer>> lists = new ArrayList<>();
|
||||
|
||||
for (int[] i : a) {
|
||||
int element = i[0];
|
||||
int index = i[1];
|
||||
|
||||
Integer next = map.ceilingKey(index);
|
||||
|
||||
if (next == null) {
|
||||
map.put(index, c);
|
||||
|
||||
lists.add(new ArrayList<>());
|
||||
lists.get(c).add(element);
|
||||
|
||||
c++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
int t = map.get(next);
|
||||
lists.get(t).add(element);
|
||||
map.put(index, t);
|
||||
map.remove(next);
|
||||
}
|
||||
|
||||
for (List<Integer> list : lists) {
|
||||
Collections.sort(list);
|
||||
|
||||
for (Integer integer : list) {
|
||||
out.print(integer + " ");
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user