Submission #139167

# Submission time Handle Problem Language Result Execution time Memory
139167 2019-07-31T10:36:13 Z lyc Nuclearia (CEOI15_nuclearia) C++14
55 / 100
1000 ms 182056 KB
//#define DEBUG
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MAXN = 2e5+5;

int W,H,N,Q;
bool flag;
struct Plant { int x, y, a, b; };

#ifdef DEBUG
    #define DBG(...) __VA_ARGS__
#else
    #define DBG(...)
#endif

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> W >> H; flag = (W>H); if (flag) swap(W,H);
    cin >> N; Plant plant[N]; FOR(i,0,N-1) { int x,y,a,b; cin >> x >> y >> a >> b; if (flag) swap(x,y); plant[i] = {x,y,a,b}; }

    //sort(plant,plant+N,[](Plant a, Plant b) { return a.x < b.x; });
    ll m[W+2][H+2], c[W+2][H+2], v[W+2][H+2];
    memset(m, 0, sizeof m);
    memset(c, 0, sizeof c);
    memset(v, 0, sizeof v);
    //int idx = 0;
    for (Plant p : plant) {
        //if (idx++ != 1) continue;
        int r = (p.a + p.b - 1) / p.b - 1;
        DBG(cout << "PLANT " << p.x << " " << p.y << " :: r " << r << endl;)
        RFOR(i,r,0) if (p.x-r+i >= 1) {
            int ry = r-i;
            int ca = p.a - p.b * (r - i);
            DBG(cout << "PROCESS COL " << p.x-r+i << " :: ry " << ry << endl;)
            //ca - b*((p.y - ry) - y) = ca - b*p.y + b*ry + b*y
            DBG(cout << "SEG " << max(1,p.y-r) << " " << max(1,p.y-ry) << " " << min(H,p.y+ry+1) << " " << min(H,p.y+r+1) << endl;)
            DBG(cout << "\t\tVAR c " << ca - p.b * p.y + p.b * ry << " m " << p.b << endl;)
            c[p.x-r+i][max(1,p.y-r)] += (ll) ca - (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x-r+i][max(1,p.y-r)] += p.b;
            c[p.x-r+i][max(1,p.y-ry)] -= (ll) ca - (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x-r+i][max(1,p.y-ry)] -= p.b;

            c[p.x-r+i][max(1,p.y-ry)] += ca;
            c[p.x-r+i][min(H+1,p.y+ry+1)] -= ca;

            //ca - b*(y - (p.y + ry)) = ca + b*p.y + b*ry - b*y
            DBG(cout << "\t\tVAR c " << ca + p.b * p.y + p.b * ry << " m " << -p.b << endl;)
            c[p.x-r+i][min(H+1,p.y+ry+1)] += (ll) ca + (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x-r+i][min(H+1,p.y+ry+1)] += -p.b;
            c[p.x-r+i][min(H+1,p.y+r+1)] -= (ll) ca + (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x-r+i][min(H+1,p.y+r+1)] -= -p.b;
        } else break;
        RFOR(i,r-1,0) if (p.x+r-i <= W) {
            int ry = r-i;
            int ca = p.a - p.b * (r - i);
            DBG(cout << "PROCESS COL " << p.x+r-i << " :: ry " << ry << endl;)
            //ca - b*((p.y - ry) - y) = ca - b*p.y + b*ry + b*y
            DBG(cout << "SEG " << max(1,p.y-r) << " " << max(1,p.y-ry) << " " << min(H,p.y+ry+1) << " " << min(H,p.y+r+1) << endl;)
            c[p.x+r-i][max(1,p.y-r)] += (ll) ca - (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x+r-i][max(1,p.y-r)] += p.b;
            c[p.x+r-i][max(1,p.y-ry)] -= (ll) ca - (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x+r-i][max(1,p.y-ry)] -= p.b;

            c[p.x+r-i][max(1,p.y-ry)] += ca;
            c[p.x+r-i][min(H+1,p.y+ry+1)] -= ca;

            //ca - b*(y - (p.y + ry)) = ca + b*p.y + b*ry - b*y
            c[p.x+r-i][min(H+1,p.y+ry+1)] += (ll) ca + (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x+r-i][min(H+1,p.y+ry+1)] += -p.b;
            c[p.x+r-i][min(H+1,p.y+r+1)] -= (ll) ca + (ll) p.b * p.y + (ll) p.b * ry;
            m[p.x+r-i][min(H+1,p.y+r+1)] -= -p.b;
        } else break;
    }

    FOR(x,1,W) FOR(y,1,H) {
        m[x][y] += m[x][y-1];
        c[x][y] += c[x][y-1];
        v[x][y] = (ll) m[x][y] * y + c[x][y];
        v[x][y] += v[x-1][y] - v[x-1][y-1] + v[x][y-1];
    }

    DBG(FOR(x,1,W) { FOR(y,1,H) { cout << m[x][y] << ' '; } cout << endl; } cout << endl;)
    DBG(FOR(x,1,W) { FOR(y,1,H) { cout << c[x][y] << ' '; } cout << endl; } cout << endl;)
    DBG(FOR(x,1,W) { FOR(y,1,H) { cout << v[x][y] << ' '; } cout << endl; } cout << endl;)

    cin >> Q; FOR(q,0,Q-1) {
        int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; 
        if (flag) swap(x1,y1), swap(x2,y2);
        ll s = v[x2][y2] - v[x1-1][y2] + v[x1-1][y1-1] - v[x2][y1-1];

        ll r = (ll)(x2-x1+1)*(y2-y1+1);
        cout << (ll)round((long double)s/r) << '\n';
    }
}

# Verdict Execution time Memory Grader output
1 Correct 158 ms 176508 KB Output is correct
2 Correct 84 ms 2680 KB Output is correct
3 Correct 76 ms 2416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 176564 KB Output is correct
2 Correct 84 ms 2748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 59264 KB Output is correct
2 Correct 85 ms 2780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 64832 KB Output is correct
2 Correct 84 ms 2728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 300 ms 178680 KB Output is correct
2 Correct 89 ms 3036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 73208 KB Output is correct
2 Correct 83 ms 2780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 61708 KB Output is correct
2 Correct 88 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 49740 KB Output is correct
2 Correct 82 ms 2812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 182056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 181960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 62584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 62328 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 63068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 62416 KB Time limit exceeded
2 Halted 0 ms 0 KB -