結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2020-02-28 22:04:54 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 212 ms / 2,000 ms |
| コード長 | 2,900 bytes |
| コンパイル時間 | 14,570 ms |
| コンパイル使用メモリ | 378,952 KB |
| 実行使用メモリ | 17,892 KB |
| 最終ジャッジ日時 | 2024-10-13 17:27:47 |
| 合計ジャッジ時間 | 18,160 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
warning: unused variable: `i`
--> src/main.rs:23:9
|
23 | for i in 0..q {
| ^ help: if this is intentional, prefix it with an underscore: `_i`
|
= note: `#[warn(unused_variables)]` on by default
warning: field `n` is never read
--> src/main.rs:67:5
|
66 | struct LazySegmentTree {
| --------------- field in this struct
67 | n: usize,
| ^
|
= note: `LazySegmentTree` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `#[warn(dead_code)]` on by default
ソースコード
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
#[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 v = read_vec::<usize>();
let (n, q) = (v[0], v[1]);
let mut a = read_vec::<i64>();
let mut queries = vec![];
for i in 0..q {
let v = read_vec::<String>();
let c = v[0].chars().next().unwrap();
let x: i64 = v[1].parse().ok().unwrap();
let y: i64 = v[2].parse().ok().unwrap();
queries.push((c, x, y));
}
let mut seg = LazySegmentTree::new(n);
let mut b = vec![0; n];
for (c, x, y) in queries {
if c == 'A' {
let x = x as usize - 1;
let count = seg.getsum(x, x + 1, 0, 0, n);
b[x] += a[x] * count;
seg.add(x, x + 1, -count, 0, 0, n);
a[x] += y;
} else {
seg.add(x as usize - 1, y as usize, 1, 0, 0, n);
}
}
for i in 0..n {
b[i] += a[i] * seg.getsum(i, i + 1, 0, 0, n);
}
for num in b {
print!("{} ", num);
}
println!("");
}
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()
}
#[derive(Debug)]
struct LazySegmentTree {
n: usize,
data: Vec<i64>,
datb: Vec<i64>,
}
impl LazySegmentTree {
fn new(sz: usize) -> LazySegmentTree {
let mut n = 1;
while n < sz {
n *= 2;
}
LazySegmentTree {
n: n,
data: vec![0i64; 2 * n - 1],
datb: vec![0i64; 2 * n - 1],
}
}
fn add(&mut self, a: usize, b: usize, x: i64, k: usize, l: usize, r: usize) {
if a <= l && r <= b {
self.data[k] += x;
} else if l < b && a < r {
self.datb[k] += (min(b, r) - max(a, l)) as i64 * x;
self.add(a, b, x, k * 2 + 1, l, (l + r) / 2);
self.add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
fn getsum(&mut self, a: usize, b: usize, k: usize, l: usize, r: usize) -> i64 {
if b <= l || r <= a {
return 0;
}
if a <= l && r <= b {
return self.data[k] * (r - l) as i64 + self.datb[k];
} else {
let mut res = (min(b, r) - max(a, l)) as i64 * self.data[k];
res += self.getsum(a, b, k * 2 + 1, l, (l + r) / 2);
res += self.getsum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
}
}
fukafukatani