Submission #757342

# Submission time Handle Problem Language Result Execution time Memory
757342 2023-06-13T05:36:36 Z SanguineChameleon Pyramid Base (IOI08_pyramid_base) C++17
80 / 100
5000 ms 45552 KB
#include <bits/stdc++.h>
using namespace std;

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

const int maxN = 1e6 + 20;
const int maxK = 4e5 + 20;
int tree[maxN << 2];
int lazy[maxN << 2];
int Lx[maxN];
int Ly[maxN];
int Rx[maxN];
int Ry[maxN];
int ly[maxN];
int ry[maxN];
int cost[maxN];
int queries[maxK << 2];
pair<int, int> events_x[maxK << 1];
pair<int, int> events_y[maxK << 1];
int N, M, B, K;

void reset(int id, int lt, int rt) {
	tree[id] = 0;
	lazy[id] = 0;
	if (lt == rt) {
		return;
	}
	int mt = (lt + rt) >> 1;
	reset(id << 1, lt, mt);
	reset(id << 1 | 1, mt + 1, rt);
}

void update(int id, int lt, int rt, int ql, int qr, int add) {
	if (lt == ql && rt == qr) {
		tree[id] += add;
		lazy[id] += add;
		return;
	}
	tree[id << 1] += lazy[id];
	lazy[id << 1] += lazy[id];
	tree[id << 1 | 1] += lazy[id];
	lazy[id << 1 | 1] += lazy[id];
	lazy[id] = 0;
	int mt = (lt + rt) >> 1;
	if (qr <= mt) {
		update(id << 1, lt, mt, ql, qr, add);
	}
	else if (ql >= mt + 1) {
		update(id << 1 | 1, mt + 1, rt, ql, qr, add);
	}
	else {
		update(id << 1, lt, mt, ql, mt, add);
		update(id << 1 | 1, mt + 1, rt, mt + 1, qr, add);
	}
	tree[id] = min(tree[id << 1], tree[id << 1 | 1]);
}

bool check(int sz) {
	int n = N - sz + 1;
	int m = M - sz + 1;
	events_x[0].first = 1;
	events_x[0].second = 0;
	events_x[1].first = n + 1;
	events_x[1].second = 0;
	events_y[0].first = 1;
	events_y[0].second = 0;
	events_y[1].first = m + 1;
	events_y[1].second = 0;
	int sz_x = 2;
	int sz_y = 2;
	for (int i = 1; i <= K; i++) {
		int lx = max(1, Lx[i] - sz + 1);
		int rx = min(n, Rx[i]);
		ly[i] = max(1, Ly[i] - sz + 1);
		ry[i] = min(m, Ry[i]);
		if (lx <= rx && ly[i] <= ry[i]) {
			events_x[sz_x].first = lx;
			events_x[sz_x].second = i;
			events_x[sz_x + 1].first = rx + 1;
			events_x[sz_x + 1].second = -i;
			sz_x += 2;
			events_y[sz_y].first = ly[i];
			events_y[sz_y].second = i;
			events_y[sz_y + 1].first = ry[i] + 1;
			events_y[sz_y + 1].second = -i;
			sz_y += 2;
		}
	}
	sort(events_x, events_x + sz_x);
	sort(events_y, events_y + sz_y);
	n = 0;
	int sz_q = 0;
	for (int i = 0; i < sz_x; i++) {
		if (i == 0 || events_x[i].first != events_x[i - 1].first) {
			if (n) {
				queries[sz_q++] = 0;
			}
			n++;
		}
		int id = events_x[i].second;
		if (id) {
			queries[sz_q++] = id;
		}
	}
	n--;
	m = 0;
	for (int i = 0; i < sz_y; i++) {
		if (i == 0 || events_y[i].first != events_y[i - 1].first) {
			m++;
		}
		int id = events_y[i].second;
		if (id > 0) {
			ly[id] = m;
		}
		else {
			ry[-id] = m - 1;
		}
	}
	m--;
	reset(1, 1, m);
	for (int i = 0; i < sz_q; i++) {
		int id = queries[i];
		if (id > 0) {
			update(1, 1, m, ly[id], ry[id], cost[id]);
		}
		else if (id < 0) {
			update(1, 1, m, ly[-id], ry[-id], -cost[-id]);
		}
		else if (tree[1] <= B) {
			return true;
		}
	}
	return false;
}

void just_do_it() {
	cin >> N >> M >> B >> K;
	for (int i = 1; i <= K; i++) {
		cin >> Lx[i] >> Ly[i] >> Rx[i] >> Ry[i] >> cost[i];
	}
	int res = 0;
	int lt = 1;
	int rt = min(N, M);
	while (lt <= rt) {
		int mt = (lt + rt) >> 1;
		if (check(mt)) {
			res = mt;
			lt = mt + 1;
		}
		else {
			rt = mt - 1;
		}
	}
	cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 15 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 528 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 832 KB Output is correct
2 Correct 50 ms 896 KB Output is correct
3 Correct 47 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 2004 KB Output is correct
2 Correct 221 ms 2012 KB Output is correct
3 Correct 204 ms 2112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 2324 KB Output is correct
2 Correct 41 ms 1848 KB Output is correct
3 Correct 81 ms 2732 KB Output is correct
4 Correct 225 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 278 ms 3240 KB Output is correct
2 Correct 432 ms 3252 KB Output is correct
3 Correct 136 ms 2472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 3100 KB Output is correct
2 Correct 544 ms 3608 KB Output is correct
3 Correct 502 ms 3660 KB Output is correct
4 Correct 536 ms 3580 KB Output is correct
5 Correct 543 ms 3632 KB Output is correct
6 Correct 130 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4209 ms 23336 KB Output is correct
2 Correct 1264 ms 15440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5094 ms 30332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5099 ms 45552 KB Time limit exceeded
2 Halted 0 ms 0 KB -