답안 #540207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540207 2022-03-19T16:29:06 Z alextodoran Nuclearia (CEOI15_nuclearia) C++17
6 / 100
931 ms 1048576 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N, M;
    cin >> N >> M;
    vector <vector <ll>> mat (N + 2, vector <ll> (M + 2, 0));

    vector <vector <ll>> UL = mat;
    vector <vector <ll>> UR = mat;
    vector <vector <ll>> DL = mat;
    vector <vector <ll>> DR = mat;
    vector <vector <ll>> U = mat;
    vector <vector <ll>> D = mat;
    vector <vector <ll>> L = mat;
    vector <vector <ll>> R = mat;

    function <void (int, int, int, int)> addUL = [&] (int x, int y, int len, int val) {
        mat[1][1] += (ll) val * max(0, len - max(x, y));
        DR[x][y] += val;
        if (x - len + 1 >= 1 && y - len + 1 >= 1) {
            DR[x - len][y - len] -= val;
        } else {
            int mn = min(x, y) - 1;
            x -= mn; y -= mn;
            DR[x - 1][y - 1] -= val;
            len -= mn;
            if (y == 1) {
                D[x - 1][y] += val;
                if (x - len >= 1) {
                    D[x - len][y] -= val;
                }
            } else if (x == 1) {
                R[x][y - 1] += val;
                if (y - len >= 1) {
                    R[x][y - len] -= val;
                }
            }
        }
    };
    function <void (int, int, int, int)> addUR = [&] (int x, int y, int len, int val) {
        DL[x][y] += val;
        if (x - len + 1 >= 1 && y + len - 1 <= M) {
            DL[x - len][y - len] -= val;
        } else {
            int mn = min(x, M - y + 1) - 1;
            x -= mn; y += mn;
            DL[x - 1][y + 1] -= val;
            len -= mn;
            if (x == 1) {
                L[x][y + 1] += val;
                if (y + len <= M) {
                    L[x][y + len] -= val;
                }
            }
        }
    };
    function <void (int, int, int, int)> addDL = [&] (int x, int y, int len, int val) {
        UR[x][y] += val;
        if (x + len - 1 <= N && y - len + 1 >= 1) {
            UR[x + len][y - len] -= val;
        } else {
            int mn = min(N - x + 1, y) - 1;
            x += mn; y -= mn;
            UR[x + 1][y - 1] -= val;
            len -= mn;
            if (y == 1) {
                U[x + 1][y] += val;
                if (x + len <= N) {
                    U[x + len][y] -= val;
                }
            }
        }
    };
    function <void (int, int, int, int)> addDR = [&] (int x, int y, int len, int val) {
        UL[x][y] += val;
        if (x + len <= N && y + len <= M) {
            UL[x + len][y + len] -= val;
        }
    };
    function <void (int, int, int, int)> add = [&] (int x, int y, int len, int val) {
        int x1 = x - len + 1, y1 = y - len + 1;
        int x2 = x + len - 1, y2 = y + len - 1;
        x1 = max(1, x1); y1 = max(1, y1);
        x2 = min(N, x2); y2 = min(M, y2);
        mat[x1][y1] += val;
        mat[x1][y2 + 1] -= val;
        mat[x2 + 1][y1] -= val;
        mat[x2 + 1][y2 + 1] += val;
    };

    int K;
    cin >> K;
    while (K--) {
        int x, y, a, b;
        cin >> x >> y >> a >> b;
        int len = a / b;
        addUL(x, y, len, +b);
        addUR(x, y + 1, len, -b);
        addDL(x + 1, y, len, -b);
        addDR(x + 1, y + 1, len, +b);
        add(x, y, len + 1, a % b);
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            UL[i][j] += UL[i - 1][j - 1];
            UR[i][j] += UR[i - 1][j + 1];
            U[i][j] += U[i - 1][j];
            L[i][j] += L[i][j - 1];
        }
    }
    for (int i = N; i >= 1; i--) {
        for (int j = M; j >= 1; j--) {
            DL[i][j] += DL[i + 1][j - 1];
            DR[i][j] += DR[i + 1][j + 1];
            D[i][j] += D[i + 1][j];
            R[i][j] += R[i][j + 1];
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            mat[i][j] += UL[i][j];
            mat[i][j] += UR[i][j];
            mat[i][j] += DL[i][j];
            mat[i][j] += DR[i][j];
            mat[i][j] += U[i][j];
            mat[i][j] += D[i][j];
            mat[i][j] += L[i][j];
            mat[i][j] += R[i][j];
            mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
        }
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
        }
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        ll sum = mat[x2][y2] - mat[x1 - 1][y2] - mat[x2][y1 - 1] + mat[x1 - 1][y1 - 1];
        ll area = (ll) (x2 - x1 + 1) * (y2 - y1 + 1);
        cout << (ll) round((long double) sum / area) << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 931 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 889 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 178872 KB Output is correct
2 Runtime error 63 ms 4560 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 194128 KB Output is correct
2 Correct 68 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 791 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 659 ms 499428 KB Output is correct
2 Correct 67 ms 4576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 227 ms 183100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 428 ms 323160 KB Output is correct
2 Runtime error 65 ms 4556 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 803 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 801 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 394 ms 188708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 363 ms 187684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 332 ms 189220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 509 ms 372172 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -