Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <experimental/set>
- int arr[3000][3000], brr[3000][3000];
- int main() {
- int n, m, a, b;
- std::cin >> n >> m >> a >> b;
- long long g, x, y, z;
- std::cin >> g >> x >> y >> z;
- x %= z, y %= z;
- const bool bigTest = (std::max(a, b) > 150 || a * b > 500) && x > 1;
- const int bigConst = 1e9 * 0.006;
- /*
- With great probability in the area of a * b
- there is a value smaller than bigConst
- */
- const int UNREACHABLE_VALUE = 1e9 + 1;
- for (int i=0; i<n; i++) {
- for (int j=0; j < m; j++) {
- arr[i][j] = g;
- if (bigTest && arr[i][j] > bigConst) {
- arr[i][j] = UNREACHABLE_VALUE;
- }
- g = (g * x + y) % z;
- }
- }
- int64_t answer = 0;
- for (int i = 0; i < n; i++) {
- std::experimental::pmr::multiset<int> st;
- for (int j = 0; j < b - 1; j++) {
- if (arr[i][j] != UNREACHABLE_VALUE) {
- st.insert(arr[i][j]);
- }
- }
- for (int j = b - 1; j < m; j++) {
- if (arr[i][j] != UNREACHABLE_VALUE) {
- st.insert(arr[i][j]);
- }
- brr[i][j - b + 1] = *st.begin();
- if (arr[i][j - b + 1] != UNREACHABLE_VALUE) {
- st.erase(st.find(arr[i][j - b + 1]));
- }
- }
- }
- for (int j = 0; j < m - b + 1; j++) {
- std::experimental::pmr::multiset<int> st;
- for (int i = 0; i < a - 1; i++) {
- if (brr[i][j] != UNREACHABLE_VALUE) {
- st.insert(brr[i][j]);
- }
- }
- for (int i = a - 1; i < n; i++) {
- if (brr[i][j] != UNREACHABLE_VALUE) {
- st.insert(brr[i][j]);
- }
- answer += *st.begin();
- if (brr[i - a + 1][j] != UNREACHABLE_VALUE) {
- st.erase(st.find(brr[i - a + 1][j]));
- }
- }
- }
- std::cout << answer;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement