Skip to content

Commit

Permalink
update tessoku-book/a76
Browse files Browse the repository at this point in the history
  • Loading branch information
emanon001 committed Jan 8, 2023
1 parent b073096 commit 0fe6ee5
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tessoku-book/src/bin/a76.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,19 @@ fn solve() {
for (i, x) in xv.iter().copied().enumerate() {
map.insert(x, i);
}
let mut bit: Bit<ModInt> = Bit::new(xv.len() + 1);
let mut bit: Bit<ModInt> = Bit::new(xv.len());
bit.add(0, 1.into());
let mut dp = vec![ModInt::zero(); xv.len()];
dp[0] = 1.into();
for i in 0..xv.len() {
let x = xv[i];
let mut range = map.range((x - r)..=(x - l));
let l = range.clone().next();
let r = range.next_back();
if let (Some((_, &lj)), Some((_, &rj))) = (l, r) {
let sum = bit.range_sum(lj, rj + 1);
dp[i] += sum;
bit.add(i, sum);
}
}
println!("{}", dp[xv.len() - 1]);
println!("{}", bit.range_sum(xv.len() - 1, xv.len()));
}

fn main() {
Expand Down

0 comments on commit 0fe6ee5

Please sign in to comment.