Submission #570285

# Submission time Handle Problem Language Result Execution time Memory
570285 2022-05-29T07:07:25 Z 600Mihnea Nuclearia (CEOI15_nuclearia) C++17
0 / 100
414 ms 620624 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

signed main() {
 /// ios::sync_with_stdio(0); cin.tie(0);

  freopen ("input.txt", "r", stdin);

  bool Inverse = 0;

  int n, m;
  cin >> n >> m;
  if (n > m) {
    Inverse = 1;
    swap(n, m);
  }
  assert(n <= m);
  vector<vector<ll>> deri(n + 3, vector<ll> (m + 3, 0)),
                     jmen(n + 3, vector<ll> (m + 3, 0)),
                     difs(n + 3, vector<ll> (m + 3, 0)),
                        v(n + 3, vector<ll> (m + 3, 0));

  function<void(int, int, int, int, int)> proc = [&] (int dist, int r, int c, int a, int b) {
    int stop = min(max(m - c, c - 1), a / b);
    assert(a - dist * b >= 1);
    int L = max(1, c - dist), R = min(m, c + dist);
    jmen[r][L] += (a - dist * b);
    jmen[r][R + 1] -= (a - dist * b);
    if (dist + 1 <= min(stop, m - c) || 1) {
      L = c + dist + 1;
      R = min(c + stop, m);
      if (L > R) assert(L == R + 1);
      jmen[r][L] += (a + 1LL * b * c);
      jmen[r][R + 1] -= (a + 1LL * b * c);
      difs[r][L] -= 1LL * b * L;
      deri[r][L + 1] -= b;
      deri[r][R + 1] += b;
      difs[r][R + 1] += 1LL * b * R;
    }
    if (dist + 1 <= min(stop, c - 1)) {
      L = max(c - stop, 1);
      R = c - dist - 1;
      if (L > R) assert(L == R + 1);
      jmen[r][L] += (a - 1LL * b * c);
      jmen[r][R + 1] -= (a - 1LL * b * c);
      difs[r][L] += 1LL * b * L;
      deri[r][L + 1] += b;
      deri[r][R + 1] -= b;
      difs[r][R + 1] -= 1LL * b * R;
    }
  };

  int ops;
  cin >> ops;
  for (int i = 1; i <= ops; i++) {
    int r, c, a, b;
    cin >> r >> c >> a >> b;
    if (Inverse) {
      swap(r, c);
    }
    for (int dist = 0; (r + dist <= n || r - dist >= 1) && a - dist * b >= 1; dist++) {
      if (r + dist <= n) {
        proc(dist, r + dist, c, a, b);
      }
      if (r - dist >= 1 && dist >= 1) {
        proc(dist, r - dist, c, a, b);
      }
    }
  }
  for (int r = 1; r <= n; r++) {
    for (int c = 1; c <= m; c++) {
      deri[r][c] += deri[r][c - 1];
      difs[r][c] += deri[r][c];
      difs[r][c] += difs[r][c - 1];
      jmen[r][c] += jmen[r][c - 1];
      v[r][c] += jmen[r][c];
      v[r][c] += difs[r][c];
    }
  }
  {

    for (int i = 1; i <= n; i++) {
      ll cur = 0;
      for (int j = 1; j <= m; j++) {
        cur += v[i][j];
        v[i][j] = v[i - 1][j] + cur;
      }
    }
  }

  int q;
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    if (Inverse) {
      swap(r1, c1);
      swap(r2, c2);
    }
    ll total = v[r2][c2] - v[r1 - 1][c2] - v[r2][c1 - 1] + v[r1 - 1][c1 - 1];
    ll area = (r2 - r1 + 1) * (c2 - c1 + 1);

    cout << total / area + (total % area >= area - total % area) << "\n";
  }
}

Compilation message

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:10:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |   freopen ("input.txt", "r", stdin);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 370 ms 620488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 414 ms 620624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 333 ms 620432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 327 ms 620392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 329 ms 620460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 363 ms 620488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 327 ms 620396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 362 ms 620376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 334 ms 620420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 350 ms 620388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 350 ms 620396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 347 ms 620472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 338 ms 620608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 386 ms 620528 KB Output isn't correct
2 Halted 0 ms 0 KB -