QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#423182#8179. 2D ParenthesescomplexorWA 2ms13952kbC++232.9kb2024-05-27 21:26:472024-05-27 21:26:48

Judging History

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

  • [2024-05-27 21:26:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13952kb
  • [2024-05-27 21:26:47]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long LL;
typedef std::pair<int, int> pii;
#define MP std::make_pair
#define fi first
#define se second
int read()
{
	int s = 0, f = 1;
	char c = getchar();
	while (!(c >= '0' && c <= '9'))
		f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9')
		s = s * 10 + (c ^ 48), c = getchar();
	return f ? s : -s;
}
const int MAXN = 400005;
struct Tuple 
{ 
	int x, y, z; 
	Tuple(int _x = 0, int _y = 0, int _z = 0)
	: x(_x), y(_y), z(_z){}
	friend bool operator<(Tuple t1, Tuple t2)
	{ return t1.x != t2.x ? t1.x < t2.x : t1.y != t2.y ? t1.y < t2.y : t1.z < t2.z; }
} ;
struct Segment
{
	int x, yl, yr, v;
	Segment(){}
	Segment(int _x, int _yl, int _yr, int _v)
	: x(_x), yl(_yl), yr(_yr), v(_v) {}
} sg[MAXN << 1];
std::set<Tuple> rec;
int n, ans[MAXN], m = 0, yy[MAXN << 1], V;
int ida[MAXN], idb[MAXN];
pii a[MAXN], b[MAXN];
namespace BIT
{
	int c[MAXN << 1] = {0};
	void modify(int x, int v)
	{
		for (; x <= V; x += x & -x)
			c[x] += v;
	}
	int query(int x)
	{
		int res = 0;
		for (; x; x -= x & -x)
			res += c[x];
		return res;
	}
	int query(int l, int r) { return query(r) - query(l - 1); }
}
int getId(int y){ return std::lower_bound(yy + 1, yy + V + 1, y) - yy; }
int main() 
{
	n = read();
	for (int i = 1; i <= n; i++) a[i].fi = read(), a[i].se = read();
	for (int i = 1; i <= n; i++) b[i].fi = read(), b[i].se = read();
	std::iota(ida + 1, ida + n + 1, 1);
	std::iota(idb + 1, idb + n + 1, 1);
	if (n <= 2) return printf("NO"), 0;
	std::sort(ida + 1, ida + n + 1, [](int i, int j){ return a[i] > a[j]; });
	std::sort(idb + 1, idb + n + 1, [](int i, int j){ return b[i] > b[j]; });
	for (int i = 1, j = 1; i <= n; i++)
	{
		for (; j <= n && b[idb[j]].fi > a[ida[i]].fi; j++)
			rec.emplace(b[idb[j]].se, b[idb[j]].fi, idb[j]);
		auto it = rec.lower_bound(Tuple(a[ida[i]].se + 1, -1e9 - 1, 0));
		if (it == rec.end()) return printf("No\n"), 0;
		ans[ida[i]] = it->z;
		yy[++V] = a[ida[i]].se, yy[++V] = it->x - 1;
		sg[++m] = Segment(a[ida[i]].fi, a[ida[i]].se, it->x - 1, 1);
		sg[++m] = Segment(it->y, a[ida[i]].se, it->x - 1, -1);
		rec.erase(it);
	}
	V = std::unique(yy + 1, yy + n * 2 + 1) - yy - 1;
	std::sort(sg + 1, sg + m + 1, [](Segment a, Segment b){
		if (a.x == b.x && a.v == b.v)
			return a.v == -1 ? a.yr - a.yl < b.yr - b.yl : a.yr - a.yl > b.yr - b.yl;
		return a.x == b.x ? a.v < b.v : a.x < b.x;
	});
	for (int i = 1; i <= m; i++)
	{
		int l = getId(sg[i].yl), r = getId(sg[i].yr);
		// printf("%d: %d %d %d %d %d\n", i, sg[i].x, sg[i].yl, sg[i].yr, sg[i].v, BIT::query(l + 1, r - 1));
		if (sg[i].v == 1 && BIT::query(l, r) > 0)
			return printf("No"), 0;
		if (sg[i].v == -1 && BIT::query(l, r) > 0)
			return printf("No\n"), 0;
		BIT::modify(l, sg[i].v), BIT::modify(r, sg[i].v);
	}
	printf("Yes\n");
	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 13952kb

input:

3
0 0
2 -2
1 1
2 2
3 1
2 3

output:

No

result:

wrong answer expected YES, found NO