Submission #757317

# Submission time Handle Problem Language Result Execution time Memory
757317 2023-06-13T05:08:01 Z SanguineChameleon Pyramid Base (IOI08_pyramid_base) C++17
80 / 100
5000 ms 77860 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 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();
	}
	for (int i = 1; i <= K; i++) {
		int lx = max(1, Lx[i] - sz + 1);
		int rx = min(n, Rx[i]);
		int ly = max(1, Ly[i] - sz + 1);
		int ry = min(m, Ry[i]);
		if (lx <= rx && ly <= ry) {
			queries[lx].push_back(i);
			if (rx < n) {
				queries[rx + 1].push_back(-i);
			}
		}
	}
	reset(1, 1, m);
	for (int i = 1; i <= n; i++) {
		for (auto id: queries[i]) {
			if (id > 0) {
				int lt = max(1, Ly[id] - sz + 1);
				int rt = min(m, Ry[id]);
				update(1, 1, m, lt, rt, cost[id]);
			}
			else {
				int lt = max(1, Ly[-id] - sz + 1);
				int rt = min(m, Ry[-id]);
				update(1, 1, m, lt, rt, -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 14 ms 23848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 26212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 32308 KB Output is correct
2 Correct 221 ms 40668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 40848 KB Output is correct
2 Correct 77 ms 32228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24276 KB Output is correct
2 Correct 50 ms 24620 KB Output is correct
3 Correct 42 ms 24640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 28340 KB Output is correct
2 Correct 244 ms 28876 KB Output is correct
3 Correct 186 ms 28856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 277 ms 36848 KB Output is correct
2 Correct 76 ms 28772 KB Output is correct
3 Correct 155 ms 40980 KB Output is correct
4 Correct 483 ms 49112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 47980 KB Output is correct
2 Correct 854 ms 50744 KB Output is correct
3 Correct 124 ms 34392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 37808 KB Output is correct
2 Correct 1130 ms 53112 KB Output is correct
3 Correct 988 ms 52784 KB Output is correct
4 Correct 1156 ms 52904 KB Output is correct
5 Correct 1176 ms 53136 KB Output is correct
6 Correct 78 ms 33484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4893 ms 75288 KB Output is correct
2 Correct 993 ms 55576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5060 ms 77268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5031 ms 77860 KB Time limit exceeded
2 Halted 0 ms 0 KB -