QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657709#7010. Rikka with A Long Colour PaletteFork512HzTL 1284ms17048kbC++201.9kb2024-10-19 15:17:522024-10-19 15:17:59

Judging History

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

  • [2024-10-19 15:17:59]
  • 评测
  • 测评结果:TL
  • 用时:1284ms
  • 内存:17048kb
  • [2024-10-19 15:17:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

//#define DEBUG
#ifdef DEBUG
const ll N = 1000;
#endif
#ifndef DEBUG
const ll N = 200100;
#endif
struct point{
	ll pos;
	bool side;
	ll id;
};
bool cmp(point x, point y)
{
	if(x.pos != y.pos) return x.pos < y.pos;
	if(x.side != y.side) return x.side < y.side;
	return x.id < y.id;
}
vector<point> a;
pii seg[N];
ll ans[N];
set<ll> mex;
struct item{
	ll x;
		
};
bool operator<(item x, item y)
{
	if(seg[x.x].second != seg[y.x].second)return seg[x.x].second < seg[y.x].second;
	return x.x < y.x;
}
set<item> buffer;

int main()
{
	#ifdef DEBUG
	freopen("1.txt", "r", stdin);
	#endif
	#ifndef DEBUG
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	#endif
	ll z;
	cin >> z;
	while(z--)
	{
		ll n, k;
		cin >> n >> k;
		mex.clear();
		a.clear();
		for(ll i=1; i<=k; i++)
			mex.insert(i);
		for(ll i=1; i<=n; i++)
		{
			ll l, r;
			cin >> l >> r;
			r--;
			seg[i+1] = {l, r};
			a.push_back({l, 0, i});
			a.push_back({r, 1, i});
		}
		sort(a.begin(), a.end(), cmp);
		memset(ans, 0, sizeof(ll) * (n+5));
		ll coverage = 0, prev = 0;
		for(point &cur: a)
		{
			if(cur.side == 0)
			{
				if(mex.empty())
					buffer.insert({cur.id});
				else
				{
					ans[cur.id] = *(mex.begin());
					mex.erase(mex.begin());
					if(mex.empty())
						prev = cur.pos;
				}
			}
			else
			{
				if(ans[cur.id])
				{
					if(!buffer.empty())
					{
						auto it = buffer.begin();
						ans[it->x] = ans[cur.id];
						buffer.erase(buffer.begin());
					}
					else 
					{
						if(mex.empty()) coverage += cur.pos - prev + 1;
						mex.insert(ans[cur.id]);
					}
				}
				else
				{
					buffer.erase({cur.id});
					ans[cur.id] = 1;
				}
			}
		}
		cout << coverage << '\n';
		cout << ans[1];
		for(ll i=2; i<=n; i++) cout << ' ' << ans[i];
		cout << '\n'; 
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5724kb

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: 36ms
memory: 3812kb

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 1 1 1 1 1 1 1 1 2 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 2 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 2 1 1 1 1 1 1 1 2
99
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 1000 cases

Test #3:

score: 0
Accepted
time: 1284ms
memory: 17048kb

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
366 13 792 71 65 346 364 793 123 68 750 52 655 39 35 231 358 735 810 552 238 317 147 383 282 21 687 886 317 181 839 28 153 257 95 463 196 116 591 319 940 584 379 728 122 244 484 599 428 609 696 537 591 928 587 166 37 639 298 260 171 20 264 46 902 377 313 786 745 433 853 496 268 177 838 394 220 2 2...

result: