結果

問題 No.1074 増殖
ユーザー tentententen
提出日時 2021-08-13 17:56:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,758 bytes
コンパイル時間 2,351 ms
コンパイル使用メモリ 80,552 KB
実行使用メモリ 67,236 KB
最終ジャッジ日時 2024-04-14 11:45:10
合計ジャッジ時間 6,562 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
56,880 KB
testcase_01 AC 53 ms
50,404 KB
testcase_02 AC 54 ms
49,916 KB
testcase_03 AC 53 ms
50,328 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        Place rightup = new Place();
        Place leftup = new Place();
        Place rightdown = new Place();
        Place leftdown = new Place();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            long ans = 0;
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int x2 = sc.nextInt();
            int y2 = sc.nextInt();
            ans += rightup.add(-x1, -y1);
            ans += leftup.add(x2, -y1);
            ans += rightdown.add(-x1, y2);
            ans += leftdown.add(x2, y2);
            sb.append(ans).append("\n");
        }
        System.out.print(sb);
    }
    
    
    static class Place {
        TreeMap<Integer, Integer> map = new TreeMap<>();
        
        public Place() {
            map.put(0, 0);
            map.put(Integer.MAX_VALUE, 0);
        }
        
        public long add(int x, int y) {
            long ans = 0;
            Integer key = map.firstKey();
            int prev = key;
            int pValue = map.get(key);
            boolean isSet = false;
            while ((key = map.higherKey(key)) != null) {
                int value = map.get(key);
                if (!isSet && pValue < x) {
                    isSet = true;
                    map.put(prev, x);
                }
                if (key >= y) {
                    if (isSet) {
                        ans += (long)(y - prev) * (x - pValue);
                        if (key > y) {
                            map.put(y, pValue);
                        }
                    }
                    break;
                } else {
                    if (isSet) {
                        ans += (long)(key - prev) * (x - pValue);
                    }
                }
                if (isSet && map.get(prev) < x) {
                    map.remove(prev);
                }
                prev = key;
                pValue = value;
            }
            return ans;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0