Submission #511146

# Submission time Handle Problem Language Result Execution time Memory
511146 2022-01-15T09:17:48 Z CraniXort Nuclearia (CEOI15_nuclearia) C++17
0 / 100
1 ms 460 KB
#include <bits/stdc++.h>

// #define fin std::cin
// #define fout std::cout

std::ifstream fin("nuclearia.in");
std::ofstream fout("nuclearia.out");

long long n, m;
long long **x, **c;
long long *line;


void update(long long i, long long left, long long right, long long value) {
    if(left <= 0) {
        line[i] += std::min(right - left + 1, -left + 1) * value;
        left = 1;
    }
    right = std::max(right, 0LL);
    right = std::min(right, m);

    x[i][left] += value;
    x[i][right+1] -= value;
        

}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    fin >> n >> m;

    x = new long long* [n+2];
    c = new long long* [n+2];
    line = new long long [n+2];
    for(long long i = 0; i<= n+1; i ++) {
        x[i] = new long long[m+2];
        c[i] = new long long[m+2];
    }

    long long plants;
    fin >> plants;

    for(long long p = 0; p < plants; p ++) {
        long long pi, pj, a, b;
        fin >> pi >> pj >> a >> b;
        
        long long maxDist = (a - 1) / b;
        long long dist, left, right;

        long long x1 = pi - maxDist; x1 = std::max(x1, 1LL);
        long long y1 = pj - maxDist; y1 = std::max(y1, 1LL);
        long long x2 = pi + maxDist; x2 = std::min(x2, n);
        long long y2 = pj + maxDist; y2 = std::min(y2, m);

        long long add = a - (maxDist) * b;
        c[x1][y1] += add;
        c[x1][y2+1] -= add;
        c[x2+1][y1] -= add;
        c[x2+1][y2+1] += add;

        maxDist --;

        for(long long i = std::max(1LL, pi - maxDist); i <= std::min(n, pi + maxDist); i ++) {
            dist = std::abs(i - pi);

            //interval 1
            left = pj - maxDist;
            
            right = left + (maxDist - dist);

            update(i, left, right, b);
            

            //interval 3
            right = pj + maxDist + 1;
            left = pj + dist + 1;

            update(i, left, right, -b);
        }
    }

    for(long long i = 1; i <= n; i ++) {
        for(long long j = 1; j <= m; j ++) {
            x[i][j] += x[i][j-1];
            c[i][j] = c[i][j] + c[i-1][j] + c[i][j-1] - c[i-1][j-1];
        }
    }

     for(long long i = 1; i <= n; i ++) {
        for(long long j = 1; j <= m; j ++) {
            x[i][j] += x[i][j-1];
        }
    }

    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= n; j++)
            x[i][j] += line[i] + c[i][j];

    long long sum[n+2][m+2] = {};
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            sum[i][j] = x[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
        }

    int Q;
    fin >> Q;
    while(Q --) {
        int x1, y1, x2, y2;
        fin >> x1 >> y1 >> x2 >> y2;

        long long total = sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1];
        long long size = (x2 - x1 + 1) * (y2 - y1 + 1);

        long long ans = total / size;
        if(2 * (total % size) >= size)
            ans += 1;

        fout << ans << '\n';

    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -