-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontest2_task_B.cpp
More file actions
64 lines (62 loc) · 1 KB
/
contest2_task_B.cpp
File metadata and controls
64 lines (62 loc) · 1 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
#include<iostream>
#include<vector>
const uint32_t N = 1 << 24;
const uint64_t MOD = 4294967296;
uint32_t a, b, cur = 0;
uint32_t nextRand()
{
cur = cur * a + b;
return cur >> 8;
}
int main()
{
uint32_t m, q, l, add, r;
std::cin >> m >> q;
std::cin >> a >> b;
std::vector<uint32_t> prefix_summ(N, 0);
std::vector<int64_t> temp(N, 0);
for (size_t i = 0; i < m; i++)
{
add = nextRand();
l = nextRand();
r = nextRand();
if (l > r)
{
std::swap(l, r);
}
temp[l] += add;
temp[l] %= MOD;
temp[r + 1] -= add;
temp[r + 1] %= MOD;
}
uint32_t add_curr = 0, summ = 0;
for (size_t i = 0; i < N; i++)
{
add_curr += temp[i];
add_curr %= MOD;
summ += add_curr;
summ %= MOD;
prefix_summ[i] = summ;
}
uint32_t ans = 0;
for (size_t i = 0; i < q; i++)
{
ans %= MOD;
l = nextRand();
r = nextRand();
if (l > r)
{
std::swap(l, r);
}
if (l != 0)
{
ans += (prefix_summ[r] - prefix_summ[l - 1]);
}
else
{
ans += prefix_summ[r];
}
}
std::cout << ans;
return 0;
}