Skip to content

Commit

Permalink
typical90 064, 066, 067
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jun 15, 2021
1 parent 158ca6e commit b257b7a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
34 changes: 34 additions & 0 deletions typical90/src/bin/064.rs
@@ -0,0 +1,34 @@
use proconio::{input, marker::Usize1};

fn main() {
input! {
n: usize,
q: usize,
a: [i64; n],
lrv: [(Usize1, Usize1, i64); q],
};
let mut x = 0;
// a[0] a[1]
// b[0]
let mut b = vec![0; n];
let mut p = a[0];
for (i, &a_i) in a.iter().enumerate().skip(1) {
b[i] = a_i - p;
x += b[i].abs();
p = a_i;
}
for (l_i, r_i, v_i) in lrv {
if l_i > 0 {
x -= b[l_i].abs();
b[l_i] += v_i;
x += b[l_i].abs();
}
if r_i < n - 1 {
x -= b[r_i + 1].abs();
b[r_i + 1] -= v_i;
x += b[r_i + 1].abs();
}
let ans = x;
println!("{}", ans);
}
}
11 changes: 11 additions & 0 deletions typical90/src/bin/065.rs
@@ -0,0 +1,11 @@
use proconio::input;
use proconio::marker::Usize1;

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
println!("{}", ans);
}
26 changes: 26 additions & 0 deletions typical90/src/bin/066.rs
@@ -0,0 +1,26 @@
use proconio::input;

fn main() {
input! {
n: usize,
lr: [(i64, i64); n],
};
let mut ans = 0_f64;
for i in 0..n {
for j in i + 1..n {
let (l_i, r_i) = lr[i];
let (l_j, r_j) = lr[j];
let all = (r_i - l_i + 1) * (r_j - l_j + 1);
let mut count = 0_i64;
for v_i in l_i..=r_i {
for v_j in l_j..=r_j {
if v_i > v_j {
count += 1;
}
}
}
ans += count as f64 / all as f64;
}
}
println!("{}", ans);
}
26 changes: 26 additions & 0 deletions typical90/src/bin/067.rs
@@ -0,0 +1,26 @@
use proconio::{input, marker::Chars};

fn main() {
input! {
mut n: Chars,
k: usize,
};
for _ in 0..k {
let mut d = u64::from_str_radix(n.iter().collect::<String>().as_str(), 8).unwrap();
if d == 0 {
println!("0");
return;
}
let mut s = vec![];
while d > 0 {
let d_i = (d % 9) as u8;
let d_i = if d_i == 8 { 5 } else { d_i };
s.push((d_i + b'0') as char);
d /= 9;
}
s.reverse();
n = s;
}
let ans = n.iter().collect::<String>();
println!("{}", ans);
}

0 comments on commit b257b7a

Please sign in to comment.