이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const ll INF = 1e18;
struct SegTree {
struct Node {
ll pref, suff;
ll best, sum;
};
vector <Node> aint;
int n;
inline void init(int _n) {
n = _n;
aint.resize(4 * n + 1, {-INF, -INF, -INF, -INF});
}
inline void refresh(int nod) {
aint[nod].sum = aint[2 * nod].sum + aint[2 * nod + 1].sum;
aint[nod].pref = max(aint[2 * nod].pref, aint[2 * nod].sum + aint[2 * nod + 1].pref);
aint[nod].suff = max(aint[2 * nod + 1].suff, aint[2 * nod + 1].sum + aint[2 * nod].suff);
aint[nod].best = max(max(aint[2 * nod].best, aint[2 * nod + 1].best), aint[2 * nod].suff + aint[2 * nod + 1].pref);
}
void update(int nod, int left, int right, int pos, int val) {
if(left == right) {
aint[nod] = {val, val, val, val};
}
else {
int mid = (left + right) / 2;
if(pos <= mid) update(2 * nod, left, mid, pos, val);
else update(2 * nod + 1, mid + 1, right, pos, val);
refresh(nod);
}
}
};
struct Point {
int x, y;
int val;
bool operator <(const Point &other) const {
if(x == other.x)
return y < other.y;
return x < other.x;
}
};
struct Slope {
int a, b;
int id1, id2;
bool operator <(const Slope &other) const {
ll s1 = 1LL * a * other.b, s2 = 1LL * other.a * b;
if(s1 == s2) {
return make_pair(id1, id2) < make_pair(other.id1, other.id2);
}
return s1 < s2;
}
};
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
vector <Point> pts(n + 1);
for(i = 1; i <= n; i++) {
cin >> pts[i].x >> pts[i].y >> pts[i].val;
}
sort(next(pts.begin()), pts.end());
vector <Slope> slp;
for(i = 1; i <= n; i++) {
for(j = i + 1; j <= n; j++) {
if(pts[i].x != pts[j].x) {
slp.push_back({pts[j].y - pts[i].y, pts[j].x - pts[i].x, i, j});
}
}
}
sort(slp.begin(), slp.end());
SegTree st; st.init(n);
vector <int> pos(n + 1);
for(i = 1; i <= n; i++) {
st.update(1, 1, n, i, pts[i].val);
pos[i] = i;
}
ll ans = max(0LL, st.aint[1].best);
int sz = slp.size();
i = 0;
while(i < sz) {
int j = i;
while(j < sz && 1LL * slp[i].a * slp[j].b == 1LL * slp[j].a * slp[i].b) {
st.update(1, 1, n, pos[slp[j].id2], pts[slp[j].id1].val);
st.update(1, 1, n, pos[slp[j].id1], pts[slp[j].id2].val);
swap(pos[slp[j].id1], pos[slp[j].id2]);
j++;
}
ans = max(ans, st.aint[1].best);
i = j;
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |