이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct pt {
int x, y;
};
bool same(int x1, int y1, int x2, int y2) {
// y1 / x1 = y2 / x2
return x1 * 1LL * y2 == y1 * 1LL * x2;
}
long long cross(pt a, pt b) {
return a.x * 1LL * b.y - a.y * 1LL * b.x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> x(n), y(n), w(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> w[i];
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
if (y[i] != y[j]) {
return y[i] < y[j];
} else {
return x[i] < x[j];
}
});
vector<int> pos(n);
for (int i = 0; i < n; i++) {
pos[order[i]] = i;
}
vector<long long> mx(4 * n);
vector<long long> sum(4 * n);
vector<long long> pref(4 * n);
vector<long long> suff(4 * n);
auto Pull = [&](int x) {
sum[x] = sum[x << 1] + sum[x << 1 | 1];
mx[x] = max({mx[x << 1], mx[x << 1 | 1], suff[x << 1] + pref[x << 1 | 1]});
pref[x] = max(pref[x << 1], sum[x << 1] + pref[x << 1 | 1]);
suff[x] = max(suff[x << 1 | 1], sum[x << 1 | 1] + suff[x << 1]);
};
function<void(int, int, int)> Build = [&](int x, int l, int r) {
if (l == r) {
sum[x] = w[order[l]];
mx[x] = max(0LL, sum[x]);
pref[x] = max(0LL, sum[x]);
suff[x] = max(0LL, sum[x]);
return;
}
int mid = l + r >> 1;
Build(x << 1, l, mid);
Build(x << 1 | 1, mid + 1, r);
Pull(x);
};
function<void(int, int, int, int)> Update = [&](int x, int l, int r, int p) {
if (l == r) {
sum[x] = w[order[l]];
mx[x] = max(0LL, sum[x]);
pref[x] = max(0LL, sum[x]);
suff[x] = max(0LL, sum[x]);
return;
}
int mid = l + r >> 1;
if (p <= mid) {
Update(x << 1, l, mid, p);
} else {
Update(x << 1 | 1, mid + 1, r, p);
}
Pull(x);
};
Build(1, 0, n - 1);
vector<array<int, 4>> qs;
for (int _i = 0; _i < n; _i++) {
for (int _j = _i + 1; _j < n; _j++) {
int i = order[_i];
int j = order[_j];
int fx = x[j] - x[i];
int fy = y[j] - y[i];
if (fy < 0 || (fy == 0 && fx < 0)) {
fx = -fx;
fy = -fy;
}
qs.push_back({fx, fy, i, j});
}
}
sort(qs.begin(), qs.end(), [&](array<int, 4> a, array<int, 4> b) {
pt p;
p.x = a[0];
p.y = a[1];
pt q;
q.x = b[0];
q.y = b[1];
if (cross(p, q) == 0) {
return make_pair(pos[a[2]], pos[a[3]]) < make_pair(pos[b[2]], pos[b[3]]);
}
return cross(p, q) > 0;
});
int sz = (int) qs.size();
long long ans = mx[1];
for (int i = 0; i < sz; i++) {
int ptr = i;
while (ptr < sz && same(qs[i][0], qs[i][1], qs[ptr][0], qs[ptr][1])) {
swap(order[pos[qs[ptr][2]]], order[pos[qs[ptr][3]]]);
swap(pos[qs[ptr][2]], pos[qs[ptr][3]]);
Update(1, 0, n - 1, pos[qs[ptr][2]]);
Update(1, 0, n - 1, pos[qs[ptr][3]]);
ptr += 1;
}
ans = max(ans, mx[1]);
i = ptr - 1;
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bulldozer.cpp: In lambda function:
bulldozer.cpp:58:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int mid = l + r >> 1;
| ~~^~~
bulldozer.cpp: In lambda function:
bulldozer.cpp:71:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int mid = l + r >> 1;
| ~~^~~
# | 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... |