QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#155517#7010. Rikka with A Long Colour PalettePetroTarnavskyi#TL 1224ms17924kbC++171.8kb2023-09-01 18:26:142023-09-01 18:26:14

Judging History

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

  • [2023-09-01 18:26:14]
  • 评测
  • 测评结果:TL
  • 用时:1224ms
  • 内存:17924kb
  • [2023-09-01 18:26: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 check(VI c, int res, VI l, VI r, int n, int k)
{
	FOR (i, 0, n) c[i]++;
	vector<PII> v;
	FOR (i, 0, n)
	{
		v.PB({l[i], c[i]});
		v.PB({r[i], -c[i]});
	}
	sort(ALL(v));
	map<int, int> m;
	int ans = 0;
	int p = 0;
	FOR (i, 0, 2 * n)
	{
		if (SZ(m) == k) ans += v[i].F - p;
		p = v[i].F;
		if (v[i].S > 0)
			m[v[i].S]++;
		else
		{
			m[-v[i].S]--;
			if (m[-v[i].S] == 0)
				m.erase(-v[i].S);
		}
	}
	assert(ans == res);
}

void solve()
{
	int n, k;
	cin >> n >> k;
	
	set<PII> m;
	FOR (i, 0, k) m.insert({-1, i + 1});
	VI l(n), r(n);
	VI ans(n);
	vector<PII> v;
	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 (m.begin()->F >= v[i].F)
		{ 
			res += v[i].F - p;
		}
		p = v[i].F;
		if (v[i].S > 0)
		{
			int j = v[i].S - 1;	
			auto it = m.begin();
			ans[j] = it->S;
			int x = max(it->F, r[j]); 			
			m.erase(m.begin());
			m.insert({x, ans[j]});
		}
	}
	check(ans, res, l, r, n, k);
	cout << res << '\n';
	assert(res >= 0);
	FOR (i, 0, n)
	{
		assert(ans[i] != -1);
		if (i) cout << ' ';
		cout << ans[i];
	}
	cout << '\n';
}

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

详细

Test #1:

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

input:

1
3 2
1 5
2 4
3 6

output:

3
1 2 2

result:

ok 1 cases

Test #2:

score: 0
Accepted
time: 33ms
memory: 3468kb

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
2 2 1 2 1 2 1 1 2 2 1 2 2 1 1 1 1 2 1 2 1 2 1 2 2 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 2 2 2 2 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 2
99
1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 2 2 1 1 1 1 1 2 1 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 1 2 1 2 1 2 2 2 ...

result:

ok 1000 cases

Test #3:

score: 0
Accepted
time: 1224ms
memory: 17924kb

input:

910
2000 1
291106515 907601188
257183002 580226984
677669535 703754379
578360426 581095542
555843963 776993944
590501585 787712383
268406144 715107805
67868779 956936247
805517214 820489184
673778237 728344625
320030940 533725999
412875077 899787237
376585734 712537132
203142903 420447884
58970816 3...

output:

999533742
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 910 cases

Test #4:

score: -100
Time Limit Exceeded

input:

1000
2000 200000
114320346 414198300
865005596 959003090
308399397 989829253
20993741 74598817
703749014 929597776
326260003 367629651
500954265 989504336
465349215 518791173
33679837 905990625
847419333 879685651
285496458 697635762
845139062 964850697
235259972 953405425
872309480 898530420
302629...

output:

0
404 1967 977 74 1820 1030 1479 1382 128 1960 911 1957 770 1972 958 695 1743 868 1004 624 257 349 154 1219 307 22 810 1156 431 192 1534 29 160 1207 100 682 1896 744 1613 909 1330 672 1268 859 1908 263 542 943 475 1503 820 608 680 1261 676 1270 38 751 1719 1803 183 1836 286 47 1210 1779 1818 969 125...

result: