답안 #54201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54201 2018-07-02T19:24:07 Z baactree Pyramid Base (IOI08_pyramid_base) C++17
70 / 100
5000 ms 71508 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tree[1 << 21][2];
const ll inf = 0x3f3f3f3f3f3f3f3f;
void push(int nodele, int noderi, int node) {
	tree[node][0] += tree[node][1];
	if (nodele != noderi) {
		tree[node * 2][1] += tree[node][1];
		tree[node * 2 + 1][1] += tree[node][1];
	}
	tree[node][1] = 0;
}
void update(int le, int ri, ll val, int nodele, int noderi, int node) {
	if (tree[node][1])push(nodele, noderi, node);
	if (le > noderi || ri < nodele)return;
	if (le <= nodele && noderi <= ri) {
		tree[node][1] = val;
		push(nodele, noderi, node);
		return;
	}
	int mid = (nodele + noderi) / 2;
	update(le, ri, val, nodele, mid, node * 2);
	update(le, ri, val, mid + 1, noderi, node * 2 + 1);
	tree[node][0] = min(tree[node * 2][0], tree[node * 2 + 1][0]);
}
ll query(int le, int ri, int nodele, int noderi, int node) {
	if (tree[node][1])push(nodele, noderi, node);
	if (le > noderi || ri < nodele)return inf;
	if (le <= nodele && noderi <= ri)return tree[node][0];
	int mid = (nodele + noderi) / 2;
	return min(query(le, ri, nodele, mid, node * 2), query(le, ri, mid + 1, noderi, node * 2 + 1));
}
int n, m, b, p;
vector<tuple<int, int, int> > vec[1000005];
bool possi(int k) {
	memset(tree, 0, sizeof(tree));
	for (int i = 1; i <= n; i++) {
		for (auto v : vec[i]) {
			int y1, y2, c;
			tie(y1, y2, c) = v;
			if (c > 0) update(max(1, y1 - k + 1), min(m - k + 1, y2), c, 1, m - k + 1, 1);
		}
		if (i >= k) {
			for (auto v : vec[i - k]) {
				int y1, y2, c;
				tie(y1, y2, c) = v;
				if (c < 0) update(max(1, y1 - k + 1), min(m - k + 1, y2), c, 1, m - k + 1, 1);
			}
		}
		if (i >= k && query(1, m - k + 1, 1, m - k + 1, 1) <= b) return true;
	}
	return false;
}
int main() {
	scanf("%d%d%d%d", &n, &m, &b, &p);
	for (int i = 0; i < p; i++) {
		int x1, y1, x2, y2, c;
		scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);
		vec[x1].emplace_back(y1, y2, c);
		vec[x2].emplace_back(y1, y2, -c);
	}
	int le, ri, ans, mid;
	le = 1;
	ri = m;
	ans = 0;
	while (le <= ri) {
		mid = (le + ri) / 2;
		if (possi(mid)) {
			ans = mid;
			le = mid + 1;
		}
		else ri = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &n, &m, &b, &p);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 56696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 56808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 56864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 56864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 56928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 56976 KB Output is correct
2 Correct 389 ms 56976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 56976 KB Output is correct
2 Correct 288 ms 56976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 57044 KB Output is correct
2 Correct 186 ms 57116 KB Output is correct
3 Correct 166 ms 57116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 57708 KB Output is correct
2 Correct 557 ms 57812 KB Output is correct
3 Correct 470 ms 57812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 58172 KB Output is correct
2 Correct 120 ms 58212 KB Output is correct
3 Correct 662 ms 58212 KB Output is correct
4 Correct 807 ms 58212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 825 ms 58212 KB Output is correct
2 Correct 1365 ms 58220 KB Output is correct
3 Correct 426 ms 58492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 649 ms 58620 KB Output is correct
2 Correct 1911 ms 58748 KB Output is correct
3 Correct 1706 ms 58748 KB Output is correct
4 Correct 1831 ms 58748 KB Output is correct
5 Correct 1880 ms 58748 KB Output is correct
6 Correct 368 ms 58876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5035 ms 67480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5020 ms 71508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5045 ms 71508 KB Time limit exceeded
2 Halted 0 ms 0 KB -