QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#73194#4393. Snatch GroceriesLiCooerAC ✓133ms4976kbC++17975b2023-01-23 00:01:272023-01-23 00:01:28

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-23 00:01:28]
  • 评测
  • 测评结果:AC
  • 用时:133ms
  • 内存:4976kb
  • [2023-01-23 00:01:27]
  • 提交

answer

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


const int N = 101000;

struct node
{
    int l , r;
}a[N];
bool cmp(const node A , const node B)
{
    if(A.l != B.l)
    {
        return A.l < B.l;

    }
    return A.r > B.r;

}

signed main()
{
    int t;
    cin >> t;
    while(t -- )
    {
        int n;
        cin >> n;
        for(int i = 1 ; i <= n ; i ++ )
        {
            cin >> a[i].l >> a[i].r;
        }
        sort(a + 1 , a + 1 + n , cmp);
        int max1 = a[1].r;
        int ans = 0;
        for(int i = 2 ; i <= n ; i ++ )
        {
            if(a[i].l <= max1)
            {
                break;
            }
            else
            {
                max1 = max(a[i].r , max1);
                ans ++;

            }
        }
        if(ans == n - 1)
        {
            ans ++ ;
        }
        cout << ans << "\n";

        
    }
	return 0;
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 133ms
memory: 4976kb

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