QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#183351#6733. Moniphant Sleepucup-team004#WA 361ms19384kbC++202.1kb2023-09-19 14:00:432023-09-19 14:00:43

Judging History

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

  • [2023-09-19 14:00:43]
  • 评测
  • 测评结果:WA
  • 用时:361ms
  • 内存:19384kb
  • [2023-09-19 14:00:43]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int inf = 1E9;

struct Tag {
    int sum = 0;
    int min = 0;
    int save = inf;
    int load = -inf;
};

Tag operator*(const Tag &a, const Tag &b) {
    Tag c;
    if (a.sum + b.load >= a.save) {
        c.sum = a.save + b.sum - b.load;
        c.min = std::min(a.min, a.save + b.min - b.load);
        c.save = a.save + b.save - b.load;
        c.load = a.min;
    } else {
        c.sum = a.sum + b.sum;
        c.min = std::min(a.min, a.sum + b.min);
        if (a.sum + b.min < a.save) {
            c.save = a.sum + b.save;
        } else {
            c.save = a.save;
        }
        c.load = std::max(a.load, std::min(a.min, a.sum + b.load));
    }
    return c;
}

constexpr int N = 1 << 20;

Tag op[5];
std::vector<Tag> tag(N);

void apply(int p, const Tag &m) {
    tag[p] = tag[p] * m;
}

void push(int p) {
    apply(2 * p, tag[p]);
    apply(2 * p + 1, tag[p]);
    tag[p] = {};
}

void modify(int p, int l, int r, int x, int y, int v) {
    if (l >= y || r <= x) {
        return;
    }
    if (l >= x && r <= y) {
        apply(p, op[v]);
        return;
    }
    int m = (l + r) / 2;
    push(p);
    modify(2 * p, l, m, x, y, v);
    modify(2 * p + 1, m, r, x, y, v);
}

int query(int p, int l, int r, int x) {
    if (r - l == 1) {
        return 500000 + tag[p].sum;
    }
    int m = (l + r) / 2;
    push(p);
    if (x < m) {
        return query(2 * p, l, m, x);
    } else {
        return query(2 * p + 1, m, r, x);
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, q;
    std::cin >> n >> q;
    
    op[1] = {1, 0, inf, -inf};
    op[2] = {-1, -1, inf, -inf};
    op[3] = {0, 0, 0, -inf};
    op[4] = {0, 0, inf, 0};
    
    for (int _ = 0; _ < q; _++) {
        int o, l, r;
        std::cin >> o >> l >> r;
        l--;
        
        if (o <= 4) {
            modify(1, 0, n, l, r, o);
        } else {
            std::cout << query(1, 0, n, l) << "\n";
        }
    }
    
    return 0;
}

詳細信息

Test #1:

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

input:

1 9
1 1 1
1 1 1
1 1 1
3 1 1
2 1 1
1 1 1
1 1 1
4 1 1
5 1 1

output:

500004

result:

ok 1 number(s): "500004"

Test #2:

score: 0
Accepted
time: 0ms
memory: 19384kb

input:

3 7
2 1 3
3 1 3
1 1 3
1 1 3
5 1 1
4 1 3
5 1 1

output:

500001
499999

result:

ok 2 number(s): "500001 499999"

Test #3:

score: -100
Wrong Answer
time: 361ms
memory: 19344kb

input:

500000 500000
2 132991 371170
5 15281 15281
1 278642 397098
2 152103 176573
2 13797 47775
3 139320 370045
3 79054 432340
3 82556 212775
4 270171 469418
5 148000 148000
3 371255 401414
5 71051 71051
2 358945 473071
2 231663 265401
2 20243 58131
1 247710 313373
5 154549 154549
1 17317 233265
5 37602 3...

output:

500000
499999
500000
499998
499999
500000
500001
500000
500000
499997
499997
500000
499999
500000
499998
500000
500002
500001
500000
499999
499997
499997
499997
500001
500000
500001
500003
499997
499998
500000
499997
500003
500001
500000
500001
500002
500002
499998
500001
499999
499998
499999
500008...

result:

wrong answer 7th numbers differ - expected: '500000', found: '500001'