|
| 1 | +```java |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +import java.io.*; |
| 5 | + |
| 6 | +class Main { |
| 7 | + |
| 8 | + // IO field |
| 9 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 11 | + static StringTokenizer st; |
| 12 | + |
| 13 | + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} |
| 14 | + static int nextInt() {return Integer.parseInt(st.nextToken());} |
| 15 | + static long nextLong() {return Long.parseLong(st.nextToken());} |
| 16 | + static void bwEnd() throws Exception {bw.flush();bw.close();} |
| 17 | + |
| 18 | + // Additional field |
| 19 | + static int N, M; |
| 20 | + static List<int[]> arr; |
| 21 | + static boolean[] del; |
| 22 | + |
| 23 | + public static void main(String[] args) throws Exception { |
| 24 | + |
| 25 | + ready(); |
| 26 | + solve(); |
| 27 | + |
| 28 | + bwEnd(); |
| 29 | + } |
| 30 | + |
| 31 | + static void ready() throws Exception{ |
| 32 | + |
| 33 | + N = Integer.parseInt(br.readLine()); |
| 34 | + M = Integer.parseInt(br.readLine()); |
| 35 | + arr = new ArrayList<>(); |
| 36 | + del = new boolean[M+1]; |
| 37 | + for(int i=1;i<=M;i++) { |
| 38 | + nextLine(); |
| 39 | + int a = nextInt(), b = nextInt(); |
| 40 | + if(a < b) { |
| 41 | + arr.add(new int[] {a,b,i}); |
| 42 | + arr.add(new int[] {N+a,N+b,i}); |
| 43 | + } |
| 44 | + else { |
| 45 | + arr.add(new int[] {a,N+b,i}); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + static void solve() throws Exception{ |
| 52 | + |
| 53 | + Collections.sort(arr, (a,b) -> { |
| 54 | + if(a[0] == b[0]) return b[1]-a[1]; |
| 55 | + return a[0]-b[0]; |
| 56 | + }); |
| 57 | + |
| 58 | + int mx = 0; |
| 59 | + for(int[] now : arr) { |
| 60 | + int l = now[0], r = now[1], x = now[2]; |
| 61 | + if(r<=mx) del[x] = true; |
| 62 | + else mx = r; |
| 63 | + } |
| 64 | + for(int i=1;i<=M;i++) if(!del[i]) bw.write(i + " "); |
| 65 | + |
| 66 | + |
| 67 | + } |
| 68 | + |
| 69 | +} |
| 70 | + |
| 71 | +``` |
0 commit comments