Submission #854548

#TimeUsernameProblemLanguageResultExecution timeMemory
854548Nhoksocqt1Nuclearia (CEOI15_nuclearia)C++17
100 / 100
253 ms185200 KiB
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define sz(x) int((x).size()) #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int MAXN = 200005; const int MAXM = 2500006; const int SQRT = 1600; struct Point { int x, y, a, b; } p[MAXN]; struct Query { int x, y, u, v; } qr[MAXN]; vector<ll> sum[SQRT], f[SQRT], g[SQRT]; int row, col, nArr, numQuery; inline void addRec(int x, int y, int u, int v, int w) { sum[x][y] += w; sum[u + 1][y] -= w; sum[x][v + 1] -= w; sum[u + 1][v + 1] += w; } void magicFunc(void) { for (int i = 0; i <= row + 1; ++i) { sum[i].assign(col + 2, 0); f[i].assign(col + 2, 0); g[i].assign(col + 2, 0); } for (int i = 1; i <= nArr; ++i) { int x(p[i].x), y(p[i].y), a(p[i].a), b(p[i].b), d(a / b); addRec(max(x - d, 1), max(y - d, 1), min(x + d, row), min(y + d, col), a); addRec(x, y, x, y, b); } for (int i = 1; i <= nArr; ++i) { int x(p[i].x), y(p[i].y), a(p[i].a), b(p[i].b), d(a / b); int z = max(1, min(d, max(x, y) - 1)); f[max(1, x - 1)][max(1, y - 1)] += b; g[max(1, x - z)][max(1, y - z)] -= 1LL * b * (z + 1); if(x - d - 1 < 1 && y - d - 1 < 1) continue; f[max(1, x - d - 1)][max(1, y - d - 1)] -= b; } for (int i = row; i > 0; --i) { for (int j = col; j > 0; --j) { sum[i][j] += g[i][j] + f[i][j]; f[max(1, i - 1)][max(1, j - 1)] += f[i][j]; f[i][j] = g[i][j] = 0; } } for (int i = 1; i <= nArr; ++i) { int x(p[i].x), y(p[i].y), a(p[i].a), b(p[i].b), d(a / b); ++x, ++y; if(x >= row || y >= col) continue; f[min(row, x + 1)][min(col, y + 1)] += b; if(x + d <= row && y + d <= col) g[min(row, x + d)][min(col, y + d)] -= 1LL * b * (d + 1); if(x + d + 1 > row || y + d + 1 > col) continue; f[min(row, x + d + 1)][min(col, y + d + 1)] -= b; } for (int i = 1; i <= row; ++i) { for (int j = 1; j <= col; ++j) { sum[i][j] += g[i][j] + f[i][j]; f[min(row + 1, i + 1)][min(col + 1, j + 1)] += f[i][j]; f[i][j] = g[i][j] = 0; } } for (int i = 1; i <= nArr; ++i) { int x(p[i].x), y(p[i].y), a(p[i].a), b(p[i].b), d(a / b); ++x; if(x >= row) continue; f[min(row, x + 1)][max(1, y - 1)] -= b; if(x + d <= row) g[min(row, x + d)][max(1, y - d)] += 1LL * b * (d + 1); if(x + d + 1 > row) continue; f[min(row, x + d + 1)][max(1, y - d - 1)] += b; } for (int i = 1; i <= row; ++i) { for (int j = col; j > 0; --j) { sum[i][j] += g[i][j] + f[i][j]; f[min(row + 1, i + 1)][max(1, j - 1)] += f[i][j]; f[i][j] = g[i][j] = 0; } } for (int i = 1; i <= nArr; ++i) { int x(p[i].x), y(p[i].y), a(p[i].a), b(p[i].b), d(a / b); ++y; if(y >= col) continue; f[max(1, x - 1)][min(col, y + 1)] -= b; if(y + d <= col) g[max(1, x - d)][min(col, y + d)] += 1LL * b * (d + 1); if(y + d + 1 > col) continue; f[max(1, x - d - 1)][min(col, y + d + 1)] += b; } for (int i = row; i > 0; --i) { for (int j = 1; j <= col; ++j) { sum[i][j] += g[i][j] + f[i][j]; f[max(1, i - 1)][min(col + 1, j + 1)] += f[i][j]; f[i][j] = g[i][j] = 0; } } for (int i = 1; i <= row; ++i) { for (int j = 1; j <= col; ++j) { sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; } } for (int i = 1; i <= row; ++i) { for (int j = 1; j <= col; ++j) { sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; } } for (int t = 0; t < numQuery; ++t) { int x(qr[t].x), y(qr[t].y), u(qr[t].u), v(qr[t].v), sizen = (u - x + 1) * (v - y + 1); ll totRad = sum[u][v] - sum[u][y - 1] - sum[x - 1][v] + sum[x - 1][y - 1]; cout << totRad / sizen + (totRad % sizen >= (sizen + 1) / 2) << '\n'; } } void process() { cin >> row >> col >> nArr; bool isSwapped = (row > col); if(isSwapped) swap(row, col); for (int i = 1; i <= nArr; ++i) { cin >> p[i].x >> p[i].y >> p[i].a >> p[i].b; p[i].b = min(p[i].b, p[i].a); if(isSwapped) swap(p[i].x, p[i].y); } cin >> numQuery; for (int t = 0; t < numQuery; ++t) { cin >> qr[t].x >> qr[t].y >> qr[t].u >> qr[t].v; if(isSwapped) { swap(qr[t].x, qr[t].y); swap(qr[t].u, qr[t].v); } } magicFunc(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); process(); 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...