File tree Expand file tree Collapse file tree 2 files changed +90
-0
lines changed Expand file tree Collapse file tree 2 files changed +90
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "bufio"
5
+ . "fmt"
6
+ "io"
7
+ "os"
8
+ )
9
+
10
+ // github.com/EndlessCheng/codeforces-go
11
+ func CF1466E (_r io.Reader , _w io.Writer ) {
12
+ in := bufio .NewReader (_r )
13
+ out := bufio .NewWriter (_w )
14
+ defer out .Flush ()
15
+ const mod int64 = 1e9 + 7
16
+
17
+ var T , n int64
18
+ for Fscan (in , & T ); T > 0 ; T -- {
19
+ Fscan (in , & n )
20
+ var p2 , c [60 ]int64
21
+ a := make ([]int64 , n )
22
+ for i := range a {
23
+ Fscan (in , & a [i ])
24
+ for j := range c {
25
+ c [j ] += a [i ] >> j & 1
26
+ }
27
+ }
28
+ for i := range c {
29
+ p2 [i ] = 1 << i % mod * n % mod
30
+ c [i ] = 1 << i % mod * c [i ] % mod
31
+ }
32
+ ans := int64 (0 )
33
+ for _ , v := range a {
34
+ var x , y int64
35
+ for j , c := range c {
36
+ if v >> j & 1 > 0 {
37
+ x += c
38
+ y += p2 [j ]
39
+ } else {
40
+ y += c
41
+ }
42
+ }
43
+ ans = (ans + x % mod * (y % mod )) % mod
44
+ }
45
+ Fprintln (out , ans )
46
+ }
47
+ }
48
+
49
+ func main () { CF1466E (os .Stdin , os .Stdout ) }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "github.com/EndlessCheng/codeforces-go/main/testutil"
5
+ "testing"
6
+ )
7
+
8
+ // https://codeforces.com/problemset/problem/1466/E
9
+ // https://codeforces.com/problemset/status/1466/problem/E
10
+ func TestCF1466E (t * testing.T ) {
11
+ // just copy from website
12
+ rawText := `
13
+ inputCopy
14
+ 8
15
+ 2
16
+ 1 7
17
+ 3
18
+ 1 2 4
19
+ 4
20
+ 5 5 5 5
21
+ 5
22
+ 6 2 2 1 0
23
+ 1
24
+ 0
25
+ 1
26
+ 1
27
+ 6
28
+ 1 12 123 1234 12345 123456
29
+ 5
30
+ 536870912 536870911 1152921504606846975 1152921504606846974 1152921504606846973
31
+ outputCopy
32
+ 128
33
+ 91
34
+ 1600
35
+ 505
36
+ 0
37
+ 1
38
+ 502811676
39
+ 264880351`
40
+ testutil .AssertEqualCase (t , rawText , 1 , CF1466E )
41
+ }
You can’t perform that action at this time.
0 commit comments