結果
問題 | No.674 n連勤 |
ユーザー | uafr_cs |
提出日時 | 2018-04-14 00:26:20 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,509 bytes |
コンパイル時間 | 2,318 ms |
コンパイル使用メモリ | 83,024 KB |
実行使用メモリ | 86,808 KB |
最終ジャッジ日時 | 2024-06-26 22:02:08 |
合計ジャッジ時間 | 14,237 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
54,460 KB |
testcase_01 | AC | 136 ms
54,124 KB |
testcase_02 | AC | 116 ms
53,148 KB |
testcase_03 | WA | - |
testcase_04 | AC | 134 ms
54,116 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 128 ms
54,184 KB |
testcase_09 | AC | 130 ms
54,284 KB |
testcase_10 | AC | 130 ms
54,124 KB |
testcase_11 | AC | 399 ms
60,204 KB |
testcase_12 | WA | - |
testcase_13 | AC | 865 ms
64,900 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.Scanner; import java.util.TreeSet; public class Main { public static class LazySetSumSegmentTree { int n; boolean[] dat, lazy; ArrayList<Long> dist; long[] l_max, c_max, r_max; boolean[] push; public LazySetSumSegmentTree(int n_, ArrayList<Long> dist) { int n = 1; while(n < n_){ n *= 2;} this.n = n; l_max = new long[this.n * 2 - 1]; c_max = new long[this.n * 2 - 1]; r_max = new long[this.n * 2 - 1]; this.dist = dist; dat = new boolean[this.n * 2 - 1]; lazy = new boolean[this.n * 2 - 1]; push = new boolean[this.n * 2 - 1]; } private void evaluate_lazy(int k, int l, int r){ if(!push[k]){ return; } dat[k] = lazy[k]; if(dat[k]){ //System.out.println(r + " " + l + " -> " + dist.get(r - 1) + " " + dist.get(l)); c_max[k] = l_max[k] = r_max[k] = (dist.get(r - 1) - dist.get(l) + 1); }else{ l_max[k] = c_max[k] = r_max[k] = 0; } if(k < n - 1){ lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k]; push[k * 2 + 1] = push[k * 2 + 2] = true; } lazy[k] = false; push[k] = false; } private void update_node(int k){ final int l = k * 2 + 1; final int r = k * 2 + 2; final long l_all_max = Math.max(Math.max(l_max[l], r_max[l]), c_max[l]); final long r_all_max = Math.max(Math.max(l_max[r], r_max[r]), c_max[r]); final long children_max = Math.max(l_all_max, r_all_max); c_max[k] = Math.max(children_max, (l_max[r] + r_max[l])); l_max[k] = l_max[l] + (dat[l] ? l_max[r] : 0); r_max[k] = r_max[r] + (dat[r] ? r_max[l] : 0); //System.out.println("l -> " + l_max[l] + " " + c_max[l] + " " + r_max[l]); //System.out.println("r -> " + l_max[r] + " " + c_max[r] + " " + r_max[r]); //System.out.println("k -> " + l_max[k] + " " + c_max[k] + " " + r_max[k]); dat[k] = dat[k*2+1] && dat[k*2+2]; } public void set(boolean v, int a, int b){ set(v, a, b, 0, 0, this.n); } public void set(boolean v, int a, int b, int k, int l, int r){ evaluate_lazy(k, l, r); if(r <= a || b <= l){ return; }else if(a <= l && r <= b){ lazy[k] = v; push[k] = true; evaluate_lazy(k, l, r); }else{ set(v, a, b, k * 2 + 1, l, (l + r) / 2); set(v, a, b, k * 2 + 2, (l + r) / 2, r); update_node(k); } } public long[] max(int a, int b){ return max(a, b, 0, 0, this.n); } public long[] max(int a, int b, int k, int l, int r){ evaluate_lazy(k, l, r); if(r <= a || b <= l){ /* 通らない予定 */ return new long[]{0, 0, 0}; }else if(a <= l && r <= b){ return new long[]{l_max[k], c_max[k], r_max[k]}; }else{ final long[] l_max_ret = max(a, b, k * 2 + 1, l, (l + r) / 2); final long[] r_max_ret = max(a, b, k * 2 + 2, (l + r) / 2, r); final long l_all_max = Math.max(Math.max(l_max_ret[0], l_max_ret[1]), l_max_ret[2]); final long r_all_max = Math.max(Math.max(r_max_ret[0], r_max_ret[1]), r_max_ret[2]); final long children_max = Math.max(l_all_max, r_all_max); final boolean l_cont_all = l_max_ret[1] == ((l + r) / 2) - l; final boolean r_cont_all = r_max_ret[1] == r - ((l + r) / 2); final long fst = l_max_ret[0] + Math.max(0, l_cont_all ? r_max_ret[0]: 0); final long snd = Math.max(children_max, (l_max_ret[2] + r_max_ret[0])); final long thd = r_max_ret[2] + Math.max(0, r_cont_all ? l_max_ret[2]: 0); update_node(k); return new long[]{fst, snd, thd}; } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final long D = sc.nextLong(); final int Q = sc.nextInt(); long[] as = new long[Q]; long[] bs = new long[Q]; TreeSet<Long> coord = new TreeSet<Long>(); for(int i = 0; i < Q; i++){ as[i] = sc.nextLong(); bs[i] = sc.nextLong(); coord.add(as[i]); coord.add(bs[i] + 0); coord.add(bs[i] + 1); } ArrayList<Long> coord_list = new ArrayList<Long>(coord); final int size = coord_list.size(); LazySetSumSegmentTree seg = new LazySetSumSegmentTree(size, coord_list); for(int q = 0; q < Q; q++){ final int a_index = Collections.binarySearch(coord_list, as[q]); final int b_index = Collections.binarySearch(coord_list, bs[q] + 1); //System.out.println(a_index + " " + b_index); seg.set(true, a_index, b_index); System.out.println(Arrays.stream(seg.max(0, size + 1)).max().getAsLong()); } } }