QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253274#6703. Tokens on the SegmentsTeal#WA 240ms13172kbC++142.8kb2023-11-16 20:36:582023-11-16 20:36:59

Judging History

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

  • [2023-11-16 20:36:59]
  • 评测
  • 测评结果:WA
  • 用时:240ms
  • 内存:13172kb
  • [2023-11-16 20:36:58]
  • 提交

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], ans, vis[N];
struct Segment {
    int l, r, id;
    friend bool operator< (const Segment& a, const Segment& b) {
        return a.r - a.l == b.r - b.l ? a.r > b.r : a.r - a.l > b.r - b.l ;
    }
} 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);
        printf("%d\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9952kb

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: 240ms
memory: 13172kb

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
6
11
9
9
7
5
9
9
3
4
5
5
11
7
9
8
10
6
11
8
10
7
9
9
9
3
7
8
3
3
6
6
3
8
6
6
10
7
10
4
5
11
9
5
10
8
7
12
7
5
6
5
4
8
7
9
3
8
9
9
7
6
5
6
7
7
7
3
5
3
4
6
5
2
6
10
7
7
4
5
7
7
9
4
8
7
7
4
8
12
7
11
7
9
10
9
6
5
8
10
10
5
5
8
7
5
9
6
7
7
6
8
10
9
3
8
5
7
5
11
9
9
9
7
11
6
9
7
8
5
9
5
6
11
6
5
4
7
7
...

result:

wrong answer 2nd numbers differ - expected: '7', found: '6'