GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — rustforces/src/apollo_vs_plan_1466E.rs at master · schiemon/rustforces

Expand file tree

/

apollo_vs_plan_1466E.rs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
108 lines (92 loc) · 2.83 KB
/

apollo_vs_plan_1466E.rs

Copy path

File metadata and controls

108 lines (92 loc) · 2.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use std::io::{BufRead, BufReader, Stdin};
fn read_vec<F: std::str::FromStr>(r: &mut BufReader<Stdin>, n: usize) -> Vec<F>
where
<F as std::str::FromStr>::Err: std::fmt::Debug,
{
let mut nums_str = String::new();
r.read_line(&mut nums_str).unwrap();
let nums_vec: Vec<F> = nums_str
.split_whitespace()
.map(|x| x.parse::<F>().unwrap())
.collect();
assert_eq!(nums_vec.len(), n);
nums_vec
}
fn read<F>(r: &mut BufReader<Stdin>) -> F
where
F: std::str::FromStr + Copy,
<F as std::str::FromStr>::Err: std::fmt::Debug,
{
read_vec::<F>(r, 1)[0]
}
fn read_pair<F>(r: &mut BufReader<Stdin>) -> (F, F)
where
F: std::str::FromStr + Copy,
<F as std::str::FromStr>::Err: std::fmt::Debug,
{
match read_vec::<F>(r, 2).as_slice() {
[a, b, ..] => (*a, *b), // We can only get references. Copy this.
[..] => unreachable!("Called read(u32) did not asserted the length of the input."),
}
}
fn read_quadruple<F>(r: &mut BufReader<Stdin>) -> (F, F, F, F)
where
F: std::str::FromStr + Copy,
<F as std::str::FromStr>::Err: std::fmt::Debug,
{
match read_vec::<F>(r, 4).as_slice() {
[a, b, c, d, ..] => (*a, *b, *c, *d), // We can only get references. Copy this.
[..] => unreachable!("Called read(u32) did not asserted the length of the input."),
}
}
const MOD: u64 = 1000000007;
const BITS: usize = 60;
pub fn solve(r: &mut BufReader<Stdin>, pow_of_two: [u64; BITS]) {
let n = read::<usize>(r);
let X = read_vec::<u64>(r, n);
let mut number_bit_owners: [u64; BITS] = [0; BITS];
for x in X.iter() {
for b in 0..BITS {
number_bit_owners[b] += is_set(*x, b);
}
}
for b in 0..BITS {
number_bit_owners[b] %= MOD;
}
// eprintln!("P: {:?}", P);
// eprintln!("B: {:?}", B);
#[inline]
fn is_not_set(x: u64, b: usize) -> u64 {
1 - is_set(x, b)
}
#[inline]
fn is_set(x: u64, b: usize) -> u64 {
(x >> b) & 1
}
let f = |j: usize| -> u64 {
(0..BITS)
.map(|b| (pow_of_two[b] * (n as u64 - is_not_set(X[j], b) * (n as u64 - number_bit_owners[b])) % MOD))
.sum::<u64>()
% MOD
};
let g = |j: usize| -> u64 {
(0..BITS)
.map(|b| (pow_of_two[b] * is_set(X[j], b) * number_bit_owners[b]) % MOD)
.sum::<u64>()
% MOD
};
println!("{}", (0..n).map(|j| f(j) * g(j) % MOD).sum::<u64>() % MOD)
}
pub fn main() {
const MULTI_TEST: bool = true;
let r = &mut BufReader::new(std::io::stdin());
let t = if MULTI_TEST { read::<u32>(r) } else { 1 };
// Compute P (power of two in modulus MOD)
let mut pow_of_two: [u64; BITS] = [1; BITS];
for i in 1..BITS {
pow_of_two[i] = 2 * pow_of_two[i - 1] % MOD;
}
for _ in 0..t {
solve(r, pow_of_two);
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.