Submission #3435856


Source Code Expand

use std::io::stdin;
use std::str::FromStr;

fn main(){
    let n: usize = get_one();
    let mut xs: Vec<u64> = get_vec();
    let ys: Vec<u64> = get_vec();
    let mut zs: Vec<u64> = get_vec();

    xs.sort();
    zs.sort();

    let mut ans = 0;

    for y in ys.iter() {
        let x_ub = upper_bound(&xs, &|x| x < y);
        let z_lb = lower_bound(&zs, &|z| y < z);
        if let (Some(i), Some(j)) = (x_ub, z_lb) {
            ans += (i+1) as i64 * (n as i64 - j as i64);
        }
    }

    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

fn upper_bound<T, F>(v: &Vec<T>, f: &F) -> Option<usize>
    where F: Fn(&T) -> bool {
    if v.first().map(f) != Some(true) {
        return None;
    }

    let last_idx = (v.len() as i64 -1) as usize;
    if f(&v[last_idx]) {
        return Some(last_idx);
    }

    return Some(upper_bound(v, f, 0, last_idx));

    fn upper_bound<T, F>(v: &Vec<T>, f: &F, left: usize, right: usize) -> usize 
        where F: Fn(&T) -> bool {
        if left+1 == right {
            return left;
        }
        let m = (left + right) / 2;
        if f(&v[m]) {
            return upper_bound(v, f, m, right);
        } else {
            return upper_bound(v, f, left, m);
        }
    }
}

fn lower_bound<T, F>(v: &Vec<T>, f: &F) -> Option<usize>
    where F: Fn(&T) -> bool {
    if v.last().map(f) != Some(true) {
        return None;
    }

    if let Some(i) = upper_bound(v, &|x| !f(x)) {
        return Some(i + 1);
    } else {
        return Some(0);
    }
}

Submission Info

Submission Time
Task C - Snuke Festival
User seiyab
Language Rust (1.15.1)
Score 300
Code Size 2357 Byte
Status AC
Exec Time 66 ms
Memory 13296 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 32
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 66 ms 10356 KB
02.txt AC 66 ms 10356 KB
03.txt AC 57 ms 11372 KB
04.txt AC 57 ms 11372 KB
05.txt AC 49 ms 8444 KB
06.txt AC 49 ms 8444 KB
07.txt AC 40 ms 8444 KB
08.txt AC 40 ms 8444 KB
09.txt AC 33 ms 8444 KB
10.txt AC 33 ms 8444 KB
11.txt AC 25 ms 8444 KB
12.txt AC 25 ms 8444 KB
13.txt AC 41 ms 13168 KB
14.txt AC 41 ms 13168 KB
15.txt AC 41 ms 13168 KB
16.txt AC 41 ms 13296 KB
17.txt AC 41 ms 13168 KB
18.txt AC 41 ms 13168 KB
19.txt AC 66 ms 10360 KB
20.txt AC 11 ms 8444 KB
21.txt AC 11 ms 8444 KB
22.txt AC 31 ms 9972 KB
23.txt AC 52 ms 11576 KB
24.txt AC 51 ms 11512 KB
25.txt AC 52 ms 10248 KB
26.txt AC 2 ms 4352 KB
27.txt AC 2 ms 4352 KB
28.txt AC 2 ms 4352 KB
29.txt AC 2 ms 4352 KB
s1.txt AC 2 ms 4352 KB
s2.txt AC 2 ms 4352 KB
s3.txt AC 2 ms 4352 KB