#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<ll, ll>
ll n, m;
ll x, y, a, b;
ll sirina, x2, y2, a2;
ll q, p;
vector <vector<ll>> kvadrat;
vector <vector<ll>> trokut;
vector <vector<ll>> trokut2;
vector <ll> bla;
ll zbr, sol, cnt;
bool granice(int x, int y) {
if (1 <= x && x <= n && 1 <= y && y <= m) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
vector<vector<ll>> mat(n + 2, vector<ll>(m + 2));
vector<vector<ll>> kvadrat(n + 2, vector<ll>(m + 2));
vector<vector<ll>> trokut(n + 2, vector<ll>(m + 2));
vector<vector<ll>> trokut2(n + 2, vector<ll>(m + 2));
cin >> p;
for (int i = 0; i < p; i++) {
cin >> x >> y >> a >> b;
x2 = x;
y2 = y;
a2 = a;
mat[x][y] += a;
sirina = 1;
while (a > 0 && granice(x, 1)) {
trokut[x][max(1ll, y)] += a;
trokut[x][max(1ll, min(m + 1, y + sirina))] -= a;
x--;
y--;
sirina += 2;
a -= b;
}
x = x2;
y = y2;
a = a2;
sirina = 1;
while (a > 0 && granice(x, 1)) {
trokut[x][max(1ll, y)] += a;
trokut[x][max(1ll, min(m + 1, y + sirina))] -= a;
x++;
y--;
sirina += 2;
a -= b;
}
x = x2;
y = y2;
a = a2;
sirina = 1;
while (a > 0 && granice(1, y)) {
trokut2[max(1ll, min(n + 1, x + 1))][y] += a;
trokut2[max(1ll, min(n + 1, x + sirina - 1))][y] -= a;
x--;
y++;
sirina += 2;
a -= b;
}
x = x2;
y = y2;
a = a2;
sirina = 1;
while (a > 0 && granice(1, y)) {
trokut2[max(1ll, min(n + 1, x + 1))][y] += a;
trokut2[max(1ll, min(n + 1, x + sirina - 1))][y] -= a;
x--;
y--;
sirina += 2;
a -= b;
}
}
for (int i = 1; i <= n; i++) {
zbr = 0;
for (int j = 1; j <= m; j++) {
zbr += trokut[i][j];
mat[i][j] += zbr;
}
}
for (int j = 1; j <= m; j++) {
zbr = 0;
for (int i = 1; i <= n; i++) {
zbr += trokut2[i][j];
mat[i][j] += zbr;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
kvadrat[i][j] = kvadrat[i - 1][j] + kvadrat[i][j - 1] - kvadrat[i - 1][j - 1] + mat[i][j];
}
}
cin >> q;
while (q--) {
cin >> x >> y >> x2 >> y2;
sol = kvadrat[x2][y2] - kvadrat[x2][y - 1] - kvadrat[x - 1][y2] + kvadrat[x - 1][y - 1];
cnt = ((x2 - x + 1) * (y2 - y + 1));
if (sol % cnt >= (cnt + 1) / 2) sol = sol / ((x2 - x + 1) * (y2 - y + 1)) + 1;
else sol = sol / ((x2 - x + 1) * (y2 - y + 1));
cout << sol << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1004 ms |
548488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
918 ms |
548456 KB |
Output is correct |
2 |
Correct |
46 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
79832 KB |
Output is correct |
2 |
Correct |
46 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
87604 KB |
Output is correct |
2 |
Correct |
48 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
672 ms |
550480 KB |
Output is correct |
2 |
Correct |
57 ms |
3216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
691 ms |
221936 KB |
Output is correct |
2 |
Correct |
50 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
81488 KB |
Output is correct |
2 |
Correct |
58 ms |
2940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
442 ms |
143784 KB |
Output is correct |
2 |
Correct |
47 ms |
2836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1042 ms |
548216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1055 ms |
548308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1016 ms |
79696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1039 ms |
79184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1028 ms |
80508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
79800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |