Submission #511150

#TimeUsernameProblemLanguageResultExecution timeMemory
511150CraniXortNuclearia (CEOI15_nuclearia)C++17
0 / 100
1094 ms729424 KiB
#include <bits/stdc++.h> #define fin std::cin #define fout std::cout // std::ifstream fin("nuclearia.in"); // std::ofstream fout("nuclearia.out"); long long n, m; long long **x, **c; long long *line; void update(long long i, long long left, long long right, long long value) { if(left <= 0) { line[i] += std::min(right - left + 1, -left + 1) * value; left = 1; } right = std::max(right, 0LL); right = std::min(right, m); x[i][left] += value; x[i][right+1] -= value; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); fin >> n >> m; x = new long long* [n+5]; c = new long long* [n+5]; line = new long long [n+5]; for(long long i = 0; i<= n+4; i ++) { x[i] = new long long[m+5]; c[i] = new long long[m+5]; } long long plants; fin >> plants; for(long long p = 0; p < plants; p ++) { long long pi, pj, a, b; fin >> pi >> pj >> a >> b; long long maxDist = (a - 1) / b; long long dist, left, right; long long x1 = pi - maxDist; x1 = std::max(x1, 1LL); long long y1 = pj - maxDist; y1 = std::max(y1, 1LL); long long x2 = pi + maxDist; x2 = std::min(x2, n); long long y2 = pj + maxDist; y2 = std::min(y2, m); long long add = a - (maxDist) * b; c[x1][y1] += add; c[x1][y2+1] -= add; c[x2+1][y1] -= add; c[x2+1][y2+1] += add; maxDist --; for(long long i = std::max(1LL, pi - maxDist); i <= std::min(n, pi + maxDist); i ++) { dist = std::abs(i - pi); //interval 1 left = pj - maxDist; right = left + (maxDist - dist); update(i, left, right, b); //interval 3 right = pj + maxDist + 1; left = pj + dist + 1; update(i, left, right, -b); } } for(long long i = 1; i <= n; i ++) { for(long long j = 1; j <= m; j ++) { x[i][j] += x[i][j-1]; c[i][j] = c[i][j] + c[i-1][j] + c[i][j-1] - c[i-1][j-1]; } } for(long long i = 1; i <= n; i ++) { for(long long j = 1; j <= m; j ++) { x[i][j] += x[i][j-1]; } } for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j++) x[i][j] += line[i] + c[i][j]; long long sum[n+5][m+5] = {}; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) { sum[i][j] = x[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]; } int Q; fin >> Q; while(Q --) { int x1, y1, x2, y2; fin >> x1 >> y1 >> x2 >> y2; long long total = sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1]; long long size = (x2 - x1 + 1) * (y2 - y1 + 1); long long ans = total / size; if(2 * (total % size) >= size) ans += 1; fout << ans << '\n'; } 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...