QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155414#7010. Rikka with A Long Colour PalettePetroTarnavskyi#WA 25ms3496kbC++171.5kb2023-09-01 16:44:142023-09-01 16:44:15

Judging History

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

  • [2023-09-01 16:44:15]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:3496kb
  • [2023-09-01 16:44:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

void solve()
{
	int n, k;
	cin >> n >> k;
	unordered_set<int> s;
	s.reserve(4 * k);
	FOR (i, 0, k) s.insert(i + 1);
	VI l(n), r(n);
	VI ans(n);
	vector<PII> v;
	set<PII> m;
	FOR (i, 0, n)
	{
		cin >> l[i] >> r[i];
		v.PB({l[i], (i + 1)});
		v.PB({r[i], -(i + 1)});
	}
	sort(ALL(v));
	int res = 0;
	int p = 0;
	FOR (i, 0, 2 * n)
	{
		if (SZ(s) == 0) res += v[i].F - p;
		p = v[i].F;
		if (v[i].S < 0)
		{
			int j = abs(v[i].S) - 1;
			if (m.count(MP(v[i].F, ans[j])))
				s.insert(ans[j]);
			m.erase(MP(v[i].F, ans[j]));
		}
		else
		{
			int c = -1;
			int j = v[i].S - 1;	
			if (SZ(s))
			{
				c = *s.begin();
				s.erase(s.begin());
				m.insert({r[j], c});
			}			
			else
			{
				auto it = m.begin();
				c = it->S;
				int x = max(it->F, r[j]); 			
				m.erase(m.begin());
				m.insert({x, c});
			}	
			ans[j] = c;
		}
	}
	cout << res << '\n';
	FOR (i, 0, n)
	{
		cout << ans[i] << ' ';
	}
	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3496kb

input:

1
3 2
1 5
2 4
3 6

output:

3
2 1 1 

result:

ok 1 cases

Test #2:

score: -100
Wrong Answer
time: 25ms
memory: 3496kb

input:

1000
100 2
22 75
26 45
72 81
29 47
2 97
25 75
82 84
17 56
2 32
28 37
39 57
11 18
6 79
40 68
16 68
40 63
49 93
10 91
55 68
31 80
18 57
28 34
55 76
21 80
22 45
11 67
67 74
4 91
34 35
65 80
21 95
1 52
25 31
2 53
22 96
89 99
7 66
2 32
33 68
75 92
10 84
28 94
12 54
9 80
21 43
51 92
20 97
7 25
17 67
38 10...

output:

99
1 1 1 1 2 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 
99
2 1 1 2 1 1 2 1 1 1 1 2 1 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 1 1 1 1 2 1 2 1 1 1 1 1...

result:

wrong output format Expected EOLN