結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-11-12 10:04:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 719 ms / 2,000 ms |
| コード長 | 2,337 bytes |
| コンパイル時間 | 2,366 ms |
| コンパイル使用メモリ | 85,584 KB |
| 実行使用メモリ | 61,364 KB |
| 最終ジャッジ日時 | 2024-09-17 15:32:54 |
| 合計ジャッジ時間 | 10,306 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
import java.util.*;
public class Main {
static final int MOD = 1000000007;
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
long d = sc.nextLong();
int q = sc.nextInt();
TreeSet<Work> set = new TreeSet<>();
StringBuilder sb = new StringBuilder();
long max = 0;
for (int i = 0; i < q; i++) {
Work tmp = new Work(sc.nextLong(), sc.nextLong());
while (true) {
Work before = set.floor(tmp);
if (before == null || before.end < tmp.start - 1) {
break;
}
tmp.add(before);
set.remove(before);
}
while (true) {
Work after = set.ceiling(tmp);
if (after == null || tmp.end < after.start - 1) {
break;
}
tmp.add(after);
set.remove(after);
}
max = Math.max(max, tmp.getCount());
set.add(tmp);
sb.append(max).append("\n");
}
System.out.print(sb);
}
static class Work implements Comparable<Work> {
long start;
long end;
public Work(long start, long end) {
this.start = start;
this.end = end;
}
public int compareTo(Work another) {
if (start == another.start) {
if (end == another.end) {
return 0;
} else if (end < another.end) {
return -1;
} else {
return 1;
}
} else {
if (start == another.start) {
return 0;
} else if (start < another.start) {
return -1;
} else {
return 1;
}
}
}
public long getCount() {
return end - start + 1;
}
public void add(Work another) {
start = Math.min(start, another.start);
end = Math.max(end, another.end);
}
public int hashCode() {
return (int)start;
}
public boolean equals(Object o) {
Work another = (Work) o;
return start == another.start && end == another.end;
}
public String toString() {
return "start:" + start + " end:" + end;
}
}
}
htensai