結果
問題 | No.1000 Point Add and Array Add |
ユーザー | uw_yu1rabbit |
提出日時 | 2021-03-14 13:02:59 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 4,604 bytes |
コンパイル時間 | 13,225 ms |
コンパイル使用メモリ | 400,232 KB |
実行使用メモリ | 14,584 KB |
最終ジャッジ日時 | 2024-11-06 02:45:22 |
合計ジャッジ時間 | 17,884 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 1 ms
6,820 KB |
testcase_14 | AC | 3 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 122 ms
11,360 KB |
testcase_17 | AC | 96 ms
9,216 KB |
testcase_18 | AC | 168 ms
14,356 KB |
testcase_19 | AC | 163 ms
14,584 KB |
testcase_20 | AC | 155 ms
11,220 KB |
testcase_21 | AC | 142 ms
11,988 KB |
testcase_22 | AC | 158 ms
12,148 KB |
testcase_23 | AC | 145 ms
12,376 KB |
コンパイルメッセージ
warning: unused variable: `i` --> src/main.rs:124:55 | 124 | let mut query:Vec<(char,usize,i64)> = (0..q).map(|i| (read() ,read() ,read())).collect(); | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default warning: variable does not need to be mutable --> src/main.rs:123:9 | 123 | let mut a:Vec<i64> = (0..n).map(|_| read()).collect(); | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
#[allow(dead_code)] #[allow(unused_imports)] fn read<T: std::str::FromStr>() -> T { use std::io::*; let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } pub mod segment_tree {//基本的には整数型で使うことを想定しています(最悪C++に逃げましょう) use std::ops::*; fn e<T>() -> T where T:Eq + Copy + Add<Output=T> + AddAssign + BitAnd<Output=T> + BitAndAssign + BitOr<Output=T> + BitOrAssign + BitXor<Output=T> + BitXorAssign<T> + Mul<Output=T> + MulAssign + Identity, { T::identity() } fn op<T>(x:T,y:T) -> T where T:Eq + Copy + Add<Output=T> + AddAssign + BitAnd<Output=T> + BitAndAssign + BitOr<Output=T> + BitOrAssign + BitXor<Output=T> + BitXorAssign<T> + Mul<Output=T> + MulAssign, { x + y } pub trait Identity { fn identity() -> Self; } macro_rules! impl_identity{ ($($t:ty),*) => { $( impl Identity for $t { fn identity() -> Self { 0 } } )* }; } impl_identity!{i64,usize,u64,i32,u32,isize} #[derive(Debug)] pub struct SegmentTree<T> { node:Vec<T>, cnt:usize, sz:usize, } impl<T> SegmentTree<T> where T:Eq + Copy + Add<Output=T> + AddAssign + BitAnd<Output=T> + BitAndAssign + BitOr<Output=T> + BitOrAssign + BitXor<Output=T> + BitXorAssign<T> + Mul<Output=T> + MulAssign + Identity, { pub fn new(_n:usize) -> Self{ let mut _cnt = 0; while (1usize << _cnt) < _n { _cnt += 1; } let size = 1 << _cnt; Self { sz:size, node:vec![e();size * 2], cnt:_cnt, } } pub fn set(&mut self,_i:usize,x:T) { let mut i = _i; i += self.sz; self.node[i] = x; for bit in 1..=self.cnt { self.update(i >> bit); } } pub fn get(&mut self,i:usize) -> T { self.node[i + self.sz] } pub fn prod(&mut self,_l:usize,_r:usize) -> T { let mut resl = e(); let mut l = _l + self.sz; let mut r = _r + self.sz; let mut resr = e(); while l < r { if l & 1 == 1 { resl = op(resl,self.node[l]); l += 1; } if r & 1 == 1 { r -= 1; resr = op(resr,self.node[r]); } l >>= 1; r >>= 1; } op(resl,resr) } pub fn update (&mut self,k:usize) { self.node[k] = op(self.node[2 * k],self.node[2 * k + 1]); } pub fn all_prod(&mut self) -> T{ self.node[1] } } } fn main(){ let n:usize = read(); let q:usize = read(); let mut seg_b = segment_tree::SegmentTree::<i64>::new(n); let mut seg_c = segment_tree::SegmentTree::<i64>::new(n + 1); let mut a:Vec<i64> = (0..n).map(|_| read()).collect(); let mut query:Vec<(char,usize,i64)> = (0..q).map(|i| (read() ,read() ,read())).collect(); query.reverse(); for i in 0..q { let (c,x,y) = query[i]; if c == 'A' { let v = seg_b.get(x - 1); seg_b.set(x - 1, v + y * seg_c.prod(0,x)); }else{ let v = seg_c.get(x - 1); let vv = seg_c.get(y as usize); seg_c.set(x - 1,v + 1); seg_c.set(y as usize,vv - 1); } } for i in 0..n { let v = seg_b.get(i); seg_b.set(i,v + a[i] * seg_c.prod(0,i + 1)); } for i in 0..n { print!("{} ", seg_b.get(i)); } println!(""); }