QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709055#6703. Tokens on the SegmentsfutarianRE 0ms0kbC++14912b2024-11-04 11:05:162024-11-04 11:05:17

Judging History

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

  • [2024-11-04 11:05:17]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-04 11:05:16]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
const int Len = 1e5 + 5;
int n,m;
struct Seg
{
	int l,r;
	Seg(){l = r = 0;}
	Seg(int L,int R){l = L , r = R;}
}seg[Len];
inline bool cmp(Seg x,Seg y){return x.l < y.l;} 
signed main()
{
	int T;scanf("%d",&T);
	while(T --)
	{
		priority_queue<int,vector<int>,greater<int>> Q;
		scanf("%d",&n);
		for(int i = 1 ; i <= n ; i ++) scanf("%d %d",&seg[i].l,&seg[i].r);
		sort(seg + 1 , seg + 1 + n , cmp);
		int now = 0 , id = 1 , as = 0 , i = 1;
		while(1)
		{
			while(id <= n && seg[i].l <= now + 1)
			{
				Q.push(seg[i].r);
				i ++;
			}
			while(!Q.empty() && Q.top() <= now) Q.pop();
			if(!Q.empty())
			{
				now ++;
				Q.pop();
				as ++;
			}
			else
			{
				if(i <= n)
				{
					now = seg[i].l;
					as ++;
					i ++;
				}
			}
			if(i >= n + 1 && Q.empty()) break;
		}
		printf("%d\n",as);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
3
1 2
1 1
2 3
3
1 2
1 1
2 2

output:


result: