Submission #1022680

# Submission time Handle Problem Language Result Execution time Memory
1022680 2024-07-13T22:40:21 Z vjudge1 Nuclearia (CEOI15_nuclearia) C++14
55 / 100
1000 ms 258536 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int MAX_N = 200005;
const int MOD = 998244353;

void solve() {
    bool swapped = 0;
    int w, h;
    cin >> w >> h;
    if(w > h) {
        swap(w,h);
        swapped = 1;
    }
    int n;
    cin >> n;
    vector<vector<int>>grid(w, vector<int>(h, 0)), pref(w, vector<int>(h, 0));
    vector<array<int,4>>v(n);
    for(int i=0; i<n; ++i) {
        cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
        --v[i][0], --v[i][1];
        if(swapped) swap(v[i][0], v[i][1]);
    }
    for(int i=0; i<w; ++i) {
        vector<pair<int,int>>cnt(h, {0,0}), cnt2(h, {0,0});
        vector<vector<int>>L(h), R(h);
        for(int j=0; j<n; ++j) {
            int dist = abs(i - v[j][0]), a = v[j][2], b = v[j][3], tmp = a/b;
            if(a%b==0) --tmp;
            if(a <= b*dist) continue;
            L[max(0LL,v[j][1] - dist)].push_back(a - b*dist);
            R[min(h-1,v[j][1] + dist)].push_back(a - b*dist);
            if((v[j][1]+dist+1) < h && a > (dist+1) * b) {
                cnt[v[j][1]+dist+1].first -= b;
                cnt2[v[j][1]+dist+1].first += a - dist * b;
                if((v[j][1]+tmp+1) < h) {
                    cnt[v[j][1]+tmp+1].first += b;
                    cnt2[v[j][1]+tmp+1].first += tmp * b - a;
                }
            }
            if(v[j][1] > dist && a > (dist+1) * b) {
                cnt2[v[j][1]-dist-1].second += a - dist * b;
                cnt[v[j][1]-dist-1].second -= b;
                if(v[j][1]-1 >= tmp) {
                    cnt[v[j][1]-tmp-1].second += b;
                    cnt2[v[j][1]-tmp-1].second += tmp * b - a;
                }
            }
        }
        int tmp = 0, Cnt = 0, prev = 0;
        for(int j=0; j<h; ++j) {
            for(int x: L[j]) tmp += x;
            grid[i][j] = tmp;
            Cnt += cnt[j].first;
            grid[i][j] += Cnt + prev + cnt2[j].first;
            prev = grid[i][j] - tmp;
            for(int x: R[j]) tmp -= x;
        }
        Cnt = prev = 0;
        for(int j=h-1; j>=0; --j) {
            Cnt += cnt[j].second;
            tmp = grid[i][j];
            grid[i][j] += Cnt + prev + cnt2[j].second;
            prev = grid[i][j] - tmp;
        }
    }
    for(int i=w-1; i>=0; --i) {
        for(int j=h-1; j>=0; --j) {
            pref[i][j] += grid[i][j];
            if(i+1 < w) pref[i][j] += pref[i+1][j];
            if(j+1 < h) pref[i][j] += pref[i][j+1];
            if(i+1 < w && j+1 < h) pref[i][j] -= pref[i+1][j+1];
        }
    }
    int q;
    cin >> q;
    while(q--) {
        long double x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        --x1, --y1, --x2, --y2;
        if(swapped) {
            swap(x1, y1);
            swap(x2, y2);
        }
        long double sum = 0;
        sum = pref[x1][y1];
        if(x2+1<w) sum -= pref[x2+1][y1];
        if(y2+1<h) sum -= pref[x1][y2+1];
        if(x2+1<w && y2+1<h) sum += pref[x2+1][y2+1];
        long double x = sum/((x2-x1+1)*(y2-y1+1));
        cout << lround(x) << endl;
    }
}

signed main() {
    int t = 1;
    while(t--) solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 122 ms 254684 KB Output is correct
2 Correct 345 ms 4644 KB Output is correct
3 Correct 423 ms 3868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 254688 KB Output is correct
2 Correct 390 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 40028 KB Output is correct
2 Correct 385 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 50520 KB Output is correct
2 Correct 383 ms 4724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 254776 KB Output is correct
2 Correct 399 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 536 ms 102204 KB Output is correct
2 Correct 383 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 45488 KB Output is correct
2 Correct 405 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 59224 KB Output is correct
2 Correct 392 ms 4264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 896 ms 258476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 852 ms 258536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 52312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 51976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 58332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1034 ms 55548 KB Time limit exceeded
2 Halted 0 ms 0 KB -