Submission #109502

# Submission time Handle Problem Language Result Execution time Memory
109502 2019-05-06T18:19:57 Z naoai Nuclearia (CEOI15_nuclearia) C++14
11 / 100
1000 ms 139276 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
const int nmax = 25e5;

vector<vector<i64>> s;

i64 sum[nmax + 1];

struct aintnod {
    i64 s, r;
} aint[4 * nmax + 1];

void update (int nod, int x, int y, int st, int dr, int a, int b) {
    if (st <= x && y <= dr) {
        aint[nod].s += a;
        aint[nod].r += b;
        return ;
    }

    int mij = (x + y) / 2;
    if (st <= mij)
        update(2 * nod, x, mij, st, dr, a, b);
    if (mij < dr)
        update(2 * nod + 1, mij + 1, y, st, dr, a, b);
}

void build (int nod, int x, int y) {
    if (x == y) {
        sum[x] = aint[nod].s;
        return ;
    }

    int mij = (x + y) / 2;

    update(2 * nod, x, mij, x, mij, aint[nod].s, aint[nod].r);
    update(2 * nod + 1, mij + 1, y, mij + 1, y, aint[nod].s + aint[nod].r * (mij + 1 - x), aint[nod].r);

    build(2 * nod, x, mij);
    build(2 * nod + 1, mij + 1, y);
}

int main () {
    int w, h, n;
    cin >> w >> h >> n;

    if (1LL * n * w * h <= 1e8) {
        s.resize(w + 1);
        for (int i = 0; i <= w; ++ i)
            s[i].resize(h + 1, 0);

        for (int i = 1; i <= n; ++ i) {
            int x, y, a, b;
            cin >> x >> y >> a >> b;

            for (int j = 1; j <= w; ++ j)
                for (int k = 1; k <= h; ++ k) {
                    int c = max(0LL, a - 1LL * b * max(abs(x - j), abs(y - k)));
                    s[j][k] += c;
                }
        }

        for (int i = 1; i <= w; ++ i)
            for (int j = 1; j <= h; ++ j)
                s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];

    } else if (h == 1) {
        for (int i = 1; i <= n; ++ i) {
            int x, y, a, b;
            cin >> x >> y >> a >> b;

            int pfin = min(w, x + a / b);
            update(1, 1, w, x, pfin, a, -b);

            pfin = max(1, x - a / b);
            if (pfin <= x - 1)
                update(1, 1, n, pfin, x - 1, a % b, b);
        }

        build(1, 1, w);
        for (int i = 1; i <= w; ++ i)
            sum[i] += sum[i - 1];

        int q;
        cin >> q;
        for (int i = 1; i <= q; ++ i) {
            int a, b, x, y;
            cin >> a >> b >> x >> y;

            i64 total = sum[x] - sum[a - 1];
            i64 arie = (x - a + 1);
            i64 r = total / arie;
            if (total % arie >= (arie + 1) / 2) ++ r;

            cout << r << "\n";
        }
        exit(0);
    } else {
        cout << "-1\n";
    }

    int q;
    cin >> q;
    for (int i = 1; i <= q; ++ i) {
        int a, b, x, y;
        cin >> a >> b >> x >> y;

        i64 total = s[x][y] - s[a - 1][y] - s[x][b - 1] + s[a - 1][b - 1];
        i64 arie = (x - a + 1) * (y - b + 1);
        i64 r = total / arie;
        if (total % arie >= (arie + 1) / 2) ++ r;

        cout << r << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 137336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 137408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 308 ms 20136 KB Output is correct
2 Correct 461 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 287 ms 20984 KB Output is correct
2 Correct 480 ms 2728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 139276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 55464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 840 ms 22372 KB Output is correct
2 Correct 475 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 29568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 384 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 384 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -