QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#33313#4236. Triangular Logsflower_and_qingyu#RE 4ms50496kbC++232.8kb2022-05-31 11:37:282022-05-31 11:37:28

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-31 11:37:28]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:50496kb
  • [2022-05-31 11:37:28]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 1e6 + 50;

inline int lc(int o) { return o << 1; }
inline int rc(int o) { return o << 1 | 1; }

struct rect_t {
	int x1, y1, x2, y2, id;
	rect_t (int x1, int y1, int x2, int y2, int id) : x1(x1), y1(y1), x2(x2), y2(y2), id(id) {

	}
	inline bool operator<(const rect_t &rhs) const { 
		return x2 < rhs.x2;
	}
};

struct pt {
	int x, y, h;
	pt (int x, int y, int h) : x(x), y(y), h(h) {
	}
	inline bool operator<(const pt &rhs) const {
		return x < rhs.x;
	}
};

std::vector<pt> vec[N << 1];

void modify(int o, int l, int r, int p, pt val) {
	vec[o].push_back(val);
	if (l == r) {
		return;
	}
	const int mid = l + r >> 1;
	if (p <= mid) modify(lc(o), l, mid, p, val);
	else modify(rc(o), mid + 1, r, p, val);
}

void take(int o, int l, int r, int ql, int qr, int lim, auto &ret) {
	if (ret.size() >= 50)
		return;
	if (ql <= l && r <= qr) {
		for (int i = (int)(vec[o].size()) - 1; i >= 0; --i) {
			auto &pt = vec[o][i];
			ret.push_back(pt);
			if (pt.x < lim)
				continue;
			if (ret.size() >= 50)
				return;
		}
	}
	else {
		const int mid = l + r >> 1;
		if (ql <= mid) take(lc(o), l, mid, ql, qr, lim, ret);
		if (qr > mid) take(rc(o), mid + 1, r, ql, qr, lim, ret);
	}
}

int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<pt> points;
	std::vector<rect_t> rects;
	std::vector<int> buc;
	for (int i = 0; i < n; ++i) {
		int x, y, h;
		std::cin >> x >> y >> h;
		buc.push_back(y);
		points.emplace_back(x, y, h);
	}
	std::sort(points.begin(), points.end());
	std::vector<int> ans(q);
	for (int i = 0; i < q; ++i) {
		int x1, y1, x2, y2;
		buc.push_back(y1);
		buc.push_back(y2);
		std::cin >> x1 >> y1 >> x2 >> y2;
		rects.emplace_back(x1, y1, x2, y2, i);
	}
	std::sort(buc.begin(), buc.end());
	buc.erase(std::unique(buc.begin(), buc.end()), buc.end());
	auto find = [&](int x) {
		return std::lower_bound(buc.begin(), buc.end(), x) - buc.begin() + 1;
	};
	for (auto &[x, y, h] : points) y = find(y);
	for (auto &[x1, y1, x2, y2, id] : rects) y1 = find(y1), y2 = find(y2);
	std::sort(rects.begin(), rects.end());
	int p = 0, m = buc.size();
	for (auto [x1, y1, x2, y2, id] : rects) {
		while (p < points.size() && points[p].x <= x2) {
			modify(1, 1, m, points[p].y, points[p]);
			++p;
		}
		std::vector<pt> ret;
		take(1, 1, m, y1, y2, x1, ret);
		std::sort(ret.begin(), ret.end(), [&](const pt &a, const pt &b) {
			return a.h < b.h;		
		});
		for (auto pt : ret) {
			assert(x1 <= pt.x && pt.x <= x2);
			assert(y1 <= pt.y && pt.y <= y2);
		}
		bool OK = false;
		for (int i = 0; i + 2 < ret.size(); ++i) {
			if (ret[i].h + ret[i + 1].h > ret[i + 2].h) {
				OK = true;
			}
		}
		ans[id] = OK;
	}
	for (int i = 0; i < q; ++i) {
		std::cout << ans[i] << '\n';
	}
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 50496kb

input:

9 5
1 3 3
2 3 1
3 3 4
1 2 1
2 2 5
3 2 9
1 1 2
2 1 6
3 1 5
1 1 1 2
1 1 2 2
1 1 1 3
1 2 3 2
1 1 3 3

output:

0
1
0
0
1

result:

ok 5 lines

Test #2:

score: -100
Dangerous Syscalls

input:

481 1
8 6788 8975
24 6552 2668
26 7948 4730
40 531 9805
110 1914 1916
164 7073 3371
165 6293 7756
170 9946 2003
179 9654 1700
215 6447 2229
221 3149 3030
242 1999 6843
242 5764 3163
249 3716 8634
250 6801 9317
260 2741 4273
282 5436 4836
284 3951 6483
288 4812 76
375 9004 5492
380 5627 5929
391 6385...

output:


result: