From c5fcf7179a83ef65c86c6a4a390029149e518649 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Tue, 5 Oct 2021 21:49:54 +0200 Subject: Duzy commit ze smieciami --- semestr-4/sieci/warsztaty8/psp0.cpp | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 semestr-4/sieci/warsztaty8/psp0.cpp (limited to 'semestr-4/sieci/warsztaty8/psp0.cpp') diff --git a/semestr-4/sieci/warsztaty8/psp0.cpp b/semestr-4/sieci/warsztaty8/psp0.cpp new file mode 100644 index 0000000..676bcb8 --- /dev/null +++ b/semestr-4/sieci/warsztaty8/psp0.cpp @@ -0,0 +1,44 @@ +#include +#include +using namespace std; +#define rand_mod 1000000033 +int rozm, zapy, ds[200000], dl; +typedef long long LL; +LL sum, wcz[200000], rand_plus, ele[6]; +bool cmp(int x, int y) +{ + return wcz[x] < wcz[y]; +} +int main() +{ + scanf("%d%Ld", &rozm, &rand_plus); + scanf("%d", &zapy); + for (int i = 0; i < zapy; ++i) + { + scanf("%Ld%Ld", wcz + 2 * i, wcz + 2 * i + 1); + --wcz[2 * i]; + } + for (int i = 0; i < 2 * zapy; ++i) + ds[i] = i; + sort(ds, ds + 2 * zapy, cmp); + while (dl < 2 * zapy && !wcz[ds[dl]]) + ++dl; + + for (int i = 1; i <= rozm; ++i) + { + ele[0] = (ele[1] * ele[1]) % rand_mod; + ele[0] += ((ele[2] + ele[3]) * (ele[2] + ele[3])) % rand_mod; + ele[0] += (ele[4] * ele[5]) % rand_mod; + ele[0] += (rand_plus * rand_plus) % rand_mod; + ele[0] += i % rand_mod; + ele[0] %= rand_mod; + sum += ele[0]; + while (dl < 2 * zapy && wcz[ds[dl]] == i) + wcz[ds[dl++]] = sum; + for (int i = 4; i >= 0; i--) ele[i+1] = ele[i]; + ele[0] = 0; + } + for (int i = 0; i < zapy; ++i) + printf("%Ld\n", wcz[2 * i + 1] - wcz[2 * i]); + return 0; +} -- cgit v1.2.3