Submission #139163

# Submission time Handle Problem Language Result Execution time Memory
139163 2019-07-31T10:26:15 Z lyc Nuclearia (CEOI15_nuclearia) C++14
30 / 100
1000 ms 187656 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][y-1] - v[x-1][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[x2][y1-1] + v[x1-1][y1-1];

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

# Verdict Execution time Memory Grader output
1 Correct 159 ms 176484 KB Output is correct
2 Correct 80 ms 4728 KB Output is correct
3 Correct 74 ms 3940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 176504 KB Output is correct
2 Correct 81 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 59384 KB Output is correct
2 Correct 80 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 64884 KB Output is correct
2 Correct 86 ms 4732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 294 ms 181128 KB Output is correct
2 Correct 86 ms 5368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 224 ms 75568 KB Output is correct
2 Correct 89 ms 4676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 64248 KB Output is correct
2 Correct 89 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 52276 KB Output is correct
2 Correct 85 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 421 ms 187640 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 444 ms 187656 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 64376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 64248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 65144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 64504 KB Time limit exceeded
2 Halted 0 ms 0 KB -