結果
問題 | No.1014 competitive fighting |
ユーザー | uwi |
提出日時 | 2020-03-20 23:06:23 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,172 ms / 2,000 ms |
コード長 | 8,176 bytes |
コンパイル時間 | 5,185 ms |
コンパイル使用メモリ | 90,044 KB |
実行使用メモリ | 75,600 KB |
最終ジャッジ日時 | 2024-07-07 12:55:29 |
合計ジャッジ時間 | 35,415 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
37,260 KB |
testcase_01 | AC | 49 ms
36,636 KB |
testcase_02 | AC | 49 ms
36,972 KB |
testcase_03 | AC | 48 ms
37,072 KB |
testcase_04 | AC | 51 ms
36,944 KB |
testcase_05 | AC | 1,025 ms
71,628 KB |
testcase_06 | AC | 956 ms
71,848 KB |
testcase_07 | AC | 914 ms
68,992 KB |
testcase_08 | AC | 835 ms
71,148 KB |
testcase_09 | AC | 961 ms
68,468 KB |
testcase_10 | AC | 239 ms
54,996 KB |
testcase_11 | AC | 590 ms
71,572 KB |
testcase_12 | AC | 891 ms
67,728 KB |
testcase_13 | AC | 426 ms
54,808 KB |
testcase_14 | AC | 394 ms
54,140 KB |
testcase_15 | AC | 455 ms
54,940 KB |
testcase_16 | AC | 103 ms
39,084 KB |
testcase_17 | AC | 242 ms
47,896 KB |
testcase_18 | AC | 688 ms
60,928 KB |
testcase_19 | AC | 904 ms
71,836 KB |
testcase_20 | AC | 352 ms
51,688 KB |
testcase_21 | AC | 702 ms
59,616 KB |
testcase_22 | AC | 519 ms
57,960 KB |
testcase_23 | AC | 293 ms
47,496 KB |
testcase_24 | AC | 291 ms
48,104 KB |
testcase_25 | AC | 157 ms
42,284 KB |
testcase_26 | AC | 599 ms
58,776 KB |
testcase_27 | AC | 247 ms
47,900 KB |
testcase_28 | AC | 261 ms
47,908 KB |
testcase_29 | AC | 69 ms
37,932 KB |
testcase_30 | AC | 899 ms
70,796 KB |
testcase_31 | AC | 731 ms
59,672 KB |
testcase_32 | AC | 64 ms
37,928 KB |
testcase_33 | AC | 188 ms
43,552 KB |
testcase_34 | AC | 823 ms
66,700 KB |
testcase_35 | AC | 1,172 ms
75,600 KB |
testcase_36 | AC | 736 ms
67,112 KB |
testcase_37 | AC | 105 ms
39,860 KB |
testcase_38 | AC | 715 ms
61,016 KB |
testcase_39 | AC | 389 ms
54,636 KB |
testcase_40 | AC | 675 ms
59,936 KB |
testcase_41 | AC | 492 ms
57,184 KB |
testcase_42 | AC | 1,069 ms
72,332 KB |
testcase_43 | AC | 171 ms
43,012 KB |
testcase_44 | AC | 1,032 ms
70,240 KB |
testcase_45 | AC | 556 ms
59,520 KB |
testcase_46 | AC | 204 ms
46,244 KB |
testcase_47 | AC | 378 ms
51,760 KB |
testcase_48 | AC | 862 ms
67,048 KB |
testcase_49 | AC | 132 ms
40,992 KB |
testcase_50 | AC | 978 ms
71,804 KB |
testcase_51 | AC | 587 ms
59,900 KB |
testcase_52 | AC | 142 ms
41,824 KB |
testcase_53 | AC | 962 ms
71,564 KB |
ソースコード
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(2*p); 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)); } }