QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612071#6703. Tokens on the Segmentskevinyang#AC ✓89ms5180kbC++141.3kb2024-10-05 04:05:242024-10-05 04:05:25

Judging History

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

  • [2024-10-05 04:05:25]
  • 评测
  • 测评结果:AC
  • 用时:89ms
  • 内存:5180kb
  • [2024-10-05 04:05:24]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<pair<int,int>>a(n);
        for(int i = 0; i<n; i++){
            cin >> a[i].first >> a[i].second;
        }
        sort(a.begin(),a.end());
        int cur = 1;
        int r = 0;
        priority_queue<int,vector<int>,greater<int>>pq;
        int ans = 0;
        while(pq.size() || r < n){
            while(pq.size() && pq.top() < cur){
                pq.pop();
            }
            while(r<n && a[r].first == cur){
                pq.push(a[r].second);
                r++;
            }
            if(pq.size() == 0 && r < n){
                cur = a[r].first;
                while(r<n && a[r].first == cur){
                    pq.push(a[r].second);
                    r++;
                }
            }
            if(pq.size()){
                pq.pop();
                ans++;
            }
            cur++;
        }
        cout << ans << '\n';
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

input:

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

output:

3
2

result:

ok 2 number(s): "3 2"

Test #2:

score: 0
Accepted
time: 89ms
memory: 5180kb

input:

10000
6
5 19
7 12
10 10
4 14
1 12
5 11
7
3 5
1 10
12 15
2 13
8 11
5 20
11 14
18
6 17
6 9
6 20
2 7
1 11
16 19
2 5
1 14
5 8
14 19
4 7
11 19
11 13
2 9
3 12
12 13
19 19
13 16
11
11 13
1 2
14 17
15 16
12 17
15 17
6 7
8 11
12 19
3 8
10 19
18
6 9
16 18
13 15
14 15
9 13
2 8
12 18
8 16
16 18
3 18
1 12
4 13
1...

output:

6
7
18
11
18
12
8
18
16
3
4
5
9
18
14
19
18
13
8
17
16
19
11
17
11
14
4
13
13
3
5
15
9
3
17
8
8
15
7
20
4
11
18
19
6
13
14
12
20
10
6
6
11
7
13
12
19
3
16
17
14
14
7
6
6
11
13
13
3
5
3
4
10
6
3
7
19
14
13
4
9
8
15
19
10
11
10
8
4
18
20
8
19
10
18
19
13
11
6
16
16
18
10
6
8
8
9
16
8
14
14
15
13
17
18...

result:

ok 10000 numbers