#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly
/*
TASK: hidden
LANG: C++11
*/
using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 200013
#define INF 1000000000000000000LL
#define mp make_pair
#define add push_back
#define remove pop
//only works for H = 1 case
int n;
int w, h, q;
int x[MAXN], y[MAXN];
ll a[MAXN], b[MAXN];
//copy from radoslav11 coding library
struct node_ap
{
ll sum, lazy, lazy_ap;
node_ap() {sum = 0; lazy = 0; lazy_ap = 0;}
node_ap(ll val)
{
sum = val;
lazy = 0;
lazy_ap = 0;
}
};
node_ap temp, broken;
node_ap merge(node_ap l, node_ap r) {
temp.sum = l.sum + r.sum;
temp.lazy = 0;
temp.lazy_ap = 0;
return temp;
}
node_ap tr[4 * 2500013];
struct segment_tree_ap {
//node_ap tr[4 * 2500013];
void update(int l, int r, int idx) {
if (tr[idx].lazy) {
tr[idx].sum += (r - l + 1) * tr[idx].lazy;
if (l != r) {
tr[2 * idx].lazy += tr[idx].lazy;
tr[2 * idx + 1].lazy += tr[idx].lazy;
}
tr[idx].lazy = 0;
}
if (tr[idx].lazy_ap) {
int mid = (l + r) >> 1;
tr[idx].sum += (((ll)(r - l + 1)) * (r - l + 2) / 2) * tr[idx].lazy_ap;
if(l != r) {
tr[2 * idx].lazy_ap += tr[idx].lazy_ap;
tr[2 * idx + 1].lazy_ap += tr[idx].lazy_ap;
tr[2 * idx + 1].lazy += tr[idx].lazy_ap * (mid - l + 1);
}
tr[idx].lazy_ap = 0;
}
}
void init(int l, int r, int idx) {
if (l == r) {
tr[idx] = node_ap();
return;
}
int mid = (l + r) >> 1;
init(l, mid, 2 * idx);
init(mid + 1, r, 2 * idx + 1);
tr[idx] = merge(tr[2 * idx], tr[2 * idx + 1]);
}
void update(int qL, int qR, ll val, ll prog, int l, int r, int idx) {
update(l, r, idx);
if (qL > r || l > qR)
return;
if (qL <= l && r <= qR) {
tr[idx].lazy += val + (l - qL) * prog;
tr[idx].lazy_ap += prog;
update(l, r, idx);
return;
}
int mid = (l + r) >> 1;
update(qL, qR, val, prog, l, mid, 2 * idx);
update(qL, qR, val, prog, mid + 1, r, 2 * idx + 1);
tr[idx] = merge(tr[2 * idx], tr[2 * idx + 1]);
}
node_ap query(int qL, int qR, int l, int r, int idx) {
update(l, r, idx);
if(l > qR || r < qL)
return broken;
if(qL <= l && r <= qR)
return tr[idx];
int mid = (l + r) >> 1;
return merge(query(qL, qR, l, mid, 2 * idx), query(qL, qR, mid + 1, r, 2 * idx + 1));
}
};
segment_tree_ap t;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> w >> h;
//assert(h == 1);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> a[i] >> b[i];
}
t.init(0, w + 100, 1); //lol
for (int i = 0; i < n; i++) {
ll possible = (a[i] - 1) / b[i];
if (possible == 0) {
t.update(x[i], x[i], a[i], 0, 0, w + 100, 1);
continue;
}
int start = max(1, (int) (x[i] - possible));
int end = min(w, (int) (x[i] + possible));
//cout << "plant " << i << " found start, end " << start << ' ' << end
//<< endl;
ll startval = a[i] - ((x[i] - (ll)start) * b[i]);
//cout << "startval is " << startval << endl;
t.update(start, x[i], startval - b[i], b[i], 0, w + 100, 1);
if (x[i] + 1 <= end) t.update(x[i] + 1, end, a[i], -b[i], 0, w + 100, 1);
}
cin >> q;
for (int i = 0; i < q; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
//cout << "boudns are " << x1 << ' ' << x2 << endl;
ll sum = t.query(x1, x2, 0, w + 100, 1).sum;
ll cells = x2 - x1 + 1;
//cout << "query " << i << " found sum " << sum << " cells " << cells << endl;
ll remainder = sum % cells;
if ((cells % 2 == 0 && remainder >= cells / 2) || (cells % 2 == 1 && remainder > cells / 2)) {
cout << 1 + sum / cells << endl;
} else {
cout << sum / cells << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
241260 KB |
Output is correct |
2 |
Runtime error |
176 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
241260 KB |
Output is correct |
2 |
Runtime error |
126 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
241260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
241260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
486 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
259 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
139 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
366 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
241260 KB |
Execution timed out |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
241260 KB |
Execution timed out |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
526 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
496 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
396 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
579 ms |
241260 KB |
Execution timed out (wall clock limit exceeded) |
2 |
Halted |
0 ms |
0 KB |
- |