結果

問題 No.1014 competitive fighting
ユーザー uwiuwi
提出日時 2020-03-20 23:03:38
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 8,174 bytes
コンパイル時間 4,340 ms
コンパイル使用メモリ 90,232 KB
実行使用メモリ 83,816 KB
最終ジャッジ日時 2024-12-15 08:11:24
合計ジャッジ時間 32,400 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
50,712 KB
testcase_01 AC 52 ms
50,384 KB
testcase_02 AC 55 ms
50,708 KB
testcase_03 AC 54 ms
50,628 KB
testcase_04 AC 56 ms
50,348 KB
testcase_05 AC 978 ms
80,724 KB
testcase_06 AC 947 ms
80,492 KB
testcase_07 AC 973 ms
81,068 KB
testcase_08 AC 933 ms
82,408 KB
testcase_09 AC 1,000 ms
79,992 KB
testcase_10 AC 254 ms
64,968 KB
testcase_11 AC 731 ms
78,560 KB
testcase_12 AC 889 ms
79,964 KB
testcase_13 AC 432 ms
65,568 KB
testcase_14 AC 428 ms
66,112 KB
testcase_15 AC 459 ms
66,232 KB
testcase_16 AC 97 ms
52,000 KB
testcase_17 AC 256 ms
59,036 KB
testcase_18 AC 692 ms
68,132 KB
testcase_19 AC 912 ms
80,276 KB
testcase_20 AC 356 ms
63,252 KB
testcase_21 AC 675 ms
67,356 KB
testcase_22 AC 555 ms
67,928 KB
testcase_23 AC 290 ms
58,704 KB
testcase_24 AC 297 ms
58,744 KB
testcase_25 AC 158 ms
54,320 KB
testcase_26 AC 619 ms
68,128 KB
testcase_27 AC 253 ms
58,748 KB
testcase_28 AC 272 ms
59,180 KB
testcase_29 AC 89 ms
50,756 KB
testcase_30 AC 964 ms
80,680 KB
testcase_31 AC 682 ms
67,220 KB
testcase_32 AC 72 ms
50,948 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 AC 947 ms
80,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		int[][] rs = new int[n][];
		for(int i = 0;i < n;i++){
			rs[i] = new int[]{ni(), ni(), ni(), i};
		}
		Arrays.sort(rs, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});
		
		int[][] es = new int[2*n][];
		for(int i = 0;i < n;i++){
			es[i] = new int[]{rs[i][0], rs[i][1] - rs[i][2], 1, i};
			es[i+n] = new int[]{rs[i][1] - rs[i][2], rs[i][0], 0, i};
		}
		Arrays.sort(es, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				if(a[0] != b[0])return -(a[0] - b[0]);
				return a[2] - b[2];
			}
		});
		int miny = Integer.MAX_VALUE;
		int miny2 = Integer.MAX_VALUE;
		boolean[] ban = new boolean[n];
		for(int i = 0;i < 2*n;i++){
			int[] e = es[i];
			if(e[2] == 0){
				if(e[1] < miny){
					miny2 = miny;
					miny = e[1];
				}else if(e[1] < miny2){
					miny2 = e[1];
				}
			}else{
				int ng = e[0];
				int y = miny == ng ? miny2 : miny;
//				tr(e, y);
				if(y <= e[1]){
					ban[e[3]] = true;
				}
			}
		}
		int amin = Integer.MAX_VALUE;
		for(int i = 0;i < n;i++){
			if(ban[i]){
				amin = Math.min(amin, rs[i][0]);
			}
		}
		for(int i = 0;i < n;i++){
			if(rs[i][1] - rs[i][2] >= amin){
				ban[i] = true;
			}
		}
		
		es = new int[2*n][];
		int p = 0;
		for(int i = 0;i < n;i++){
			if(ban[i])continue;
			es[p++] = new int[]{rs[i][0], 0, i, rs[i][1] - rs[i][2]};
			es[p++] = new int[]{rs[i][1] - rs[i][2], 1, i, rs[i][0]};
		}
		es = Arrays.copyOf( es, p);
		
		int[] xs = new int[2*p];
		for(int i = 0;i < p;i++){
			xs[i] = es[i][0]+1000000000;
			xs[i+p] = es[i][3]+1000000000;
		}
		shrinkX(xs);
		for(int i = 0;i < p;i++){
			es[i][0] = xs[i];
			es[i][3] = xs[i+p];
		}
		
		Arrays.sort(es, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				if(a[0] != b[0])return a[0] - b[0];
				if(a[2] != b[2])return a[2] - b[2];
				return a[1] - b[1];
			}
		});
		
		long[] anss = new long[n];
		SegmentTreeRMQL st = new SegmentTreeRMQL(n);
		for(int[] e : es){
			if(e[1] == 1){
				if(rs[e[2]][0] > rs[e[2]][1] - rs[e[2]][2]){
					anss[e[2]] = rs[e[2]][1] - Math.min(0, st.minx(0, e[0]+1));
					st.update(e[3], -anss[e[2]]);
				}
			}else{
				if(rs[e[2]][0] <= rs[e[2]][1] - rs[e[2]][2]){
					anss[e[2]] = rs[e[2]][1] - Math.min(0, st.minx(0, e[3]+1));
					st.update(e[0], -anss[e[2]]);
				}
			}
		}
		
		String[] rets = new String[n];
		for(int i = 0;i < n;i++){
			if(ban[i]){
				rets[rs[i][3]] = "BAN";
			}else{
				rets[rs[i][3]] = "" + anss[i];
			}
		}
		for(String ret : rets){
			out.println(ret);
		}
	}
	
	public static int[] shrinkX(int[] a) {
		int n = a.length;
		if(n == 0)return new int[0];
		long[] b = new long[n];
		for (int i = 0; i < n; i++)
			b[i] = (long) a[i] << 32 | i;
		Arrays.sort(b);
		int[] ret = new int[n];
		int p = 0;
		ret[0] = (int) (b[0] >> 32);
		for (int i = 0; i < n; i++) {
			if (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) {
				p++;
				ret[p] = (int) (b[i] >> 32);
			}
			a[(int) b[i]] = p;
		}
		return Arrays.copyOf(ret, p + 1);
	}
	
	public static class SegmentTreeRMQL {
		public int M, H, N;
		public long[] st;
		
		public SegmentTreeRMQL(int n)
		{
			N = n;
			M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
			H = M>>>1;
			st = new long[M];
			Arrays.fill(st, 0, M, Long.MAX_VALUE);
		}
		
		public SegmentTreeRMQL(long[] a)
		{
			N = a.length;
			M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
			H = M>>>1;
			st = new long[M];
			for(int i = 0;i < N;i++){
				st[H+i] = a[i];
			}
			Arrays.fill(st, H+N, M, Long.MAX_VALUE);
			for(int i = H-1;i >= 1;i--)propagate(i);
		}
		
		public void update(int pos, long x)
		{
			st[H+pos] = Math.min(x, st[H+pos]);
			for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);
		}
		
		private void propagate(int i)
		{
			st[i] = Math.min(st[2*i], st[2*i+1]);
		}
		
		public long minx(int l, int r){
			long min = Long.MAX_VALUE;
			if(l >= r)return min;
			while(l != 0){
				int f = l&-l;
				if(l+f > r)break;
				long v = st[(H+l)/f];
				if(v < min)min = v;
				l += f;
			}
			
			while(l < r){
				int f = r&-r;
				long v = st[(H+r)/f-1];
				if(v < min)min = v;
				r -= f;
			}
			return min;
		}
		
		public long min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}
		
		private long min(int l, int r, int cl, int cr, int cur)
		{
			if(l <= cl && cr <= r){
				return st[cur];
			}else{
				int mid = cl+cr>>>1;
				long ret = Long.MAX_VALUE;
				if(cl < r && l < mid){
					ret = Math.min(ret, min(l, r, cl, mid, 2*cur));
				}
				if(mid < r && l < cr){
					ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));
				}
				return ret;
			}
		}
		
		public int firstle(int l, long v) {
			int cur = H+l;
			while(true){
				if(st[cur] <= v){
					if(cur < H){
						cur = 2*cur;
					}else{
						return cur-H;
					}
				}else{
					cur++;
					if((cur&cur-1) == 0)return -1;
					if((cur&1)==0)cur>>>=1;
				}
			}
		}
		
		public int lastle(int l, long v) {
			int cur = H+l;
			while(true){
				if(st[cur] <= v){
					if(cur < H){
						cur = 2*cur+1;
					}else{
						return cur-H;
					}
				}else{
					if((cur&cur-1) == 0)return -1;
					cur--;
					if((cur&1)==1)cur>>>=1;
				}
			}
		}
	}

	
	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 F().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