Submission #2633521
Source Code Expand
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class Main { int n; Person[] persons; public static void main(String args[]) { new Main().run(); } void run() { FastReader sc = new FastReader(); n = sc.nextInt(); persons = new Person[n]; for (int i = 0; i < n; i++) { int s = sc.nextInt(); int t = sc.nextInt(); persons[i] = new Person(s, t, i); } solve(); } void solve() { Arrays.sort(persons, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { return o1.s - o2.s; } }); int[] ss = new int[n]; for (int i = 0; i < n; i++) { ss[i] = persons[i].s; } for (int i = 0; i < n; i++) { int tIndex = lower_bound(ss, i, n - 1, persons[i].t); persons[i].num = tIndex - i - 1; } Arrays.sort(persons, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { return o1.index - o2.index; } }); for (int i = 0; i < n; i++) { System.out.println(persons[i].num); } } class Person { int s; int t; int index; int num; public Person(int s, int t, int index) { this.s = s; this.t = t; this.index = index; num = 0; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } } static int lower_bound(int[] arr, int beginIndex, int endIndex, int key) { int low = beginIndex; int high = endIndex; while (high - low >= 0) { int mid = (low + high) / 2; if (key <= arr[mid]) { high = mid - 1; } else { low = mid + 1; } } return low; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Submission Info
Submission Time | |
---|---|
Task | B - How are you? |
User | ynish |
Language | Java8 (OpenJDK 1.8.0) |
Score | 100 |
Code Size | 3484 Byte |
Status | AC |
Exec Time | 1099 ms |
Memory | 50508 KB |
Judge Result
Set Name | Sample | Dataset1 | Dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 30 / 30 | 70 / 70 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt |
Dataset1 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
Dataset2 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 70 ms | 19284 KB |
01-02.txt | AC | 71 ms | 21460 KB |
01-03.txt | AC | 70 ms | 20948 KB |
01-04.txt | AC | 71 ms | 19028 KB |
01-05.txt | AC | 79 ms | 19540 KB |
01-06.txt | AC | 114 ms | 22100 KB |
01-07.txt | AC | 144 ms | 19796 KB |
01-08.txt | AC | 127 ms | 20180 KB |
01-09.txt | AC | 139 ms | 21972 KB |
01-10.txt | AC | 141 ms | 18388 KB |
02-01.txt | AC | 140 ms | 19284 KB |
02-02.txt | AC | 197 ms | 22228 KB |
02-03.txt | AC | 653 ms | 49560 KB |
02-04.txt | AC | 1076 ms | 47460 KB |
02-05.txt | AC | 1045 ms | 47324 KB |
02-06.txt | AC | 1099 ms | 50508 KB |
02-07.txt | AC | 985 ms | 47136 KB |
sample-01.txt | AC | 70 ms | 18516 KB |
sample-02.txt | AC | 70 ms | 20180 KB |