結果

問題 No.759 悪くない忘年会にしような!
ユーザー 37zigen37zigen
提出日時 2018-12-07 02:40:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 835 ms / 2,000 ms
コード長 3,450 bytes
コンパイル時間 5,070 ms
コンパイル使用メモリ 75,012 KB
実行使用メモリ 67,568 KB
最終ジャッジ日時 2023-10-12 03:29:12
合計ジャッジ時間 20,455 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,356 KB
testcase_01 AC 45 ms
49,256 KB
testcase_02 AC 45 ms
49,364 KB
testcase_03 AC 44 ms
49,192 KB
testcase_04 AC 45 ms
49,464 KB
testcase_05 AC 45 ms
47,168 KB
testcase_06 AC 44 ms
47,352 KB
testcase_07 AC 46 ms
49,288 KB
testcase_08 AC 45 ms
49,656 KB
testcase_09 AC 45 ms
49,420 KB
testcase_10 AC 45 ms
49,320 KB
testcase_11 AC 44 ms
49,192 KB
testcase_12 AC 45 ms
49,332 KB
testcase_13 AC 44 ms
49,316 KB
testcase_14 AC 44 ms
49,248 KB
testcase_15 AC 45 ms
49,804 KB
testcase_16 AC 44 ms
49,232 KB
testcase_17 AC 44 ms
49,296 KB
testcase_18 AC 46 ms
49,492 KB
testcase_19 AC 43 ms
49,280 KB
testcase_20 AC 44 ms
49,316 KB
testcase_21 AC 45 ms
49,360 KB
testcase_22 AC 44 ms
49,392 KB
testcase_23 AC 44 ms
49,504 KB
testcase_24 AC 44 ms
49,560 KB
testcase_25 AC 44 ms
49,248 KB
testcase_26 AC 44 ms
49,188 KB
testcase_27 AC 43 ms
49,404 KB
testcase_28 AC 44 ms
49,456 KB
testcase_29 AC 44 ms
49,316 KB
testcase_30 AC 45 ms
49,528 KB
testcase_31 AC 45 ms
49,372 KB
testcase_32 AC 44 ms
49,788 KB
testcase_33 AC 112 ms
52,692 KB
testcase_34 AC 61 ms
50,996 KB
testcase_35 AC 96 ms
52,528 KB
testcase_36 AC 113 ms
52,700 KB
testcase_37 AC 66 ms
51,844 KB
testcase_38 AC 115 ms
52,760 KB
testcase_39 AC 68 ms
51,220 KB
testcase_40 AC 111 ms
52,636 KB
testcase_41 AC 112 ms
52,704 KB
testcase_42 AC 121 ms
51,404 KB
testcase_43 AC 121 ms
52,596 KB
testcase_44 AC 387 ms
60,016 KB
testcase_45 AC 402 ms
59,828 KB
testcase_46 AC 403 ms
61,976 KB
testcase_47 AC 390 ms
60,212 KB
testcase_48 AC 369 ms
59,616 KB
testcase_49 AC 126 ms
53,180 KB
testcase_50 AC 130 ms
52,380 KB
testcase_51 AC 131 ms
53,104 KB
testcase_52 AC 132 ms
52,640 KB
testcase_53 AC 392 ms
60,268 KB
testcase_54 AC 400 ms
60,232 KB
testcase_55 AC 396 ms
60,080 KB
testcase_56 AC 372 ms
59,636 KB
testcase_57 AC 373 ms
59,512 KB
testcase_58 AC 353 ms
60,004 KB
testcase_59 AC 402 ms
59,796 KB
testcase_60 AC 352 ms
59,660 KB
testcase_61 AC 407 ms
59,988 KB
testcase_62 AC 424 ms
59,932 KB
testcase_63 AC 835 ms
65,484 KB
testcase_64 AC 826 ms
66,100 KB
testcase_65 AC 399 ms
60,072 KB
testcase_66 AC 785 ms
67,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		int[] P = new int[N];
		int[] T = new int[N];
		int[] R = new int[N];
		int[][] a = new int[N][];
		for (int i = 0; i < N; ++i) {
			P[i] = sc.nextInt();
			T[i] = sc.nextInt();
			R[i] = sc.nextInt();
			a[i] = new int[] { P[i], T[i], R[i], i };
		}
		Arrays.sort(a, new Comparator<int[]>() {
			public int compare(int[] o1, int[] o2) {
				if (o1[0] != o2[0]) {
					return -Integer.compare(o1[0], o2[0]);
				} else if (o1[1] != o2[1]) {
					return -Integer.compare(o1[1], o2[1]);
				} else {
					return -Integer.compare(o1[2], o2[2]);
				}
			}
		});
		boolean[] ok = new boolean[N];
		Arrays.fill(ok, true);
		RMQ rmq = new RMQ(10000 + 1);
		for (int i = 0; i < N; ++i) {
			if (rmq.query(a[i][1], 10000 + 1) >= a[i][2]) {
				ok[a[i][3]] = false;
			}
			rmq.update(a[i][1], a[i][2]);
		}
		for (int i = 0; i < N; ++i) {
			if (ok[i])
				System.out.println(i + 1);
		}
	}

	class RMQ {
		int n;
		int[] v;

		public RMQ(int n_) {
			n = 1;
			while (n < n_)
				n *= 2;
			v = new int[2 * n - 1];
			Arrays.fill(v, -1);
		}

		void update(int k, int val) {
			k += n - 1;
			v[k] = Math.max(v[k], val);
			while (k > 0) {
				k = (k - 1) / 2;
				v[k] = Math.max(v[2 * k + 1], v[2 * k + 2]);
			}
		}

		int query(int a, int b) {
			return query(a, b, 0, n, 0);
		}

		int query(int a, int b, int l, int r, int k) {
			if (a <= l && r <= b)
				return v[k];
			else if (b <= l || r <= a)
				return -1;
			else {
				int vl = query(a, b, l, (l + r) / 2, 2 * k + 1);
				int vr = query(a, b, (l + r) / 2, r, 2 * k + 2);
				return Math.max(vl, vr);
			}
		}
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}

class Scanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}
}
0