QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282179 | #1173. Knowledge Is... | K8He | WA | 1ms | 6044kb | C++14 | 1.8kb | 2023-12-11 15:59:41 | 2023-12-11 15:59:42 |
Judging History
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 () {
SOLVE::In ();
SOLVE::Solve ();
SOLVE::Out ();
return 0;
} /*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6044kb
input:
7 5 9 10 7 9 3 4 9 10 2 6 8 9 5 8
output:
3 3 2 4 2 1 0
result:
wrong answer Interval intersecting