Submission #259229

# Submission time Handle Problem Language Result Execution time Memory
259229 2020-08-07T12:36:08 Z vioalbert Nuclearia (CEOI15_nuclearia) C++14
0 / 100
1000 ms 176876 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 2500005;
ll w, h, n, q;
vector<vector<ll>> grid;
ll st[4*N], lazy[4*N];

void build(int idx, int l, int r) {
	if(l == r) {
		st[idx] = grid[1][l];
		lazy[idx] = 0;
		return;
	}
	int mid = (l+r)/2, lc = idx<<1, rc = idx<<1|1;
	build(lc, l, mid);
	build(rc, mid+1, r);
	st[idx] = st[lc] + st[rc];
}

void push(int idx, int l, int r) {
	if(l < r && lazy[idx]) {
		int mid = (l+r)/2, lc = idx<<1, rc = idx<<1|1;
		st[lc] += lazy[idx] * (mid - l + 1), lazy[lc] += lazy[idx];
		st[rc] += lazy[idx] * (r - mid), lazy[rc] += lazy[idx];
	}
	lazy[idx] = 0;
}

void update(int idx, int l, int r, int x, int y, ll val) {
	push(idx, l, r);
	if(r < x || y < l) return;
	if(x <= l && r <= y) {
		st[idx] += (r - l + 1) * val;
		lazy[idx] = val;
		return;
	}
	int mid = (l+r)/2, lc = idx<<1, rc = idx<<1|1;
	update(lc, l, mid, x, y, val);
	update(rc, mid+1, r, x, y, val);
	st[idx] = st[lc] + st[rc];
}

ll query(int idx, int l, int r, int x, int y) {
	push(idx, l, r);
	if(r < x || y < l) return 0;
	if(x <= l && r <= y) return st[idx];
	int mid = (l+r)/2, lc = idx<<1, rc = idx<<1|1;
	ll const lq = query(lc, l, mid, x, y);
	ll const rq = query(rc, mid+1, r, x, y);
	return lq + rq;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> w >> h >> n;
	grid.assign(h+1, vector<ll>(w+1, 0));
	build(1, 1, w);
	for(int i = 0; i < n; i++) {
		ll x, y, a, b; cin >> x >> y >> a >> b;
		ll len = (a + b - 1) / b;
		ll loc = (x - len + 1 < 1ll) ? 1 : (x - len + 1);
		ll fi = a - (x - loc) * b;
		// cerr << loc << ' ' << fi << '\n';
		update(1, 1, w, loc, loc, fi);
		if(loc + 1 <= x)
			update(1, 1, w, loc + 1, x, b);
		if(x + 1 <= w)
			update(1, 1, w, x + 1, min(w, x + len - 1), -b);
		if(x + len <= w)
			update(1, 1, w, x+len, x+len, -fi);
	}
	for(int i = 1; i <= w; i++) {
		grid[1][i] = query(1, 1, w, 1, i);
		// cerr << grid[1][i] << ' ';
	}
	// cerr << '\n';
	build(1, 1, w);

	cin >> q;
	while(q--) {
		ll r1, c1, r2, c2; cin >> c1 >> r1 >> c2 >> r2;
		// cerr << r1 << ' ' << c1 << ' ' << r2 << ' ' << c2 << '\n';
		double ans = query(1, 1, w, c1, c2);
		ans /= 1.0 * (r2 - r1 + 1) * (c2 - c1 + 1);
		cout << (ll)(ans+0.5) << '\n';
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 701 ms 170884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 671 ms 170808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 20224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 24832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1002 ms 176876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 516 ms 53352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 134 ms 22136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 358 ms 31148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1104 ms 174608 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 174824 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 440 ms 22136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 444 ms 22008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 268 ms 22776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 432 ms 22520 KB Output isn't correct
2 Halted 0 ms 0 KB -