結果

問題 No.1234 典型RMQ
ユーザー o2co2c
提出日時 2020-09-20 21:28:25
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 6,349 bytes
コンパイル時間 14,442 ms
コンパイル使用メモリ 379,208 KB
実行使用メモリ 6,924 KB
最終ジャッジ日時 2024-11-09 02:18:06
合計ジャッジ時間 20,371 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,248 KB
testcase_06 AC 181 ms
6,692 KB
testcase_07 AC 150 ms
5,248 KB
testcase_08 AC 188 ms
6,884 KB
testcase_09 AC 167 ms
5,248 KB
testcase_10 AC 178 ms
6,796 KB
testcase_11 AC 176 ms
6,656 KB
testcase_12 AC 168 ms
5,248 KB
testcase_13 AC 150 ms
5,248 KB
testcase_14 AC 171 ms
5,248 KB
testcase_15 AC 163 ms
5,248 KB
testcase_16 AC 179 ms
6,780 KB
testcase_17 AC 166 ms
5,248 KB
testcase_18 AC 145 ms
5,248 KB
testcase_19 AC 183 ms
6,732 KB
testcase_20 AC 128 ms
6,924 KB
testcase_21 AC 178 ms
6,680 KB
testcase_22 AC 148 ms
6,832 KB
testcase_23 AC 148 ms
6,892 KB
testcase_24 AC 146 ms
6,824 KB
testcase_25 AC 146 ms
6,924 KB
testcase_26 AC 146 ms
6,800 KB
testcase_27 AC 1 ms
5,248 KB
testcase_28 AC 1 ms
5,248 KB
testcase_29 AC 1 ms
5,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> src/main.rs:14:338
   |
14 | ...es !read {($($t :tt ) ,*;$n :expr ) =>{{let stdin =::std ::io ::stdin () ;let ret =::std ::io ::BufRead ::lines (stdin .lock () ) .take ($n ) .map (|line |{let line =line .unwrap () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } ) .collect ::<Vec <_ >>() ;ret } } ;($($t :tt ) ,*) =>{{let line =readln () ;let mut it =l...
   |                                                                                                                                                                                                                                                                                                                                            ----^^
   |                                                                                                                                                                                                                                                                                                                                            |
   |                                                                                                                                                                                                                                                                                                                                            help: remove this `mut`
...
24 | ... = read!([i64]);
   |       ------------ in this macro invocation
   |
   = note: `#[warn(unused_mut)]` on by default
   = note: this warning originates in the macro `read` (in Nightly builds, run with -Z macro-backtrace for more info)

ソースコード

diff #

#[allow(unused_imports)]
use {std::cmp::*, std::collections::*, std::io::Write, std::ops::*};

#[allow(unused_macros)]
macro_rules! dbg { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin()
        .read_line(&mut line)
        .unwrap_or_else(|e| panic!("{}", e));
    line
}
macro_rules !read {($($t :tt ) ,*;$n :expr ) =>{{let stdin =::std ::io ::stdin () ;let ret =::std ::io ::BufRead ::lines (stdin .lock () ) .take ($n ) .map (|line |{let line =line .unwrap () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } ) .collect ::<Vec <_ >>() ;ret } } ;($($t :tt ) ,*) =>{{let line =readln () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } } ;}
macro_rules !_read {($it :ident ;[char ] ) =>{_read !($it ;String ) .chars () .collect ::<Vec <_ >>() } ;($it :ident ;[u8 ] ) =>{Vec ::from (_read !($it ;String ) .into_bytes () ) } ;($it :ident ;usize1 ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::<usize >() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 } ;($it :ident ;[usize1 ] ) =>{$it .map (|s |s .parse ::<usize >() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 ) .collect ::<Vec <_ >>() } ;($it :ident ;[$t :ty ] ) =>{$it .map (|s |s .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) ) .collect ::<Vec <_ >>() } ;($it :ident ;$t :ty ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) } ;($it :ident ;$($t :tt ) ,+) =>{($(_read !($it ;$t ) ) ,*) } ;}

#[allow(unused_macros)]
macro_rules !max {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::max ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::max ($a ,max !($($rest ) ,+) ) } } ;}
#[allow(unused_macros)]
macro_rules !chmax {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_max =max !($($cmps ) ,+) ;if $base <cmp_max {$base =cmp_max ;true } else {false } } } ;}

fn main() {
    let _n = read!(usize);
    let a = read!([i64]);
    let q = read!(usize);
    let mut seg = LazySegmentTree::<Node>::from_vec(&a);
    for _ in 0..q {
        let (k, l, r, c) = read!(usize, usize1, usize1, i64);
        if k == 1 {
            seg.update(l..=r, &c);
        } else {
            println!("{}", seg.prod(l..=r));
        }
    }
}
const INF: i64 = 1_000_000_000_000_000_000;
struct Node;
impl ME for Node {
    type M = i64;
    type E = i64;
    fn id_m() -> Self::M {
        INF
    }
    fn id_e() -> Self::E {
        0
    }
    fn f(a: &Self::M, b: &Self::M) -> Self::M {
        min(*a, *b)
    }
    fn g(a: &Self::M, b: &Self::E) -> Self::M {
        a + b
    }
    fn h(a: &Self::E, b: &Self::E) -> Self::E {
        a + b
    }
    fn p(a: &Self::E, _k: usize) -> Self::E {
        *a
    }
}

trait ME {
    type M: Clone;
    type E: Clone + PartialEq;
    fn id_m() -> Self::M;
    fn id_e() -> Self::E;
    fn id() -> (Self::M, Self::E) {
        (Self::id_m(), Self::id_e())
    }
    fn f(a: &Self::M, b: &Self::M) -> Self::M;
    fn g(a: &Self::M, b: &Self::E) -> Self::M;
    fn h(a: &Self::E, b: &Self::E) -> Self::E;
    fn p(a: &Self::E, k: usize) -> Self::E;
}
struct LazySegmentTree<T: ME> {
    width: usize,
    dat: Vec<(T::M, T::E)>,
}
#[allow(dead_code)]
impl<T: ME> LazySegmentTree<T> {
    fn new(n: usize) -> Self {
        let width = n.next_power_of_two();
        Self {
            width,
            dat: vec![T::id(); (width << 1) - 1],
        }
    }
    fn from_vec(a: &[T::M]) -> Self {
        let width = a.len().next_power_of_two();
        let mut dat = vec![T::id(); (width << 1) - 1];
        for i in 0..a.len() {
            dat[i + width - 1].0 = a[i].clone();
        }
        for i in (0..width - 1).rev() {
            dat[i].0 = T::f(&dat[(i << 1) + 1].0, &dat[(i << 1) + 2].0);
        }
        Self { width, dat }
    }
    fn __eval(&mut self, now: usize, k: usize) {
        let e = T::p(&self.dat[now].1, k);
        self.dat[now].0 = T::g(&self.dat[now].0, &e);
        if k > 1 {
            self.dat[(now << 1) + 1].1 = T::h(&self.dat[(now << 1) + 1].1, &self.dat[now].1);
            self.dat[(now << 1) + 2].1 = T::h(&self.dat[(now << 1) + 2].1, &self.dat[now].1);
        }
        self.dat[now].1 = T::id_e();
    }
    fn __update(&mut self, x: &T::E, now: usize, lc: usize, rc: usize, l: usize, r: usize) {
        self.__eval(now, rc - lc);
        if l <= lc && rc <= r {
            self.dat[now].1 = T::h(&self.dat[now].1, x);
            self.__eval(now, rc - lc);
        } else if l < rc && lc < r {
            self.__update(x, (now << 1) + 1, lc, (lc + rc) / 2, l, r);
            self.__update(x, (now << 1) + 2, (lc + rc) / 2, rc, l, r);
            self.dat[now].0 = T::f(&self.dat[(now << 1) + 1].0, &self.dat[(now << 1) + 2].0);
        }
    }
    fn update<R>(&mut self, range: R, x: &T::E)
    where
        R: std::ops::RangeBounds<usize>,
    {
        let l = match range.start_bound() {
            std::ops::Bound::Included(&a) => a,
            _ => 0,
        };
        let r = match range.end_bound() {
            std::ops::Bound::Excluded(&a) => a,
            std::ops::Bound::Included(&a) => a + 1,
            _ => self.width,
        };
        self.__update(x, 0, 0, self.width, l, r);
    }
    fn __prod(&mut self, now: usize, lc: usize, rc: usize, l: usize, r: usize) -> T::M {
        self.__eval(now, rc - lc);
        if rc <= l || r <= lc {
            T::id_m()
        } else if l <= lc && rc <= r {
            self.dat[now].0.clone()
        } else {
            T::f(
                &self.__prod((now << 1) + 1, lc, (lc + rc) >> 1, l, r),
                &self.__prod((now << 1) + 2, (lc + rc) >> 1, rc, l, r),
            )
        }
    }
    fn prod<R>(&mut self, range: R) -> T::M
    where
        R: std::ops::RangeBounds<usize>,
    {
        let l = match range.start_bound() {
            std::ops::Bound::Included(&a) => a,
            _ => 0,
        };
        let r = match range.end_bound() {
            std::ops::Bound::Excluded(&a) => a,
            std::ops::Bound::Included(&a) => a + 1,
            _ => self.width,
        };
        self.__prod(0, 0, self.width, l, r)
    }
}
0