Submission #757333

# Submission time Handle Problem Language Result Execution time Memory
757333 2023-06-13T05:26:31 Z SanguineChameleon Pyramid Base (IOI08_pyramid_base) C++17
70 / 100
5000 ms 96064 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#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;
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];
vector<int> queries[maxN];
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;
	for (int i = 1; i <= n; i++) {
		queries[i].clear();
	}
	vector<pair<int, int>> events_x;
	vector<pair<int, int>> events_y;
	events_x.emplace_back(1, 0);
	events_x.emplace_back(n + 1, 0);
	events_y.emplace_back(1, 0);
	events_y.emplace_back(m + 1, 0);
	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.emplace_back(lx, i);
			events_x.emplace_back(rx + 1, -i);
			events_y.emplace_back(ly[i], i);
			events_y.emplace_back(ry[i] + 1, -i);
		}
	}
	sort(events_x.begin(), events_x.end());
	sort(events_y.begin(), events_y.end());
	n = 0;
	for (int i = 0; i < (int)events_x.size(); i++) {
		if (i == 0 || events_x[i].first != events_x[i - 1].first) {
			queries[++n].clear();
		}
		int id = events_x[i].second;
		if (id) {
			queries[n].push_back(id);
		}
	}
	n--;
	m = 0;
	for (int i = 0; i < (int)events_y.size(); 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 = 1; i <= n; i++) {
		for (auto id: queries[i]) {
			if (id > 0) {
				update(1, 1, m, ly[id], ry[id], cost[id]);
			}
			else {
				update(1, 1, m, ly[-id], ry[-id], -cost[-id]);
			}
		}
		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 15 ms 23872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24020 KB Output is correct
2 Correct 65 ms 24036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 24132 KB Output is correct
2 Correct 34 ms 24012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 24976 KB Output is correct
2 Correct 67 ms 24744 KB Output is correct
3 Correct 58 ms 24740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 26800 KB Output is correct
2 Correct 277 ms 26684 KB Output is correct
3 Correct 248 ms 26872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 233 ms 28260 KB Output is correct
2 Correct 77 ms 27116 KB Output is correct
3 Correct 108 ms 27796 KB Output is correct
4 Correct 368 ms 28364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 29476 KB Output is correct
2 Correct 460 ms 28908 KB Output is correct
3 Correct 181 ms 28892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 323 ms 30092 KB Output is correct
2 Correct 644 ms 29624 KB Output is correct
3 Correct 662 ms 29548 KB Output is correct
4 Correct 644 ms 29872 KB Output is correct
5 Correct 675 ms 29664 KB Output is correct
6 Correct 162 ms 28964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5088 ms 61556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5051 ms 78788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5016 ms 96064 KB Time limit exceeded
2 Halted 0 ms 0 KB -