QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253351#6703. Tokens on the SegmentsTeal#WA 186ms7364kbC++141.8kb2023-11-16 21:54:052023-11-16 21:54:05

Judging History

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

  • [2023-11-16 21:54:05]
  • 评测
  • 测评结果:WA
  • 用时:186ms
  • 内存:7364kb
  • [2023-11-16 21:54:05]
  • 提交

answer

#include <set>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N (200010)
#define inf (0x3f3f3f3f)
#define INF (0x3f3f3f3f3f3f3f3fll)
#define LL long long
int T, n, ret[N];
struct Segment {
    int l, r;
    friend bool operator< (const Segment& a, const Segment& b) {
        return a.r > b.r;
    }
} Seg[N];

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9')
        ch == '-' ? f = -1, ch = getchar() : ch = getchar();
    while (ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x * f;
}

bool cmp(const Segment& a, const Segment& b) {
    return a.l < b.l;
}

int main() {
    T = read();
    while (T--) {
        n = read();

        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            Seg[i].l = read(), Seg[i].r = read();
            ret[++cnt] = Seg[i].l;
            ret[++cnt] = Seg[i].r;
        } 
        sort(ret + 1, ret + cnt + 1);
        cnt = unique(ret + 1, ret + cnt + 1) - ret;
        sort(Seg + 1, Seg + n + 1, cmp);
        for (int i = 1; i <= n; ++i) {
            Seg[i].l = lower_bound(ret + 1, ret + cnt + 1, Seg[i].l) - ret;
            Seg[i].r = lower_bound(ret + 1, ret + cnt + 1, Seg[i].r) - ret;
            // printf("    SEG %d %d %d\n", i, Seg[i].l, Seg[i].r);
        }

        int idx = 1, ans = 0;
        priority_queue<Segment> q;
        for (int i = 1; i <= cnt; ++i) {
            while (q.size() && q.top().r < i) q.pop();
            while (idx <= n && Seg[idx].l >= i) q.push(Seg[idx]), idx++;
            if (q.size()) ++ans, q.pop();
        }
        printf("%d\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 186ms
memory: 7364kb

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
17
11
14
12
8
17
16
3
4
5
9
16
14
15
15
13
8
17
16
15
11
17
11
14
4
13
13
3
5
14
9
3
17
8
8
15
7
19
4
11
17
19
6
13
14
12
19
10
6
6
11
7
13
12
18
3
16
16
13
14
7
6
6
11
13
13
3
5
3
4
10
6
3
7
17
14
13
4
9
8
14
17
10
11
10
8
4
16
20
8
17
10
18
17
13
11
6
15
16
16
10
6
8
8
9
16
8
14
14
15
13
17
15...

result:

wrong answer 3rd numbers differ - expected: '18', found: '17'