結果

問題 No.674 n連勤
ユーザー tentententen
提出日時 2020-09-03 18:48:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 76,164 KB
実行使用メモリ 63,500 KB
最終ジャッジ日時 2023-08-15 13:47:01
合計ジャッジ時間 10,102 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,060 KB
testcase_01 AC 123 ms
56,116 KB
testcase_02 AC 123 ms
55,732 KB
testcase_03 AC 125 ms
56,152 KB
testcase_04 AC 123 ms
56,064 KB
testcase_05 AC 126 ms
55,972 KB
testcase_06 AC 125 ms
56,036 KB
testcase_07 AC 125 ms
54,048 KB
testcase_08 AC 121 ms
56,204 KB
testcase_09 AC 123 ms
55,568 KB
testcase_10 AC 123 ms
56,116 KB
testcase_11 AC 252 ms
60,048 KB
testcase_12 AC 253 ms
60,452 KB
testcase_13 AC 567 ms
60,528 KB
testcase_14 AC 571 ms
60,620 KB
testcase_15 AC 547 ms
60,568 KB
testcase_16 AC 642 ms
63,500 KB
testcase_17 AC 638 ms
63,072 KB
testcase_18 AC 596 ms
60,996 KB
testcase_19 AC 612 ms
60,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long d = sc.nextLong();
    	int q = sc.nextInt();
    	TreeMap<Long, Long> works = new TreeMap<>();
    	works.put(-10L, -10L);
    	works.put(d + 10, d + 10);
    	long max = 0;
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < q; i++) {
    	    long left = sc.nextLong();
    	    long right = sc.nextLong();
    	    long key;
    	    while (true) {
    	        key = works.floorKey(left);
    	        if (works.get(key) + 1 >= left) {
    	            right = Math.max(works.get(key), right);
    	            left = key;
    	            works.remove(key);
    	        } else {
    	            break;
    	        }
    	    }
    	    while (true) {
    	        key = works.higherKey(left);
    	        if (right + 1 >= key) {
    	            right = Math.max(works.get(key), right);
    	            works.remove(key);
    	        } else {
    	            break;
    	        }
    	    }
    	    works.put(left, right);
    	    max = Math.max(max, right - left + 1);
    	    sb.append(max).append("\n");
    	}
    	System.out.print(sb);
	}
}
0