QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282178#1173. Knowledge Is...K8HeRE 0ms0kbC++142.0kb2023-12-11 15:59:312023-12-11 15:59:31

Judging History

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

  • [2023-12-11 15:59:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-11 15:59:31]
  • 提交

answer

#include <bits/stdc++.h>
#define _for(i, a, b) for (int i = a; i <= b; ++i)
#define for_(i, a, b) for (int i = a; i >= b; --i)
#define far(i, vec) for (auto i : vec)
#define bdmd int mid = (l + r) >> 1
typedef long double ldb;
typedef long long ll;
typedef double db;
typedef std::pair <int, int> pii;
typedef std::pair <ll, ll> pll;
namespace IO {
	int rnt () {
		int x = 0, w = 1; char c = getchar ();
		while (!isdigit (c)) { if (c == '-') w = -1; c = getchar (); }
		while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
		return x * w;
	}
} // namespace IO
const int N = 5e5 + 10, P = 998244353;
namespace SOLVE {
	using namespace IO;
	int n, ans[N];
	class R {
	public:
		int l, r, id;
		R () = default;
		R (int _l, int _r, int _id) : l (_l), r (_r), id (_id) {}
	} rg[N];
	void In () {
		n = rnt ();
		_for (i, 1, n) {
			int l = rnt (), r = rnt ();
			rg[i] = R (l, r, i);
		}
		return;
	}
	void Solve () {
		std::sort (rg + 1, rg + n + 1, [&] (R a, R b) {
			return a.l == b.l ? a.r < b.r : a.l < b.l; });
		std::priority_queue <pii, std::vector <pii>, std::greater <pii> > q[2];
		int tot = 0;
		_for (i, 1, n) {
			if (!q[0].empty () && q[0].top ().first < rg[i].l) {
				ans[q[0].top ().second] = ans[rg[i].id] = ++tot;
				q[1].push (pii (rg[i].r, rg[i].id)), q[0].pop ();
			}
			else if (!q[1].empty ()) {
				ans[i] = ans[q[1].top ().second];
				q[0].push (q[1].top ()), q[1].pop ();
				q[1].push (pii (rg[i].r, rg[i].id));
			}
			else q[0].push (pii (rg[i].r, rg[i].id));
		}
		while (!q[0].empty ()) ans[q[0].top ().second] = ++tot, q[0].pop ();
		return;
	}
	void Out () {
		_for (i, 1, n) printf ("%d ", ans[i]);
		puts ("");
		return;
	}
}
int main () {
#ifndef ONLINE_JUDGE
	freopen ("interval1.in", "r", stdin);
	// freopen ("interval.out", "w", stdout);
#else
	freopen ("interval.in", "r", stdin);
	freopen ("interval.out", "w", stdout);
#endif
	SOLVE::In ();
	SOLVE::Solve ();
	SOLVE::Out ();
	return 0;
} /*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

7 5
9 10
7 9
3 4
9 10
2 6
8 9
5 8

output:


result: