結果
問題 | No.1000 Point Add and Array Add |
ユーザー | ks2m |
提出日時 | 2020-02-28 22:21:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 827 ms / 2,000 ms |
コード長 | 1,695 bytes |
コンパイル時間 | 2,093 ms |
コンパイル使用メモリ | 78,848 KB |
実行使用メモリ | 77,564 KB |
最終ジャッジ日時 | 2024-04-21 19:09:56 |
合計ジャッジ時間 | 11,003 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
36,624 KB |
testcase_01 | AC | 45 ms
36,572 KB |
testcase_02 | AC | 46 ms
36,980 KB |
testcase_03 | AC | 47 ms
36,492 KB |
testcase_04 | AC | 47 ms
36,884 KB |
testcase_05 | AC | 46 ms
36,624 KB |
testcase_06 | AC | 47 ms
36,628 KB |
testcase_07 | AC | 47 ms
36,604 KB |
testcase_08 | AC | 48 ms
36,864 KB |
testcase_09 | AC | 48 ms
36,772 KB |
testcase_10 | AC | 47 ms
36,764 KB |
testcase_11 | AC | 48 ms
36,944 KB |
testcase_12 | AC | 99 ms
39,960 KB |
testcase_13 | AC | 103 ms
39,292 KB |
testcase_14 | AC | 124 ms
40,304 KB |
testcase_15 | AC | 101 ms
39,720 KB |
testcase_16 | AC | 694 ms
65,472 KB |
testcase_17 | AC | 511 ms
55,312 KB |
testcase_18 | AC | 799 ms
77,564 KB |
testcase_19 | AC | 825 ms
75,768 KB |
testcase_20 | AC | 707 ms
74,536 KB |
testcase_21 | AC | 827 ms
71,368 KB |
testcase_22 | AC | 782 ms
74,212 KB |
testcase_23 | AC | 802 ms
74,584 KB |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int q = Integer.parseInt(sa[1]); sa = br.readLine().split(" "); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } BIT bit = new BIT(n); List<Obj> list = new ArrayList<>(); for (int i = 0; i < q; i++) { sa = br.readLine().split(" "); if ("A".equals(sa[0])) { Obj o = new Obj(); o.i = Integer.parseInt(sa[1]); o.y = Integer.parseInt(sa[2]); o.cnt = bit.sum(o.i); list.add(o); } else { bit.add(Integer.parseInt(sa[1]), 1); bit.add(Integer.parseInt(sa[2]) + 1, -1); } } br.close(); long[] b = new long[n]; for (int i = 0; i < b.length; i++) { b[i] = a[i] * bit.sum(i + 1); } for (Obj o : list) { b[o.i - 1] += o.y * (bit.sum(o.i) - o.cnt); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < b.length; i++) { sb.append(b[i]).append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } static class Obj { int i, cnt; long y; } static class BIT { int n; long[] arr; public BIT(int n) { this.n = n; arr = new long[n + 1]; } void add(int idx, long val) { for (int i = idx; i <= n; i += i & -i) { arr[i] += val; } } int sum(int idx) { int sum = 0; for (int i = idx; i > 0; i -= i & -i) { sum += arr[i]; } return sum; } } }