QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621406#4419. Package DeliveryppppppAC ✓199ms5304kbC++171.4kb2024-10-08 14:17:442024-10-08 14:17:49

Judging History

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

  • [2024-10-08 14:17:49]
  • 评测
  • 测评结果:AC
  • 用时:199ms
  • 内存:5304kb
  • [2024-10-08 14:17:44]
  • 提交

answer

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<math.h>
#include<set>
#include<bitset>
#include<deque>
#include<unordered_map>
#include<algorithm>
#define int long long
using namespace std;
const int N = 1e6 + 10, M = 1e8 + 10;
const int mod = 998244353;
int n,k;
struct cs
{
	int x,y;
}c[N];
bool cmp(cs d1,cs d2)
{
	if(d1.x==d2.x)return d1.y<d2.y;
	return d1.x<d2.x;
}
void df() {
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>c[i].x>>c[i].y;
	if(k==1)
	{
		cout<<n<<endl;
		return;
	}
	sort(c+1,c+1+n,cmp);
	priority_queue<int,vector<int>,greater<int>>q;
	q.push(c[1].y);
	int ans=0,nu=0;
	for(int i=2;i<=n;i++)
	{
		nu=0;
		int kl=0;
		while(q.empty()!=1)
		{
			int tt=q.top();
			if(c[i].x<=tt)//能相交的
			{
				int jk=q.size();
				int mn=min(nu,jk);
				if(nu!=0)
				{
					ans++;
					kl=0;
				}
				while(mn--)q.pop();
				break;
			}
			q.pop();
			kl++;
			if(kl==k)
			{
				ans++;
				nu=0,kl=0;
			}
			else
				nu=k-kl;
		}
		if(kl!=0)ans++;
		q.push(c[i].y);
//		cout<<i<<"[[[";
//		cout<<nu<<" "<<kl<<" ";
//		cout<<ans<<endl;
	}
	if(q.empty()!=1)
	{
		int tt=q.size();
		ans+=tt/k;
		if(tt%k)ans++;
	}
	cout<<ans<<endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie();
	cout.tie();
	int t = 1;
	cin >> t;
	while (t--) {
		df();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 199ms
memory: 5304kb

input:

2024
100 1
442460151 948559787
257924752 333997853
135225571 423096735
145956270 581316137
150642648 957750064
96771425 543507149
148750856 983838996
440403577 961685342
156399906 910285983
243714738 956235493
326220800 458442515
529302759 988863811
27258022 939870551
104136802 968000285
915165476 9...

output:

100
50
34
25
20
17
15
13
12
11
10
9
10
8
7
7
7
7
6
9
6
7
8
5
7
6
7
5
8
10
9
7
6
8
6
6
8
8
6
11
7
10
7
9
7
9
8
8
9
6
8
6
7
9
8
7
7
10
8
11
6
11
8
8
7
9
8
8
9
7
9
10
7
9
9
8
6
8
8
10
9
7
8
7
9
7
11
7
10
6
9
8
7
8
7
9
8
5
9
9
100
50
34
28
27
24
24
22
26
21
29
27
24
26
25
25
23
22
22
29
24
24
23
26
24
2...

result:

ok 2024 lines