結果
問題 | No.1000 Point Add and Array Add |
ユーザー | phspls |
提出日時 | 2022-12-28 02:26:42 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 289 ms / 2,000 ms |
コード長 | 4,614 bytes |
コンパイル時間 | 14,659 ms |
コンパイル使用メモリ | 377,920 KB |
実行使用メモリ | 33,408 KB |
最終ジャッジ日時 | 2024-05-02 04:43:34 |
合計ジャッジ時間 | 19,867 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 174 ms
27,520 KB |
testcase_17 | AC | 153 ms
18,816 KB |
testcase_18 | AC | 265 ms
33,280 KB |
testcase_19 | AC | 289 ms
33,408 KB |
testcase_20 | AC | 168 ms
24,608 KB |
testcase_21 | AC | 278 ms
28,672 KB |
testcase_22 | AC | 230 ms
33,152 KB |
testcase_23 | AC | 279 ms
33,408 KB |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:111:9 | 111 | let mut a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default warning: field `orgn` is never read --> src/main.rs:5:5 | 3 | struct LazySegmentTree<F, G, H, T, U> { | --------------- field in this struct 4 | n: usize, 5 | orgn: usize, | ^^^^ | = note: `LazySegmentTree` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default warning: method `update_closed` is never used --> src/main.rs:46:8 | 15 | / impl<F, G, H, T, U> LazySegmentTree<F, G, H, T, U> where 16 | | T: std::fmt::Debug + Copy, 17 | | U: std::fmt::Debug + std::cmp::PartialEq + Copy, 18 | | F: Fn(T, T) -> T, 19 | | G: Fn(T, U) -> T, 20 | | H: Fn(U, U) -> U, | |_________________- method in this implementation ... 46 | fn update_closed(&mut self, left: usize, right: usize, val: U) { | ^^^^^^^^^^^^^
ソースコード
#[derive(Debug, Clone)] struct LazySegmentTree<F, G, H, T, U> { n: usize, orgn: usize, unit: T, mem: Vec<T>, lazy_unit: U, lazy: Vec<U>, operator: F, mapper: G, composer: H, } impl<F, G, H, T, U> LazySegmentTree<F, G, H, T, U> where T: std::fmt::Debug + Copy, U: std::fmt::Debug + std::cmp::PartialEq + Copy, F: Fn(T, T) -> T, G: Fn(T, U) -> T, H: Fn(U, U) -> U, { fn new(n: usize, unit: T, lazy_unit: U, operator: F, mapper: G, composer: H) -> Self { let mut size = 1usize; while size < n { size *= 2; } Self { n: size, orgn: n, unit: unit, mem: vec![unit; size*2-1], lazy_unit: lazy_unit, lazy: vec![lazy_unit; size*2-1], operator: operator, mapper: mapper, composer: composer, } } fn find_closed(&mut self, l: usize, r: usize) -> T { self.find(l, r+1) } fn find(&mut self, l: usize, r: usize) -> T { self._find(l, r, 0, 0, self.n) } fn update_closed(&mut self, left: usize, right: usize, val: U) { self.update(left, right+1, val); } fn update(&mut self, left: usize, right: usize, val: U) { self._update(left, right, val, 0, 0, self.n); } fn get(&mut self, pos: usize) -> T { self.find_closed(pos, pos) } fn _evaluate(&mut self, k: usize) { if self.lazy[k] == self.lazy_unit { return; } if k < self.n-1 { let left = self._left(k); let right = self._right(k); self.lazy[left] = (self.composer)(self.lazy[left], self.lazy[k]); self.lazy[right] = (self.composer)(self.lazy[right], self.lazy[k]); } self.mem[k] = (self.mapper)(self.mem[k], self.lazy[k]); self.lazy[k] = self.lazy_unit; } fn _find(&mut self, a: usize, b: usize, nodenum: usize, l: usize, r: usize) -> T { self._evaluate(nodenum); if r <= a || b <= l { self.unit } else if a <= l && r <= b { self.mem[nodenum] } else { let left = self._find(a, b, self._left(nodenum), l, (l+r)/2); let right = self._find(a, b, self._right(nodenum), (l+r)/2, r); (self.operator)(left, right) } } fn _update(&mut self, a: usize, b: usize, x: U, nodenum: usize, l: usize, r: usize) { self._evaluate(nodenum); if a <= l && r <= b { self.lazy[nodenum] = (self.composer)(self.lazy[nodenum], x); self._evaluate(nodenum); } else if a < r && l < b { self._update(a, b, x, self._left(nodenum), l, (l + r) / 2); self._update(a, b, x, self._right(nodenum), (l + r) / 2, r); self.mem[nodenum] = (self.operator)(self.mem[self._left(nodenum)], self.mem[self._right(nodenum)]); } } fn _left(&self, k: usize) -> usize { 2*k+1 } fn _right(&self, k: usize) -> usize { 2*k+2 } fn _parent(&self, k: usize) -> usize { (k-1)/2 } } fn main() { let mut nq = String::new(); std::io::stdin().read_line(&mut nq).ok(); let nq: Vec<usize> = nq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nq[0]; let q = nq[1]; let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let mut a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let queries = (0..q).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<&str> = temp.trim().split_whitespace().collect(); (temp[0].chars().nth(0).unwrap(), temp[1].parse::<usize>().unwrap(), temp[2].parse::<usize>().unwrap()) }) .collect::<Vec<_>>(); let mut total = vec![0isize; n]; for &(c, x, y) in queries.iter() { if c == 'B' { total[x-1] += 1; if y < n { total[y] -= 1; } } } for i in 0..n-1 { total[i+1] += total[i]; } let mut b = (0..n).map(|i| a[i] * total[i] as usize).collect::<Vec<_>>(); let mut segtree = LazySegmentTree::new(n, 0usize, 0usize, |x, y| x + y, |x, y| x+y, |x, y| x+y); for &(c, x, y) in queries.iter() { let x = x-1; if c == 'A' { let cnt = segtree.get(x); b[x] += (total[x] as usize - cnt) * y; } else { segtree.update(x, y, 1); } } println!("{}", b.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(" ")); }