-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathA.cpp
47 lines (36 loc) · 985 Bytes
/
A.cpp
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
#include <iostream>
using namespace std;
int main() {
freopen("sum0.in", "r", stdin);
freopen("sum0.out", "w", stdout);
int n, x, y, m, z, t;
cin >> n >> x >> y;
int* a = new int[n];
long long* pref = new long long[n];
cin >> a[0];
pref[0] = a[0];
cin >> m >> z >> t;
int* b = new int[2 * m];
int* c = new int[2 * m];
cin >> b[0];
for (int i = 1; i < n; i++) {
a[i] = (x * a[i - 1] + y) % (1 << 16);
pref[i] = a[i] + pref[i - 1];
}
for (int i = 1; i < 2 * m; i++) {
b[i] = (z * b[i - 1] + t) % (1 << 30);
if (b[i] < 0) b[i] = (1 << 30) + b[i];
}
for (int i = 0; i < 2 * m; i++) {
c[i] = b[i] % n;
}
long long res = 0;
for (int i = 0; i < m; i++) {
int r = max(c[2 * i], c[2 * i + 1]);
int l = min(c[2 * i], c[2 * i + 1]);
if (l > 0) res += pref[r] - pref[l - 1];
else res += pref[r];
}
cout << res;
return 0;
}