結果
問題 | No.1074 増殖 |
ユーザー |
![]() |
提出日時 | 2021-08-13 17:56:11 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,758 bytes |
コンパイル時間 | 2,035 ms |
コンパイル使用メモリ | 78,900 KB |
実行使用メモリ | 67,296 KB |
最終ジャッジ日時 | 2024-10-03 08:53:04 |
合計ジャッジ時間 | 6,045 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 WA * 2 TLE * 1 -- * 8 |
ソースコード
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();}}