-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathout_data.cpp
More file actions
123 lines (112 loc) · 2.35 KB
/
out_data.cpp
File metadata and controls
123 lines (112 loc) · 2.35 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int SIZE = 200050;
const int mod = 1e9 + 7;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return f * x;
}
int n, ans;
int num[SIZE], siz[SIZE];
inline int quickpow(int a, int b)
{
int res = 1;
int base = a;
while (b) {
if (b & 1)
res = res * base % mod;
base = base * base % mod;
b >>= 1;
}
return res;
}
inline int get_C(int a, int b)
{
return siz[b] * quickpow(siz[a], mod - 2) % mod * quickpow(siz[b - a], mod - 2) % mod;
}
inline void solve_0()
{
int top = (n - 2) / 2, opt = 1;
for (int i = 1; i <= n; ++i) {
ans += (get_C((i - 1) / 2, top) * opt * num[i]) % mod;
ans = (ans + mod) % mod;
opt = opt * -1;
}
}
inline void solve_1()
{
int top = (n - 1) / 2;
bool opt = true;
for (int i = 1; i <= n; ++i) {
if (opt) {
ans = (ans + get_C((i - 1) / 2, top) * num[i]) % mod;
ans = (ans + mod) % mod;
opt = false;
continue;
}
opt = true;
}
}
inline void solve_2()
{
int top = (n - 2) / 2;
for (int i = 1; i <= n; ++i) {
ans += (get_C((i - 1) / 2, top) * num[i]) % mod;
ans = (ans + mod) % mod;
}
}
inline void solve_3()
{
bool opt = true;
for (int i = 1; i <= n; ++i) {
if (opt) {
num[i] = (num[i] + num[i + 1]) % mod;
} else {
num[i] = (num[i] - num[i + 1]) % mod;
}
opt = opt ^ true;
}
n--;
solve_2();
}
signed main()
{
// freopen("14.in","r",stdin);
// freopen("14.out","w",stdout);
n = read();
for (int i = 1; i <= n; ++i) {
num[i] = read();
}
siz[0] = siz[1] = 1;
for (int i = 2; i <= n; ++i) {
siz[i] = siz[i - 1] * i % mod;
}
bool opt = true;
switch (n % 4) {
case 0:
solve_0();
break;
case 1:
solve_1();
break;
case 2:
solve_2();
break;
case 3:
solve_3();
break;
}
printf("%lld\n", ans);
}