编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#4918 #1028. 愤怒的小鸟 Wrong Answer 20 790 ms 12996 K C++ 17 / 2.6 K TosakaUCW 2024-02-20 22:22:31
显示原始代码
#include <bits/stdc++.h>
// #define int long long
#define fi first

#define se second

#define pb push_back

#define ls (p << 1)

#define rs (p << 1 | 1)

#define mid (l + r >> 1)

using std::cin, std::cout, std::string;
int read(int x = 0, int f = 0, char ch = getchar()) {
    while (ch < 48 or 57 < ch) f = ch == 45, ch = getchar();
    while (48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar();
    return f ? -x : x;
}
const int N = 5e5 + 5;
const int INF = 1 << 30;
// const long long INF = 1LL << 60;
int n, k, m, ans, buf[N], ind[N];
int l[N], r[N];
int max[N << 2], tag[N << 2];
std::vector<std::pair<int, int>> seg;
int query(int p, int l, int r, int x, int y) {
    if (x <= l and r <= y)
        return max[p];
    int res = 0;
    if (tag[p])
        max[ls] += tag[p], max[rs] += tag[p], tag[ls] += tag[p], tag[rs] += tag[p], tag[p] = 0;
    max[p] = std::max(max[ls], max[rs]);
    if (y <= mid)
        return query(ls, l, mid, x, y);
    if (x > mid)
        return query(rs, mid + 1, r, x, y);
    return std::max(query(ls, l, mid, x, y), query(rs, mid + 1, r, x, y));
}
void modify_assign(int p, int l, int r, int x, int k) {
    if (l == r) {
        max[p] = k;
        return;
    }
    if (tag[p])
        max[ls] += tag[p], max[rs] += tag[p], tag[ls] += tag[p], tag[rs] += tag[p], tag[p] = 0;
    if (x <= mid)
        modify_assign(ls, l, mid, x, k);
    else
        modify_assign(rs, mid + 1, r, x, k);
    max[p] = std::max(max[ls], max[rs]);
}
void modify_add(int p, int l, int r, int x, int y, int k) {
    if (x <= l and r <= y) {
        max[p] += k, tag[p] += k;
        return;
    }
    if (tag[p])
        max[ls] += tag[p], max[rs] += tag[p], tag[ls] += tag[p], tag[rs] += tag[p], tag[p] = 0;
    if (x <= mid)
        modify_add(ls, l, mid, x, y, k);
    if (mid < y)
        modify_add(rs, mid + 1, r, x, y, k);
    max[p] = std::max(max[ls], max[rs]);
}
void solve() {
    n = read(), k = read();
    for (int i = 1; i <= n; i++) {
        int l = std::max(0, read()) + 1, r = read() + 1;
        if (r < 1)
            continue;
        seg.pb({ l, r }), ind[l]++, buf[l]++, buf[r + 1]--, m = std::max(m, r + 1);
    }
    std::sort(seg.begin(), seg.end());
    for (int i = 1, now = 0, p = 0, res; i <= m; i++) {
        buf[i] += buf[i - 1];
        res = buf[i] + query(1, 0, m, std::max(0, i - 2 * k), std::max(0, i - k));
        ans = std::max(ans, res), now += ind[i];
        for (modify_assign(1, 0, m, i, res - now); p < seg.size() and seg[p].se == i; p++)
            --now, modify_add(1, 0, m, seg[p].fi, seg[p].se, 1);
    }
    cout << ans;
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("C.in", "r", stdin);
#endif
    for (int T = 1; T--; solve())
        ;
    return 0;
}
子任务 #1
Wrong Answer
得分:20
测试点 #1
Accepted
得分:100
用时:5 ms
内存:404 KiB

输入文件(bird1.in

10 4
-8 -1
-7 6
-10 -9
-10 -10
-7 -5
-2 0
1 1
-5 4
-6 8
3 3

答案文件(bird1.out

4

用户输出

4

系统信息

Exited with return code 0
测试点 #2
Wrong Answer
得分:0
用时:7 ms
内存:372 KiB

输入文件(bird2.in

15 3
-30 -22
-37 -9
-27 -21
31 48
-42 -35
-41 23
-47 18
31 44
4 6
-15 39
-32 32
-30 45
-44 -39
-45 -
<10 bytes omitted>

答案文件(bird2.out

8

用户输出

6

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:5 ms
内存:412 KiB

输入文件(bird3.in

20 18
-71 -47
-97 -67
2 78
-33 33
-57 59
-54 80
-82 60
-38 -1
-8 95
-10 69
-65 25
-13 -10
-29 0
-83 
<46 bytes omitted>

答案文件(bird3.out

14

用户输出

14

系统信息

Exited with return code 0
测试点 #4
Wrong Answer
得分:0
用时:5 ms
内存:352 KiB

输入文件(bird4.in

800 7
277 436
-685 191
-345 -320
-9 36
-265 759
-121 672
-206 -145
-725 -377
-701 527
-631 -290
-414
<7191 bytes omitted>

答案文件(bird4.out

396

用户输出

299

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #5
Wrong Answer
得分:0
用时:6 ms
内存:320 KiB

输入文件(bird5.in

1000 2
160 397
-649 -255
101 436
-703 562
-981 173
-671 -473
790 825
-677 721
-626 837
-914 -758
-33
<9035 bytes omitted>

答案文件(bird5.out

500

用户输出

343

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #6
Wrong Answer
得分:0
用时:11 ms
内存:608 KiB

输入文件(bird6.in

5000 19
-4844 -1293
-4329 -1473
-4921 3983
-5000 -2962
-2462 -849
-3308 -1040
480 3295
-3438 -738
15
<54717 bytes omitted>

答案文件(bird6.out

2507

用户输出

1820

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #7
Wrong Answer
得分:0
用时:320 ms
内存:12996 KiB

输入文件(bird7.in

100000 5
-111653 146070
-248065 -241611
-494919 -320505
-208949 -127576
-208235 -155124
-156018 2625
<1497026 bytes omitted>

答案文件(bird7.out

49853

用户输出

34672

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #8
Wrong Answer
得分:0
用时:346 ms
内存:12936 KiB

输入文件(bird8.in

100000 6
275526 431817
-464616 -317042
-497451 385826
-248348 384090
-62913 87091
233199 425778
-339
<1497050 bytes omitted>

答案文件(bird8.out

49954

用户输出

34726

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #9
Wrong Answer
得分:0
用时:42 ms
内存:992 KiB

输入文件(bird9.in

100000 6
-1462 -1046
-1876 129
1206 1241
-1616 -1191
-1356 -995
-1950 -1848
-1152 -927
-1472 -546
-1
<1037988 bytes omitted>

答案文件(bird9.out

50013

用户输出

36762

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #10
Wrong Answer
得分:0
用时:43 ms
内存:1080 KiB

输入文件(bird10.in

100000 31
936 1968
-19 902
-1933 -1874
-1815 -1038
-655 823
-1266 -1241
-1941 -667
-1715 -1636
-1567
<1037865 bytes omitted>

答案文件(bird10.out

49968

用户输出

38436

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0