QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95601#4393. Snatch GroceriesLiberty12619#AC ✓48ms5160kbC++20672b2023-04-10 20:04:462023-04-10 20:04:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-10 20:04:47]
  • 评测
  • 测评结果:AC
  • 用时:48ms
  • 内存:5160kb
  • [2023-04-10 20:04:46]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
#define int long long
#define x first
#define y second
using namespace std;
const int N = 1e5,INF = 1e12;
typedef pair<int,int> PII;
void solve()
{
	int n;
	cin>>n;
	vector<PII>regs(n+5);
	for(int i=1;i<=n;i++)	scanf("%lld%lld",&regs[i].x,&regs[i].y);
	sort(regs.begin()+1,regs.begin()+n+1);
	if(n==1)
	{
		cout<<1<<endl;
		return;
	}
	int r = -1,ans=n;
	for(int i=1;i<=n;i++)
	{
		if(regs[i].x<=r)
		{
			ans=i-2;
			break;
		}	
		r=max(r,regs[i].y);
	}
	
	cout<<ans<<endl;
}
signed main()
{
	int T = 1;
	cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 48ms
memory: 5160kb

input:

5
3
1 2
3 4
5 6
3
1 2
3 4
4 5
100000
263324740 263324748
920719069 920719077
82595123 82595132
765796214 765796222
621714954 621714959
77799324 77799332
278166427 278166428
375391536 375391545
856576804 856576812
512542774 512542781
829984452 829984457
302442403 302442404
779239984 779239986
1189173...

output:

3
1
275
5575
10000

result:

ok 5 lines