結果

問題 No.674 n連勤
ユーザー tentententen
提出日時 2020-09-03 18:48:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 751 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 2,691 ms
コンパイル使用メモリ 79,772 KB
実行使用メモリ 50,720 KB
最終ジャッジ日時 2024-11-23 21:14:45
合計ジャッジ時間 10,867 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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