結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | uafr_cs |
提出日時 | 2017-11-04 09:15:07 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,961 bytes |
コンパイル時間 | 2,160 ms |
コンパイル使用メモリ | 82,632 KB |
実行使用メモリ | 81,640 KB |
最終ジャッジ日時 | 2024-11-22 17:01:54 |
合計ジャッジ時間 | 15,791 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 149 ms
54,860 KB |
testcase_01 | AC | 150 ms
54,664 KB |
testcase_02 | AC | 159 ms
54,644 KB |
testcase_03 | AC | 140 ms
54,872 KB |
testcase_04 | AC | 150 ms
54,724 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 838 ms
81,488 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 1,157 ms
80,640 KB |
testcase_19 | WA | - |
ソースコード
import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static class LazySegTree{ int n; long[] plus_sum, minus_sum; long[] lazy_plus, lazy_minus; int[] sign; public LazySegTree(int n_) { int n = 1; while(n < n_){ n *= 2;} this.n = n; plus_sum = new long[this.n * 2 - 1]; minus_sum = new long[this.n * 2 - 1]; lazy_plus = new long[this.n * 2 - 1]; lazy_minus = new long[this.n * 2 - 1]; sign = new int[this.n * 2 + 1]; for(int i = 0; i < this.n * 2 - 1 ; i++){ plus_sum[i] = 0; lazy_plus[i] = 0; minus_sum[i] = 0; lazy_minus[i] = 0; sign[i] = 0; } } private void evaluate_node(int k, int a, int b){ if(sign[k] == 0){ return; } if(sign[k] == 1){ plus_sum[k] += lazy_plus[k] * (b - a); minus_sum[k] = 0; }else if(sign[k] == -1){ plus_sum[k] = 0; minus_sum[k] += lazy_minus[k] * (b - a); } if(k < n - 1){ sign[k * 2 + 1] = sign[k]; sign[k * 2 + 2] = sign[k]; if(sign[k] == 1){ lazy_plus[k * 2 + 1] = lazy_plus[k]; lazy_plus[k * 2 + 2] = lazy_plus[k]; lazy_minus[k * 2 + 1] = 0; lazy_minus[k * 2 + 2] = 0; }else if(sign[k] == -1){ lazy_plus[k * 2 + 1] = 0; lazy_plus[k * 2 + 2] = 0; lazy_minus[k * 2 + 1] = lazy_minus[k]; lazy_minus[k * 2 + 2] = lazy_minus[k]; } } sign[k] = 0; lazy_plus[k] = lazy_minus[k] = 0; } public void update_node(int k){ plus_sum[k] = plus_sum[2 * k + 1] + plus_sum[2 * k + 2]; minus_sum[k] = minus_sum[2 * k + 1] + minus_sum[2 * k + 2]; } public void update(long v, int a, int b, int k, int l, int r){ evaluate_node(k, l, r); final int signum = Long.signum(v); if(r <= a || b <= l){ return; }else if(a <= l && r <= b){ sign[k] = signum; if(signum == 1){ lazy_plus[k] = v; lazy_minus[k] = 0; }else if(signum == -1){ lazy_plus[k] = 0; lazy_minus[k] = v; } evaluate_node(k, l, r); }else{ update(v, a, b, 2 * k + 1, l, (l + r) / 2); update(v, a, b, 2 * k + 2, (l + r) / 2, r); update_node(k); } } public long get_plus(int a, int b, int k, int l, int r){ evaluate_node(k, l, r); if(r <= a || b <= l){ return 0; }else if(a <= l && r <= b){ return plus_sum[k]; }else { long v1 = get_plus(a, b, k * 2 + 1, l, (l + r) / 2); long v2 = get_plus(a, b, k * 2 + 2, (l + r) / 2, r); update_node(k); return v1 + v2; } } public long get_minus(int a, int b, int k, int l, int r){ evaluate_node(k, l, r); if(r <= a || b <= l){ return 0; }else if(a <= l && r <= b){ return minus_sum[k]; }else { long v1 = get_minus(a, b, k * 2 + 1, l, (l + r) / 2); long v2 = get_minus(a, b, k * 2 + 2, (l + r) / 2, r); update_node(k); return v1 + v2; } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int Q = sc.nextInt(); long a_score = 0, b_score = 0; LazySegTree seg = new LazySegTree(N); for(int i = 0; i < Q; i++){ final int x = sc.nextInt(); final int l = sc.nextInt(); final int r = sc.nextInt() + 1; if(x == 0){ final long a_team = seg.get_plus(l, r, 0, 0, seg.n); final long b_team = -seg.get_minus(l, r, 0, 0, seg.n); if(a_team > b_team){ a_score += a_team; }else if(a_team < b_team){ b_score += b_team; } //System.out.println(a_team + " " + b_team); }else if(x == 1){ seg.update( 1, l, r, 0, 0, seg.n); }else if(x == 2){ seg.update(-1, l, r, 0, 0, seg.n); } //System.out.println(i + " plus " + seg.get_plus(0, N, 0, 0, seg.n)); //System.out.println(i + " minus " + seg.get_minus(0, N, 0, 0, seg.n)); } a_score += seg.get_plus(0, N, 0, 0, seg.n); b_score -= seg.get_minus(0, N, 0, 0, seg.n); System.out.println(a_score + " " + b_score); } }