結果
問題 | No.1234 典型RMQ |
ユーザー | fukafukatani |
提出日時 | 2020-09-18 22:10:49 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 776 ms / 2,000 ms |
コード長 | 3,131 bytes |
コンパイル時間 | 13,519 ms |
コンパイル使用メモリ | 378,532 KB |
実行使用メモリ | 7,444 KB |
最終ジャッジ日時 | 2024-11-09 01:55:03 |
合計ジャッジ時間 | 28,668 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 576 ms
6,048 KB |
testcase_07 | AC | 555 ms
5,372 KB |
testcase_08 | AC | 583 ms
6,892 KB |
testcase_09 | AC | 568 ms
6,016 KB |
testcase_10 | AC | 578 ms
6,412 KB |
testcase_11 | AC | 576 ms
6,268 KB |
testcase_12 | AC | 572 ms
5,576 KB |
testcase_13 | AC | 559 ms
5,372 KB |
testcase_14 | AC | 572 ms
5,736 KB |
testcase_15 | AC | 566 ms
5,512 KB |
testcase_16 | AC | 578 ms
6,268 KB |
testcase_17 | AC | 570 ms
5,676 KB |
testcase_18 | AC | 528 ms
5,248 KB |
testcase_19 | AC | 583 ms
6,100 KB |
testcase_20 | AC | 462 ms
6,412 KB |
testcase_21 | AC | 579 ms
6,292 KB |
testcase_22 | AC | 776 ms
7,060 KB |
testcase_23 | AC | 774 ms
7,184 KB |
testcase_24 | AC | 773 ms
7,444 KB |
testcase_25 | AC | 774 ms
7,064 KB |
testcase_26 | AC | 773 ms
7,316 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: unused variable: `i` --> src/main.rs:33:9 | 33 | for i in 0..q { | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::<usize>(); let mut a = read_vec::<i64>(); let num_buckets = 1000; let bucket_width = 1000; let mut bucket_added = vec![0; num_buckets]; let mut bucket_min = vec![std::i64::MAX; num_buckets]; for i in 0..n { bucket_min[i / bucket_width] = min(a[i], bucket_min[i / bucket_width]); } let q = read::<usize>(); let mut queries = vec![]; for i in 0..q { let v = read_vec::<i64>(); let (k, l, r, c) = (v[0], v[1] as usize - 1, v[2] as usize - 1, v[3]); queries.push((k, l, r, c)); } for (k, l, r, c) in queries { if k == 1 { let mut tl = 0; let mut tr = bucket_width - 1; for bi in 0..num_buckets { if r < tl || l > tr { // Nothing } else if l <= tl && r >= tr { bucket_added[bi] += c; bucket_min[bi] += c; } else { for i in 0..bucket_width { if i + tl >= l && i + tl <= r { a[i + tl] += c; } } bucket_min[bi] = std::i64::MAX; for i in 0..bucket_width { if i + tl >= n { break; } bucket_min[bi] = min(a[i + tl] + bucket_added[bi], bucket_min[bi]); } } tl += bucket_width; tr += bucket_width; } } else { let mut tl = 0; let mut tr = bucket_width - 1; let mut ans = std::i64::MAX; for bi in 0..num_buckets { if r < tl || l > tr { // Nothing } else if l <= tl && r >= tr { ans = min(ans, bucket_min[bi]); } else { for i in 0..bucket_width { if i + tl >= l && i + tl <= r { if i + tl >= n { break; } ans = min(ans, a[i + tl] + bucket_added[bi]); } } } tl += bucket_width; tr += bucket_width; } println!("{}", ans); } } } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }