結果
問題 | No.1074 増殖 |
ユーザー | tenten |
提出日時 | 2023-06-07 20:47:17 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,735 bytes |
コンパイル時間 | 2,856 ms |
コンパイル使用メモリ | 92,140 KB |
実行使用メモリ | 65,380 KB |
最終ジャッジ日時 | 2024-06-09 13:30:32 |
合計ジャッジ時間 | 13,184 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | WA | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] xlow = new int[n]; int[] ylow = new int[n]; int[] xhigh = new int[n]; int[] yhigh = new int[n]; Compress xn = new Compress(); Compress yn = new Compress(); Compress xp = new Compress(); Compress yp = new Compress(); for (int i = 0; i < n; i++) { xlow[i] = -sc.nextInt(); xn.add(xlow[i]); ylow[i] = -sc.nextInt(); yn.add(ylow[i]); xhigh[i] = sc.nextInt(); xp.add(xhigh[i]); yhigh[i] = sc.nextInt(); yp.add(yhigh[i]); } xn.init(); yn.init(); xp.init(); yp.init(); Dimension leftDown = new Dimension(xn, yn); Dimension leftUp = new Dimension(xn, yp); Dimension rightDown = new Dimension(xp, yn); Dimension rightUp = new Dimension(xp, yp); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int ans = leftDown.get(xlow[i], ylow[i]) + leftUp.get(xlow[i], yhigh[i]) + rightDown.get(xhigh[i], ylow[i]) + leftUp.get(xhigh[i], yhigh[i]); sb.append(ans).append("\n"); } System.out.print(sb); } static class Dimension { Compress xCom; Compress yCom; int[] used; public Dimension(Compress xCom, Compress yCom) { this.xCom = xCom; this.yCom = yCom; used = new int[yCom.size + 1]; } public int get(int xVal, int yVal) { int xIdx = xCom.get(xVal); int yIdx = yCom.get(yVal); int ans = 0; for (int i = 0; i < yIdx; i++) { ans += xCom.getSum(used[i], xIdx) * yCom.value[i]; used[i] = Math.max(used[i], xIdx); } return ans; } } static class Compress { TreeMap<Integer, Integer> compress = new TreeMap<>(); int[] value; int[] sum; int size; public Compress() { compress.put(0, null); } public void add(int x) { compress.put(x, null); } public void init() { size = compress.size(); value = new int[size + 1]; int prev = 0; int idx = 0; for (int x : compress.keySet()) { compress.put(x, idx); if (idx > 0) { value[idx - 1] = x - prev; } prev = x; idx++; } sum = new int[size + 1]; for (int i = 0; i <= size; i++) { if (i == 0) { sum[i] = value[i]; } else { sum[i] = sum[i - 1] + value[i]; } } } public int get(int x) { return compress.get(x); } public int getSum(int from, int to) { if (to <= from) { return 0; } if (from == 0) { return sum[to - 1]; } else { return sum[to - 1] - sum[from - 1]; } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }