QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226016 | #7582. Snowy Smile | ucup-team004# | TL | 0ms | 3588kb | C++20 | 2.1kb | 2023-10-25 14:39:12 | 2023-10-25 14:39:12 |
Judging History
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;
modify(2 * p, l, m, x, v);
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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: -100
Time Limit Exceeded
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...