結果

問題 No.759 悪くない忘年会にしような!
ユーザー uwiuwi
提出日時 2018-12-07 00:12:26
言語 Java11
(openjdk 11.0.7)
結果
AC  
実行時間 830 ms / 2,000 ms
コード長 6,929 Byte
コンパイル時間 4,288 ms
使用メモリ 41,612 KB
最終ジャッジ日時 2020-07-01 20:29:15

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 83 ms
22,444 KB
testcase_01 AC 82 ms
22,420 KB
testcase_02 AC 83 ms
22,460 KB
testcase_03 AC 84 ms
22,444 KB
testcase_04 AC 83 ms
22,460 KB
testcase_05 AC 83 ms
22,456 KB
testcase_06 AC 83 ms
22,452 KB
testcase_07 AC 82 ms
22,456 KB
testcase_08 AC 82 ms
22,420 KB
testcase_09 AC 81 ms
22,452 KB
testcase_10 AC 82 ms
22,452 KB
testcase_11 AC 82 ms
22,408 KB
testcase_12 AC 85 ms
22,468 KB
testcase_13 AC 83 ms
22,452 KB
testcase_14 AC 82 ms
22,424 KB
testcase_15 AC 82 ms
22,460 KB
testcase_16 AC 82 ms
22,408 KB
testcase_17 AC 83 ms
22,460 KB
testcase_18 AC 82 ms
22,460 KB
testcase_19 AC 96 ms
22,352 KB
testcase_20 AC 83 ms
22,424 KB
testcase_21 AC 82 ms
22,404 KB
testcase_22 AC 83 ms
22,416 KB
testcase_23 AC 82 ms
22,412 KB
testcase_24 AC 82 ms
22,432 KB
testcase_25 AC 82 ms
22,452 KB
testcase_26 AC 82 ms
22,416 KB
testcase_27 AC 83 ms
22,452 KB
testcase_28 AC 83 ms
22,432 KB
testcase_29 AC 88 ms
22,324 KB
testcase_30 AC 85 ms
22,428 KB
testcase_31 AC 85 ms
22,436 KB
testcase_32 AC 93 ms
22,456 KB
testcase_33 AC 158 ms
24,020 KB
testcase_34 AC 107 ms
22,688 KB
testcase_35 AC 147 ms
23,340 KB
testcase_36 AC 157 ms
23,968 KB
testcase_37 AC 113 ms
22,784 KB
testcase_38 AC 165 ms
24,188 KB
testcase_39 AC 117 ms
22,824 KB
testcase_40 AC 148 ms
23,724 KB
testcase_41 AC 152 ms
23,876 KB
testcase_42 AC 163 ms
24,236 KB
testcase_43 AC 171 ms
27,800 KB
testcase_44 AC 817 ms
41,568 KB
testcase_45 AC 817 ms
41,536 KB
testcase_46 AC 828 ms
41,604 KB
testcase_47 AC 808 ms
41,612 KB
testcase_48 AC 822 ms
41,588 KB
testcase_49 AC 179 ms
27,780 KB
testcase_50 AC 169 ms
27,776 KB
testcase_51 AC 174 ms
27,808 KB
testcase_52 AC 177 ms
27,792 KB
testcase_53 AC 810 ms
41,588 KB
testcase_54 AC 810 ms
41,592 KB
testcase_55 AC 802 ms
41,564 KB
testcase_56 AC 829 ms
41,576 KB
testcase_57 AC 812 ms
41,576 KB
testcase_58 AC 811 ms
41,584 KB
testcase_59 AC 830 ms
41,544 KB
testcase_60 AC 818 ms
41,572 KB
testcase_61 AC 819 ms
41,604 KB
testcase_62 AC 821 ms
41,608 KB
testcase_63 AC 459 ms
35,160 KB
testcase_64 AC 479 ms
35,560 KB
testcase_65 AC 371 ms
31,904 KB
testcase_66 AC 459 ms
35,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
package adv2018;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.List;

public class Day7 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		int[][] ss = new int[n][];
		for(int i = 0;i < n;i++) {
			ss[i] = new int[] {ni(), ni(), ni(), i+1};
		}
		
		List<Integer> ans = new ArrayList<>();
		StaticRangeTreeRSQ srt = new StaticRangeTreeRSQ(ss, 10001);
		Arrays.sort(ss, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				if(a[2] != b[2])return -(a[2] - b[2]);
				if(a[1] != b[1])return -(a[1] - b[1]);
				return -(a[0] - b[0]);
			}
		});
		for(int i = 0;i < n;i++) {
			if(i > 0 && ss[i][0] == ss[i-1][0] && ss[i][1]  == ss[i-1][1] && ss[i][2] == ss[i-1][2]) {
				ans.add(ss[i][3]);
				continue;
			}
			if(srt.sum(ss[i][0], 10001, ss[i][1], 10001) == 0) {
				ans.add(ss[i][3]);
			}
			srt.add(ss[i][0], ss[i][1], 1);
		}
		Collections.sort(ans);
		for(int v : ans) {
			out.println(v);
		}
	}
	
	public static class StaticRangeTreeRSQ {
		public int M, H, N;
		public int[][] fts;
		public int[][] maps;
		public int[] count;
		public int I = Integer.MAX_VALUE;
		
		/**
		 * @param co DESTRUCTIVE
		 * @param n limit of coordinate
		 */
		public StaticRangeTreeRSQ(int[][] co, int n)
		{
			N = n;
			M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
			H = M>>>1;
			
			Arrays.sort(co, new Comparator<int[]>() { // x asc
				public int compare(int[] a, int[] b) {
					if(a[0] != b[0])return a[0] - b[0];
					return a[1] - b[1];
				}
			});
			maps = new int[M][];
			fts = new int[M][];
			count = new int[M];
			for(int i = 0;i < co.length;i++){
				count[H+co[i][0]]++;
			}
			int off = 0;
			for(int i = 0;i < n;i++){
				maps[H+i] = new int[count[H+i]];
				for(int j = 0;j < count[H+i];j++,off++){
					maps[H+i][j] = co[off][1];
				}
				fts[H+i] = new int[count[H+i]+1];
			}
			
			for(int i = H-1;i >= 1;i--){
				if(maps[2*i+1] == null){
					maps[i] = maps[2*i];
					count[i] = count[2*i];
				}else{
					count[i] = count[2*i] + count[2*i+1];
					maps[i] = new int[count[i]];
					int l = 0;
					int j = 0, k = 0;
					while(j < count[2*i] && k < count[2*i+1]){
						if(maps[2*i][j] < maps[2*i+1][k]){
							maps[i][l++] = maps[2*i][j++];
						}else if(maps[2*i][j] > maps[2*i+1][k]){
							maps[i][l++] = maps[2*i+1][k++];
						}else{
							maps[i][l++] = maps[2*i][j++];
							k++;
						}
					}
					while(j < count[2*i])maps[i][l++] = maps[2*i][j++];
					while(k < count[2*i+1])maps[i][l++] = maps[2*i+1][k++];
					if(l != count[i]){ // uniq
						count[i] = l;
						maps[i] = Arrays.copyOf(maps[i], l);
					}
				}
				fts[i] = new int[count[i]+1];
			}
		}
		
		public void add(int x, int y, int v)
		{
			for(int pos = H+x;pos >= 1;pos>>>=1){
				int ind = Arrays.binarySearch(maps[pos], y);
				if(ind >= 0){
					addFenwick(fts[pos], ind, v);
				}else{
					throw new RuntimeException(String.format("access to non-existing point : (%d,%d):%d", x, y, v));
				}
			}
		}
		
		public long gsum;
		
		// [xl,xr)*[yl,yr)
		public long sum(int xl, int xr, int yl, int yr) { 
			gsum = 0;
			sum(xl, xr, yl, yr, 0, H, 1);
			return gsum;
		}
		
		public void sum(int xl, int xr, int yl, int yr, int cl, int cr, int cur)
		{
			if(xl <= cl && cr <= xr){
				int indl = Arrays.binarySearch(maps[cur], yl-1);
				int indr = Arrays.binarySearch(maps[cur], yr-1);
				if(indl < 0)indl = -indl - 2;
				if(indr < 0)indr = -indr - 2;
				gsum += sumFenwick(fts[cur], indr) - sumFenwick(fts[cur], indl);
			}else{
				int mid = cl+cr>>>1;
				if(cl < xr && xl < mid)sum(xl, xr, yl, yr, cl, mid, 2*cur);
				if(mid < xr && xl < cr)sum(xl, xr, yl, yr, mid, cr, 2*cur+1);
			}
		}
		
		public static int sumFenwick(int[] ft, int i)
		{
			int sum = 0;
			for(i++;i > 0;i -= i&-i)sum += ft[i];
			return sum;
		}
		
		public static void addFenwick(int[] ft, int i, int v)
		{
			if(v == 0 || i < 0)return;
			int n = ft.length;
			for(i++;i < n;i += i&-i)ft[i] += v;
		}
	}

	
	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//		Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){
//			@Override
//			public void run() {
//				long s = System.currentTimeMillis();
//				solve();
//				out.flush();
//				if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//			}
//		};
//		t.start();
//		t.join();
	}
	
	public static void main(String[] args) throws Exception { new Day7().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i = 0;i < n;i++)a[i] = nl();
		return a;
	}
	
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[][] nmi(int n, int m) {
		int[][] map = new int[n][];
		for(int i = 0;i < n;i++)map[i] = na(m);
		return map;
	}
	
	private int ni() { return (int)nl(); }
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}
0