Problems Submissions
Register Login 質問(Gitter) GitHub

Submit Info #3652

Problem Lang User Status Time Memory
Convolution rust ziita1111 AC 4035 ms 78.10 MiB

ケース詳細
Name Status Time Memory
example_00 AC 5 ms 0.67 MiB
example_01 AC 5 ms 0.62 MiB
fft_killer_00 AC 4035 ms 78.08 MiB
fft_killer_01 AC 4032 ms 78.09 MiB
max_random_00 AC 4032 ms 78.10 MiB
max_random_01 AC 4033 ms 78.09 MiB
medium_00 AC 63 ms 1.94 MiB
medium_01 AC 35 ms 1.40 MiB
medium_02 AC 63 ms 1.84 MiB
random_00 AC 3993 ms 75.14 MiB
random_01 AC 4006 ms 78.08 MiB
random_02 AC 1970 ms 41.22 MiB
small_00 AC 3 ms 0.62 MiB
small_01 AC 5 ms 0.66 MiB
small_02 AC 6 ms 0.64 MiB
small_03 AC 5 ms 0.64 MiB
small_04 AC 5 ms 0.61 MiB
small_05 AC 5 ms 0.62 MiB
small_06 AC 6 ms 0.59 MiB
small_07 AC 5 ms 0.63 MiB
small_08 AC 6 ms 0.68 MiB
small_09 AC 7 ms 0.64 MiB
small_10 AC 5 ms 0.68 MiB
small_11 AC 3 ms 0.62 MiB
small_12 AC 7 ms 0.62 MiB
small_13 AC 4 ms 0.63 MiB
small_14 AC 5 ms 0.59 MiB
small_15 AC 5 ms 0.62 MiB

#![allow(unused_imports)] #![allow(non_snake_case, unused)] use std::cmp::*; use std::collections::*; use std::ops::*; macro_rules! eprint { ($($t:tt)*) => {{ use ::std::io::Write; let _ = write!(::std::io::stderr(), $($t)*); }}; } macro_rules! eprintln { () => { eprintln!(""); }; ($($t:tt)*) => {{ use ::std::io::Write; let _ = writeln!(::std::io::stderr(), $($t)*); }}; } macro_rules! dbg { ($v:expr) => {{ let val = $v; eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val); val }} } macro_rules! mat { ($($e:expr),*) => { Vec::from(vec![$($e),*]) }; ($($e:expr,)*) => { Vec::from(vec![$($e),*]) }; ($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) }; ($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) }; } macro_rules! ok { ($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => { $a$([$i])*.$f($($t),*) }; ($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { { let t = $e; ok!($a$([$i])*.$f($($es),*)$(@$t)*@t) } }; } 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)),*) }; } pub fn main() { let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join(); } const MOD: u32 = 1_000_000_007; const INF: usize = std::usize::MAX/2; pub trait SetMinMax { fn setmin(&mut self, v: Self) -> bool; fn setmax(&mut self, v: Self) -> bool; } impl<T> SetMinMax for T where T: PartialOrd { fn setmin(&mut self, v: T) -> bool { *self > v && { *self = v; true } } fn setmax(&mut self, v: T) -> bool { *self < v && { *self = v; true } } } // https://math314.hateblo.jp/entry/2015/05/07/014908 fn ntt(c: Vec<i64>, inv: bool, mo: i64, g: i64) -> Vec<i64>{ let n = c.len(); if n==1 { return c; } let c1: Vec<i64> = (0..n/2).map(|x| c[2*x]).collect(); let c2: Vec<i64> = (0..n/2).map(|x| c[2*x+1]).collect(); let r1 = ntt(c1, inv, mo, g); let r2 = ntt(c2, inv, mo, g); let mut ret = vec![0;n]; let mut h = mod_pow(g,(mo-1)/(n as i64),mo); // (h ^ n) == 1 (mod mo) if inv {h = mod_inv(h,mo);} // h = h ^ -1 let mut base = 1; for i in 0..n { ret[i] = r1[i%(n/2)] + base * r2[i%(n/2)]; ret[i] %= mo; base = base * h % mo; } ret } fn conv(mut a1: Vec<i64>, mut a2: Vec<i64>) -> Vec<i64> { let sz = a1.len()+a2.len(); let mut n = 1; while sz>n {n*=2;} while a1.len()<n { a1.push(0);} while a2.len()<n { a2.push(0);} // https://www.cnblogs.com/Guess2/p/8422205.html // https://lumakernel.github.io/ecasdqina/math/FFT/NTT let mo = 998244353; let g = 3; let f1 = ntt(a1.clone(),false,mo,g); let f2 = ntt(a2.clone(),false,mo,g); let c1: Vec<i64> = (0..n).map(|x| f1[x]*f2[x]%mo).collect(); let ans = ntt(c1.clone(),true,mo,g); let A = ans.iter().map(|x| x*mod_inv(n as i64,mo)%mo).collect::<Vec<i64>>(); A } fn mod_pow(mut a: i64, n: i64, mo: i64) -> i64{ a %= mo; if a == 0 { return 0; } let mut lo = n; let mut ret = 1; let mut x = a; while lo > 0 { if lo % 2 == 1 { ret = ret * x % mo; } x = x * x % mo; lo /= 2; } ret } fn mod_inv(a: i64, mo: i64) -> i64{ mod_pow(a,mo-2,mo) } fn solve() { let (n,m) = read!(usize,usize); let a = read!([i64]); let b = read!([i64]); let ret = conv(a,b); for i in 0..(n+m-1){ print!("{} ", ret[i]); } } fn run() { solve(); }