QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253337#6703. Tokens on the SegmentsTeal#WA 144ms7624kbC++143.2kb2023-11-16 21:39:252023-11-16 21:39:26

Judging History

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

  • [2023-11-16 21:39:26]
  • 评测
  • 测评结果:WA
  • 用时:144ms
  • 内存:7624kb
  • [2023-11-16 21:39:25]
  • 提交

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], val[N * 4], lazy[N * 4], vis[N];
struct Segment {
    int l, r, id;
    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;
}

// void build(int x, int l, int r) {
//     lazy[x] = val[x] = 0;
//     if (l == r) return;
//     int mid = (l + r) >> 1;
//     build(x * 2, l, mid), build(x * 2 + 1, mid + 1, r);
// }

// void spread(int x) {
//     if (lazy[x]) {
//         int lson = x * 2, rson = x * 2 + 1;
//         lazy[lson] = val[lson] = lazy[x];
//         lazy[rson] = val[rson] = lazy[x];
//         lazy[x] = 0;
//     }
// }

// void Modify(int x, int l, int r, int a, int b, int d) {
//     if (a <= l && r <= b) {
//         val[x] = d;
//         lazy[x] = d;
//         return;
//     }
//     spread(x);
//     int mid = (l + r) >> 1;
//     if (b <= mid) Modify(x * 2, l, mid, a, b, d);
//     else if (a > mid) Modify(x * 2 + 1, mid + 1, r, a, b, d);
//     else Modify(x * 2, l, mid, a, mid, d), Modify(x * 2 + 1, mid + 1, r, mid + 1, b, d);
// }

// void Query(int x, int l, int r) {
//     if (lazy[x]) {
//         // printf("%d %d %d\n", l, r, lazy[x]);
//         if (!vis[lazy[x]]) ++ans, vis[lazy[x]] = true;
//         return;
//     }
//     if (l == r) return;
//     int mid = (l + r) >> 1;
//     Query(x * 2, l, mid), Query(x * 2 + 1, mid + 1, r);
// }

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

        vis[0] = true;
        for (int i = 1; i <= n; ++i) vis[i] = 0;

        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            Seg[i].l = read(), Seg[i].r = read();
            Seg[i].id = i;
            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);
        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);
        }
        // build(1, 1, cnt);
        // for (int i = 1; i <= n; ++i) Modify(1, 1, cnt, Seg[i].l, Seg[i].r, Seg[i].id);
        // ans = 0;
        // Query(1, 1, cnt);
        int idx = 1, ans = 0;
        for (int i = 1; i <= cnt; ++i) {
            
            // printf("%d %d %d %d\n", i, idx, Seg[idx].l, Seg[idx].r);
            while (idx <= n && Seg[idx].r < i) idx++;
            if (idx > n) break;
            if (Seg[idx].l <= i) idx++, ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7624kb

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: 144ms
memory: 7224kb

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:

5
7
15
9
12
11
8
13
12
3
4
5
9
13
14
14
12
12
8
14
12
11
10
14
11
10
4
12
11
3
5
12
9
3
14
8
7
15
7
14
4
9
17
17
6
9
12
11
17
10
6
6
10
7
12
11
14
3
12
11
12
13
7
6
6
11
12
11
3
5
3
4
10
6
3
7
13
13
10
4
9
7
11
14
10
10
10
8
4
11
17
8
14
10
14
13
12
10
6
11
12
13
10
5
8
8
9
12
8
11
11
14
12
14
11
3
...

result:

wrong answer 1st numbers differ - expected: '6', found: '5'