Submission #3784613


Source Code Expand

use std::cmp::Ordering;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
    fn upper_bound(&self, &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

fn main() {
    let _: usize = read();
    let a: Vec<u64> = read_vec();
    let b: Vec<u64> = read_vec();

    let mut ans = 0;
    for c in 1..28 {
        let c = 2u64.pow(c);
        let half_c = c / 2;
        let temp_a = a.iter().map(|x| x % c).collect::<Vec<_>>();
        let mut temp_b = b.iter().map(|x| x % c).collect::<Vec<_>>();
        temp_b.sort();
        let mut counts = 0;
        for a_num in temp_a {
            if a_num < half_c {
                let lb = temp_b.lower_bound(&(half_c - a_num));
                let ub = temp_b.lower_bound(&(c - a_num));
                counts += ub - lb;
            } else if a_num == half_c {
                let lb = temp_b.lower_bound(&half_c);
                counts += lb;
            } else {
                let lb = temp_b.lower_bound(&(c - a_num));
                let ub = temp_b.lower_bound(&(c + half_c - a_num));
                counts += temp_b.len() - ub + lb;
            }
        }
        if counts % 2 == 1 {
            ans += half_c;
        }
    }
    println!("{:?}", ans);
}

Submission Info

Submission Time
Task D - Two Sequences
User ryoryoryo111
Language Rust (1.15.1)
Score 0
Code Size 2539 Byte
Status WA
Exec Time 1697 ms
Memory 13788 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 4
AC × 8
WA × 8
Set Name Test Cases
Sample example_0, example_1, example_2, example_3
All N100000_0, N100000_1, N150000_0, N150000_1, N200000_0, N200000_1, N200000_ex_0, N200000_ex_1, example_0, example_1, example_2, example_3, rand_0, rand_1, smallrand_0, smallrand_1
Case Name Status Exec Time Memory
N100000_0 WA 751 ms 10036 KB
N100000_1 WA 746 ms 9928 KB
N150000_0 AC 1195 ms 11484 KB
N150000_1 WA 1194 ms 13628 KB
N200000_0 WA 1697 ms 13388 KB
N200000_1 WA 1695 ms 13384 KB
N200000_ex_0 AC 1622 ms 13788 KB
N200000_ex_1 WA 1619 ms 13388 KB
example_0 AC 2 ms 4352 KB
example_1 AC 2 ms 4352 KB
example_2 AC 2 ms 4352 KB
example_3 AC 2 ms 4352 KB
rand_0 WA 32 ms 4352 KB
rand_1 WA 69 ms 4352 KB
smallrand_0 AC 2 ms 4352 KB
smallrand_1 AC 2 ms 4352 KB