結果
| 問題 |
No.1172 Add Recursive Sequence
|
| コンテスト | |
| ユーザー |
noshi91
|
| 提出日時 | 2020-05-10 00:29:26 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 3,487 ms / 4,000 ms |
| コード長 | 3,398 bytes |
| コンパイル時間 | 14,719 ms |
| コンパイル使用メモリ | 379,468 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 20:16:36 |
| 合計ジャッジ時間 | 23,063 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 |
ソースコード
use std::io::{self, Read as _, Write as _};
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
fn new(s: &'a str) -> Self {
Self(s.split_whitespace())
}
fn next<T>(&mut self) -> T
where
T: std::str::FromStr,
T::Err: std::fmt::Debug,
{
let s = self.0.next().expect("found EOF");
match s.parse() {
Ok(v) => v,
Err(msg) => {
println!(
"parse error. T = {}, s = \"{}\": {:?}",
std::any::type_name::<T>(),
s,
msg
);
panic!()
}
}
}
}
mod fp {
use std::convert::From;
use std::ops;
const P: u32 = 1000000007;
#[derive(Copy, Clone)]
pub struct Fp(pub u32);
impl From<i64> for Fp {
fn from(mut x: i64) -> Fp {
x %= P as i64;
if x < 0 {
x += P as i64;
}
Fp(x as u32)
}
}
impl ops::Add<Fp> for Fp {
type Output = Fp;
fn add(mut self, rhs: Fp) -> Fp {
self += rhs;
self
}
}
impl ops::AddAssign<Fp> for Fp {
fn add_assign(&mut self, rhs: Fp) {
self.0 += rhs.0;
if self.0 >= P {
self.0 -= P;
}
}
}
impl ops::Mul<Fp> for Fp {
type Output = Fp;
fn mul(mut self, rhs: Fp) -> Fp {
self *= rhs;
self
}
}
impl ops::MulAssign<Fp> for Fp {
fn mul_assign(&mut self, rhs: Fp) {
self.0 = (self.0 as u64 * rhs.0 as u64 % P as u64) as u32;
}
}
impl ops::Neg for Fp {
type Output = Fp;
fn neg(self) -> Fp {
Fp(match self.0 {
0 => 0,
s => P - s,
})
}
}
impl ops::Sub<Fp> for Fp {
type Output = Fp;
fn sub(mut self, rhs: Fp) -> Fp {
self -= rhs;
self
}
}
impl ops::SubAssign<Fp> for Fp {
fn sub_assign(&mut self, rhs: Fp) {
if self.0 < rhs.0 {
self.0 += P;
}
self.0 -= rhs.0;
}
}
impl std::iter::Sum for Fp {
fn sum<I>(iter: I) -> Fp
where
I: Iterator<Item = Fp>,
{
iter.fold(Fp(0), |s, x| s + x)
}
}
}
use fp::Fp;
fn main() {
let mut stdin = String::new();
std::io::stdin().read_to_string(&mut stdin).unwrap();
let mut sc = Scanner::new(&stdin);
let stdout = io::stdout();
let mut stdout = io::BufWriter::new(stdout.lock());
let k = sc.next();
let n = sc.next();
let m = sc.next();
let mut a = (0..k).map(|_| Fp(sc.next())).collect::<Vec<_>>();
let c = (0..k)
.map(|_| Fp(sc.next()))
.collect::<Vec<_>>()
.into_iter()
.rev()
.collect::<Vec<_>>();
a.reserve_exact(n);
for i in 0..n {
a.push(c.iter().zip(&a[i..]).map(|(&c, &a)| c * a).sum());
}
let mut x = vec![Fp(0); n];
for _ in 0..m {
let (l, r): (usize, usize) = (sc.next(), sc.next());
for i in l..r {
x[i] += a[i - l];
}
}
for Fp(x) in x {
writeln!(stdout, "{}", x).unwrap();
}
stdout.flush().unwrap();
}
noshi91