제출 #1022680

#제출 시각아이디문제언어결과실행 시간메모리
1022680vjudge1Nuclearia (CEOI15_nuclearia)C++14
55 / 100
1073 ms258536 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...