QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578109 | #7582. Snowy Smile | skip2004 | WA | 301ms | 4000kb | C++20 | 1.5kb | 2024-09-20 16:39:45 | 2024-09-20 16:39:45 |
Judging History
answer
#include<bits/stdc++.h>
namespace rgs = std::ranges;
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
struct ob {
int x, y, w;
auto operator <=> (const ob &) const = default;
};
struct pr {
ll pre, suf, max, sum;
void inc(ll v) {
pre += v, suf += v, max += v, sum += v;
}
};
pr merge(pr x, pr y) {
return (pr) {
std::max(x.pre, x.sum + y.pre),
std::max(y.suf, x.suf + y.suf),
std::max({x.max, y.max, x.suf + y.pre}),
x.sum + y.sum
};
}
const int N = 2005;
int L;
pr a[N << 3];
void init(int n) {
L = 2 << std::__lg(n);
for(int i = 1;i <= L * 2;++i) a[i] = {};
}
void upt(int p, int v) {
a[p += L].inc(v);
for(;p >>= 1;)
a[p] = merge(a[p << 1], a[p << 1 | 1]);
}
void solve() {
int n; cin >> n;
std::vector<ob> a(n);
std::vector<int> vy;
for(auto & [x, y, w] : a) {
cin >> x >> y >> w;
vy.push_back(y);
}
sort(a.begin(), a.end());
rgs::sort(vy);
ll ans = 0;
for(int i = 0;i < n;++i) {
a[i].y = lower_bound(vy.begin(), vy.end(), a[i].y) - vy.begin() + 1;
}
for(int i = 0;i < n;++i) {
if(!i || a[i].x != a[i - 1].x) {
init(n);
for(int j = i, k = j;j < n;j = k) {
for(;k < n && a[k].x == a[j].x;++k) ;
for(int l = j;l < k;++l) {
upt(a[l].y, a[l].w);
}
ans = std::max(ans, ::a[1].max);
}
}
}
cout << ans << '\n';
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
int T; cin >> T;
for(int i = 0;i < T;++i) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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
Wrong Answer
time: 301ms
memory: 4000kb
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 2382521347 1018976777 2653040526 1309403622 2358891488 2446335573 2173157697 2112317422 1470851645 2423431804 2209082718 1816803460 1330200071 2624066382 1797988037 1962117758 996805867 1826546180 2157986113 1706604892 2564225254 1942258759 3249581197 2090539403 666502909 14660...
result:
wrong answer 3rd numbers differ - expected: '1734353870', found: '2382521347'