Submission #365912

# Submission time Handle Problem Language Result Execution time Memory
365912 2021-02-12T13:55:39 Z kostia244 Nuclearia (CEOI15_nuclearia) C++17
30 / 100
1000 ms 61356 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
int n, m, q;
vector<vector<ll>> che;
vector<ll> rur, rul;
	
void init() {
	che.resize(n, vector<ll>(m));
	rur.resize(m);
	rul.resize(m);
}
void add_radius(int x, int y, int r, ll val) {
	che[max(x-r, 0)][max(y-r, 0)] += val;
	if(x+r+1 < n)
		che[x+r+1][max(y-r, 0)] -= val;
	if(y+r+1 < m)
		che[max(x-r, 0)][y+r+1] -= val;
	if(x+r+1 < n && y+r+1 < m)
		che[x+r+1][y+r+1] += val;
}
void add_vert(int x, int y, ll a, ll b) {
	ll maxrad = a/b;
	add_radius(x, y, maxrad, a);
	//cout << a-b*maxrad << ":((" << endl;
	for(ll i = 0; i < min((ll)(n+m), (ll)maxrad); i++) {
		add_radius(x, y, maxrad, -b);
		add_radius(x, y, i, b);
	}
	
}
void finish() {
	for(int it = 0; it < 2; it++) {
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(i) che[i][j] += che[i-1][j];
			if(j) che[i][j] += che[i][j-1];
			if(i&&j) che[i][j] -= che[i-1][j-1];
		}
	}
	
	/*for(auto i : che) {
		for(auto j : i) cout << j << " ";
		cout << endl;
	}*/
	}
}

ll get_rect(int xl, int xr, int yl, int yr) {
	ll sum = che[xr][yr];
	--xl, --yl;
	if(xl>=0) sum -= che[xl][yr];
	if(yl>=0) sum -= che[xr][yl];
	if(xl>=0&&yl>=0) sum += che[xl][yl];
	ll area = (xr-xl)*(yr-yl);
	//cout << xl << " " << xr << " " << yl << " " << yr << " -- " << area << endl;
	ll rem = sum % area;
	return (sum/area) + (rem*2 >= area);
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m >> q;
	int rev = 0;
	if(n > m) swap(n, m), rev = 1;
	init();
	for(int x, y, a, b; q--;) {
		cin >> x >> y >> a >> b;x--, y--;
		if(rev) swap(x, y);
		add_vert(x, y, a, b);
	}
	finish();
	cin >> q;
	for(int xl, xr, yl, yr; q--;) {
		cin >> xl >> yl >> xr >> yr;xl--,xr--,yl--,yr--;
		if(rev) swap(xl, yl);
		if(rev) swap(xr, yr);
		//cout << xl << " " << xr << " " << yl << " " << yr << " QUERY:" << endl;
		cout << get_rect(xl, xr, yl, yr) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 966 ms 59136 KB Output is correct
2 Correct 89 ms 4700 KB Output is correct
3 Correct 78 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 837 ms 59136 KB Output is correct
2 Correct 81 ms 4756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 19948 KB Output is correct
2 Correct 78 ms 4460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 21912 KB Output is correct
2 Correct 82 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 61356 KB Output is correct
2 Correct 91 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 901 ms 26184 KB Output is correct
2 Correct 81 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 22380 KB Output is correct
2 Correct 89 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 18360 KB Output is correct
2 Correct 76 ms 4452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 59040 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 59040 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 19948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 19948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 20812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 19948 KB Time limit exceeded
2 Halted 0 ms 0 KB -