QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226020#7582. Snowy Smileucup-team004#AC ✓2282ms3956kbC++202.1kb2023-10-25 14:42:062023-10-25 14:42:07

Judging History

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

  • [2023-10-25 14:42:07]
  • 评测
  • 测评结果:AC
  • 用时:2282ms
  • 内存:3956kb
  • [2023-10-25 14:42:06]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int N = 1 << 12;

struct Info {
    i64 sum = 0;
    i64 max = 0;
    i64 pre = 0;
    i64 suf = 0;
};

Info operator+(const Info &a, const Info &b) {
    Info c;
    c.sum = a.sum + b.sum;
    c.max = std::max({a.max, b.max, a.suf + b.pre});
    c.pre = std::max(a.pre, a.sum + b.pre);
    c.suf = std::max(a.suf + b.sum, b.suf);
    return c;
}

Info t[N];

void pull(int p) {
    t[p] = t[2 * p] + t[2 * p + 1];
}

void modify(int p, int l, int r, int x, i64 v) {
    if (r - l == 1) {
        i64 mv = std::max(0LL, v);
        t[p] = {v, mv, mv, mv};
        return;
    }
    int m = (l + r) / 2;

    if (x < m) {
        modify(2 * p, l, m, x, v);
    } else {
        modify(2 * p + 1, m, r, x, v);
    }

    pull(p);
}

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> x(n), y(n), w(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i] >> y[i] >> w[i];
    }

    auto vx = x, vy = y;
    std::sort(vx.begin(), vx.end());
    std::sort(vy.begin(), vy.end());
    vx.erase(std::unique(vx.begin(), vx.end()), vx.end());
    vy.erase(std::unique(vy.begin(), vy.end()), vy.end());
    int nx = vx.size(), ny = vy.size();

    std::vector<std::vector<std::pair<int, int>>> a(nx);
    for (int i = 0; i < n; i++) {
        x[i] = std::lower_bound(vx.begin(), vx.end(), x[i]) - vx.begin();
        y[i] = std::lower_bound(vy.begin(), vy.end(), y[i]) - vy.begin();
        a[x[i]].emplace_back(y[i], w[i]);
    }
    i64 ans = 0;
    for (int i = 0; i < nx; i++) {
        std::vector<i64> val(ny);
        for (int j = 0; j < ny; j++) {
            modify(1, 0, ny, j, 0);
        }
        for (int j = i; j < nx; j++) {
            for (auto [y, w] : a[j]) {
                val[y] += w;
                modify(1, 0, ny, y, val[y]);
            }
            ans = std::max(ans, t[1].max);
        }
    }
    std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

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

input:

2
4
1 1 50
2 1 50
1 2 50
2 2 -500
2
-1 1 5
-1 1 1

output:

100
6

result:

ok 2 number(s): "100 6"

Test #2:

score: 0
Accepted
time: 2282ms
memory: 3956kb

input:

52
10
30 -1 -40065867
-15 -74 -695603735
-14 3 -847010045
33 -92 -458180374
-88 -86 -488393753
50 -91 -949931576
39 -99 -168684248
-29 64 783067879
14 -5 -104144786
-67 90 492127865
10
-29 -70 151800541
54 41 -677722362
-85 -72 766300892
-47 -90 -74384884
-12 -56 679506148
0 -41 -30038154
-4 -6 -254...

output:

1275195744
2084179225
1734353870
1018976777
2591083202
1309403622
2358891488
2143566532
1602649268
2112317422
1470851645
2423431804
2209082718
1571719735
1313345276
2039708041
1526772930
1368470878
866267413
1826546180
1878414495
1706604892
1822460963
1942258759
2943744963
2090539403
666502909
14660...

result:

ok 52 numbers