結果
問題 | No.1014 competitive fighting |
ユーザー | uwi |
提出日時 | 2020-03-20 23:02:14 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 8,144 bytes |
コンパイル時間 | 5,248 ms |
コンパイル使用メモリ | 88,068 KB |
実行使用メモリ | 84,220 KB |
最終ジャッジ日時 | 2024-05-09 00:09:46 |
合計ジャッジ時間 | 38,372 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
40,992 KB |
testcase_01 | RE | - |
testcase_02 | AC | 61 ms
40,744 KB |
testcase_03 | AC | 62 ms
41,008 KB |
testcase_04 | AC | 62 ms
41,116 KB |
testcase_05 | AC | 1,165 ms
69,412 KB |
testcase_06 | AC | 1,232 ms
71,120 KB |
testcase_07 | AC | 1,147 ms
71,220 KB |
testcase_08 | AC | 1,084 ms
72,880 KB |
testcase_09 | AC | 1,185 ms
71,124 KB |
testcase_10 | RE | - |
testcase_11 | AC | 845 ms
68,376 KB |
testcase_12 | AC | 1,040 ms
70,540 KB |
testcase_13 | AC | 505 ms
55,492 KB |
testcase_14 | AC | 483 ms
55,512 KB |
testcase_15 | AC | 588 ms
54,788 KB |
testcase_16 | AC | 121 ms
39,376 KB |
testcase_17 | AC | 290 ms
48,756 KB |
testcase_18 | AC | 874 ms
59,128 KB |
testcase_19 | AC | 1,287 ms
68,596 KB |
testcase_20 | AC | 413 ms
52,068 KB |
testcase_21 | AC | 802 ms
57,688 KB |
testcase_22 | AC | 650 ms
58,232 KB |
testcase_23 | AC | 342 ms
47,856 KB |
testcase_24 | AC | 345 ms
48,944 KB |
testcase_25 | AC | 183 ms
42,340 KB |
testcase_26 | AC | 711 ms
57,664 KB |
testcase_27 | AC | 277 ms
48,312 KB |
testcase_28 | AC | 315 ms
48,708 KB |
testcase_29 | AC | 99 ms
38,292 KB |
testcase_30 | AC | 1,091 ms
69,072 KB |
testcase_31 | AC | 818 ms
57,508 KB |
testcase_32 | AC | 90 ms
37,928 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 | 1,156 ms
69,468 KB |
ソースコード
package contest200320; 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]; xs[i+p] = es[i][3]; } 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; 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)); } }