結果
| 問題 | No.3411 Range Clamp Sum |
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2025-12-18 04:18:41 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 303 ms / 10,000 ms |
| コード長 | 1,986 bytes |
| 記録 | |
| コンパイル時間 | 15,074 ms |
| コンパイル使用メモリ | 400,332 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-18 04:19:03 |
| 合計ジャッジ時間 | 18,205 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
let n: usize = sc.next();
let q: usize = sc.next();
let mut a: Vec<i32> = sc.next_vec(n);
for _ in 0..q {
let op = sc.next::<u32>();
if op == 1 {
let x = sc.next::<usize>() - 1;
let y = sc.next::<i32>();
a[x] = y;
} else {
let l = sc.next::<usize>() - 1;
let r = sc.next::<usize>();
let p = sc.next::<i32>();
let q = sc.next::<i32>();
let ans = unsafe { calc(&mut a[l..r], p, q)};
writeln!(out, "{ans}").ok();
}
}
}
#[target_feature(enable = "avx2")]
unsafe fn calc(a: &[i32], p: i32, q: i32) -> i64 {
a.iter().map(|&a| a.max(p).min(q) as i64).sum::<i64>()
}
// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
use std::str::FromStr;
pub struct Scanner<'a> {
it: std::str::SplitWhitespace<'a>,
}
impl<'a> Scanner<'a> {
pub fn new(s: &'a String) -> Scanner<'a> {
Scanner {
it: s.split_whitespace(),
}
}
pub fn next<T: FromStr>(&mut self) -> T {
self.it.next().unwrap().parse::<T>().ok().unwrap()
}
pub fn next_bytes(&mut self) -> Vec<u8> {
self.it.next().unwrap().bytes().collect()
}
pub fn next_chars(&mut self) -> Vec<char> {
self.it.next().unwrap().chars().collect()
}
pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
(0..len).map(|_| self.next()).collect()
}
}
}
// ---------- end scannner ----------
use std::io::Write;
fn main() {
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
let mut sc = scanner::Scanner::new(&s);
let out = std::io::stdout();
let mut out = std::io::BufWriter::new(out.lock());
run(&mut sc, &mut out);
}
akakimidori