Problems Submissions
Register Login 質問(Gitter) GitHub

Submit Info #3659

Problem Lang User Status Time Memory
Convolution rust ziita1111 WA 5000 ms 36.71 MiB

ケース詳細
Name Status Time Memory
example_00 WA 5 ms 0.60 MiB
example_01 WA 5 ms 0.62 MiB
fft_killer_00 TLE 5000 ms -1 Mib
fft_killer_01 TLE 5000 ms -1 Mib
max_random_00 TLE 5000 ms -1 Mib
max_random_01 TLE 5000 ms -1 Mib
medium_00 WA 79 ms 1.82 MiB
medium_01 WA 42 ms 1.22 MiB
medium_02 WA 79 ms 1.79 MiB
random_00 TLE 5000 ms -1 Mib
random_01 TLE 5000 ms -1 Mib
random_02 WA 2873 ms 36.71 MiB
small_00 WA 3 ms 0.62 MiB
small_01 WA 5 ms 0.62 MiB
small_02 WA 5 ms 0.60 MiB
small_03 WA 7 ms 0.62 MiB
small_04 WA 5 ms 0.68 MiB
small_05 WA 5 ms 0.60 MiB
small_06 WA 5 ms 0.62 MiB
small_07 WA 5 ms 0.61 MiB
small_08 WA 6 ms 0.61 MiB
small_09 WA 6 ms 0.67 MiB
small_10 WA 5 ms 0.67 MiB
small_11 WA 6 ms 0.60 MiB
small_12 WA 5 ms 0.65 MiB
small_13 WA 4 ms 0.62 MiB
small_14 WA 6 ms 0.67 MiB
small_15 WA 6 ms 0.59 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(mut c: Vec<i64>, inv: bool, mo: i64, g: i64) -> Vec<i64>{ let n = c.len(); 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 // bit reverse let mut idx = 0; for j in 1..n-1 { let mut k = (n>>1); loop { idx ^= k; if k<=idx {break;} k >>= 1; } if j < idx {c.swap(idx,j);} } let mut i = 1; loop { let d = i*2; let mut w: i64 = 1; let mut base = mod_pow(h,(n/d) as i64,mo); for j in 0..i { for k in 0..n/d { let s = j + d * k; let x = c[s]; let y = c[s+i]; c[s] = (x + y * w) % mo; c[s+i] = (x - y * w) % mo; if c[s+i] < 0 {c[s+i] += mo;} } w = w * base % mo; } i *= 2; if i==n {break;} } c } 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 p = vec![(998244353,3),(985661441,3),(975175681,3)]; let mut A = vec![vec![];p.len()]; for i in 0..p.len(){ let (mo,g) = p[i]; 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); A[i] = ans.iter().map(|x| x*mod_inv(n as i64,mo)%mo).collect::<Vec<i64>>(); } let mut R = vec![0;n]; for i in 0..n { let mut b = (0..p.len()).map(|x| A[x][i]).collect::<Vec<i64>>(); let mut m = (0..p.len()).map(|x| p[x].0).collect::<Vec<i64>>(); let ret = garner(b, m, MOD as i64); R[i] = ret; } R } fn garner(mut b: Vec<i64>, mut m: Vec<i64>, mo: i64) -> i64{ b.push(0); m.push(mo); let mut constant = vec![0;m.len()]; let mut coff = vec![1;m.len()]; for i in 0..m.len()-1 { let mut v = (b[i]-constant[i])*mod_inv(coff[i],m[i])%m[i]; if v<0 {v+=m[i];} for j in i+1..m.len() { constant[j] += v * coff[j]; constant[j] %= m[j]; coff[j] *= m[i]; coff[j] %= m[j]; } for j in 0..m.len() { } } constant[m.len()-1] } 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(); }