QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#478258#4393. Snatch Grocerieshorzward#AC ✓37ms4308kbC++171.0kb2024-07-14 19:43:022024-07-14 19:43:03

Judging History

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

  • [2024-07-14 19:43:03]
  • 评测
  • 测评结果:AC
  • 用时:37ms
  • 内存:4308kb
  • [2024-07-14 19:43:02]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0)

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i].second >> v[i].first;
    }
    if(n == 1) {
        cout << "1\n";
        return;
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(i == 0 && v[i].first < v[i + 1].second) {
            ans++;
            continue;
        }
        else if(i == 0) break;
        if(i == n - 1 && v[i].second > v[i - 1].first) {
            ans++;
            continue;
        }
        else if(i == n - 1) break;
        if(v[i].second > v[i - 1].first && v[i].first < v[i + 1].second) ans++;
        else break;

    }
    cout << ans << '\n';
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 37ms
memory: 4308kb

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