QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282241#1173. Knowledge Is...K8HeWA 1ms5864kbC++141.9kb2023-12-11 16:43:172023-12-11 16:43:18

Judging History

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

  • [2023-12-11 16:43:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5864kb
  • [2023-12-11 16:43:17]
  • 提交

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, m, 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 (), m = 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[rg[i].id] = ans[q[1].top ().second];
				ans[q[1].top ().second] = 0;
				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));
			if (tot == m) break;
		}
		_for (i, 1, n) {
			if (tot == m) break;
			if (!ans[i]) ans[i] = ++tot;
		}
		std::cerr << tot << std::endl;
		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: 100
Accepted
time: 1ms
memory: 5792kb

input:

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

output:

3 4 1 2 2 1 3 

result:

ok answer = 7

Test #2:

score: 0
Accepted
time: 1ms
memory: 5792kb

input:

2 2
1 2
3 4

output:

1 1 

result:

ok answer = 2

Test #3:

score: 0
Accepted
time: 0ms
memory: 4008kb

input:

2 1
1 2
2 3

output:

1 0 

result:

ok answer = 1

Test #4:

score: 0
Accepted
time: 0ms
memory: 4116kb

input:

1 1
4 26

output:

1 

result:

ok answer = 1

Test #5:

score: 0
Accepted
time: 0ms
memory: 5800kb

input:

500 258
1 3
3 5
2 4
3 5
4 5
4 5
1 4
1 2
3 5
2 5
2 5
4 5
4 5
4 5
2 3
1 4
1 4
1 4
4 5
4 5
2 3
4 5
3 5
3 5
1 5
1 4
2 5
1 5
3 5
3 4
4 5
2 3
3 5
3 5
4 5
2 3
1 5
1 5
2 3
2 3
3 4
3 5
3 4
1 3
1 2
1 5
4 5
2 3
2 4
1 3
4 5
4 5
4 5
1 3
3 5
4 5
3 5
1 5
1 2
1 2
3 5
3 5
4 5
3 4
3 5
2 3
2 5
2 4
2 5
3 5
2 3
1 5
4 5
...

output:

39 119 120 121 122 123 124 1 125 126 127 128 129 130 40 131 132 133 134 135 41 136 137 138 139 140 141 142 143 144 145 42 146 147 148 43 149 150 44 45 151 152 153 46 2 154 155 47 156 48 157 158 159 49 160 161 162 163 3 4 164 165 166 167 168 50 169 170 171 172 51 173 174 175 176 52 177 178 179 180 18...

result:

ok answer = 376

Test #6:

score: 0
Accepted
time: 1ms
memory: 5856kb

input:

500 242
8 9
9 10
2 9
8 10
9 10
6 10
4 8
4 5
2 6
7 10
3 8
1 8
1 6
5 9
7 8
8 10
8 9
8 10
2 9
2 3
6 8
3 10
5 9
1 3
6 8
4 10
9 10
8 9
8 10
1 9
3 9
3 7
2 3
6 10
3 6
6 10
3 4
3 6
9 10
5 7
8 10
6 10
5 6
5 7
7 8
1 3
4 7
9 10
4 9
2 4
8 9
1 3
8 10
3 4
9 10
4 9
5 10
8 9
1 3
1 5
8 10
3 4
8 9
3 9
3 6
3 10
6 7
7 ...

output:

230 174 231 150 170 12 167 45 70 74 168 169 71 232 170 128 233 154 234 5 171 4 235 6 172 6 208 236 116 237 238 115 7 11 72 68 21 73 214 116 159 17 74 117 173 8 118 204 239 22 240 9 143 23 223 241 41 117 10 46 166 24 127 242 75 0 119 174 0 180 76 113 0 72 120 187 175 176 121 0 177 178 177 179 192 91 ...

result:

ok answer = 471

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 5864kb

input:

500 250
50 84
36 68
94 98
13 88
4 62
45 74
80 89
56 87
65 89
44 52
69 78
29 76
61 90
91 99
16 98
69 92
50 77
86 95
73 79
83 90
78 89
1 79
81 86
14 37
91 94
27 48
11 73
94 97
49 80
15 60
26 39
34 76
69 77
22 72
6 78
92 96
46 83
83 94
62 95
77 80
32 72
46 90
41 88
47 91
68 75
14 36
26 43
14 87
49 74
2...

output:

61 152 97 221 118 178 193 95 131 78 249 180 109 135 1 144 243 212 164 201 107 191 197 35 225 61 172 125 64 109 41 181 244 169 188 158 48 202 115 178 170 41 40 56 234 33 50 218 228 38 60 75 125 151 93 79 235 113 73 188 39 166 132 5 241 46 216 135 221 16 168 55 234 236 34 159 10 232 190 92 148 29 199 ...

result:

wrong answer participant answer = 499, judge answer = 500