This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #include <x86intrin.h>
#include <bits/stdc++.h>
#include <chrono>
#include <random>
// @author: Vlapos
namespace operators
{
template <typename T1, typename T2>
std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
{
in >> x.first >> x.second;
return in;
}
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> x)
{
out << x.first << " " << x.second;
return out;
}
template <typename T1>
std::istream &operator>>(std::istream &in, std::vector<T1> &x)
{
for (auto &i : x)
in >> i;
return in;
}
template <typename T1>
std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
{
for (auto &i : x)
out << i << " ";
return out;
}
template <typename T1>
std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
{
for (auto &i : x)
out << i << " ";
return out;
}
}
// name spaces
using namespace std;
using namespace operators;
// end of name spaces
// defines
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()
// end of defines
// usefull stuff
void boost()
{
ios_base ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
inline int getbit(int &x, int &bt) { return (x >> bt) & 1; }
const int dx4[4] = {-1, 0, 0, 1};
const int dy4[4] = {0, -1, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, -0, 1, -1, 1, -1, 0, 1};
const ll INF = (1e18) + 500;
const int BIG = (1e9) * 2 + 100;
const int MAXN = (1e5) + 5;
const int MOD7 = (1e9) + 7;
const int MOD9 = (1e9) + 9;
const uint MODFFT = 998244353;
#define int ll
struct segTree
{
struct Node
{
int mxSum = 0, mxPref = 0, mxSuff = 0, sum = 0;
};
vector<Node> tree;
int sz = 0;
Node merge(Node a, Node b)
{
Node res;
res.sum = a.sum + b.sum;
res.mxSum = max({a.mxSum, b.mxSum, res.mxSum, a.mxSuff + b.mxPref});
res.mxPref = max(a.mxPref, a.sum + b.mxPref);
res.mxSuff = max(b.mxSuff, b.sum + a.mxSuff);
return res;
}
void init(int n)
{
sz = 1;
while (sz < n)
sz *= 2;
tree.resize(2 * sz);
}
void set(int pos, int val, int v, int lv, int rv)
{
if (rv - lv == 1)
{
tree[v].mxPref = tree[v].mxSum = tree[v].mxSuff = max(val, 0LL);
tree[v].sum = val;
return;
}
int m = (lv + rv) >> 1;
if (pos < m)
set(pos, val, v * 2 + 1, lv, m);
else
set(pos, val, v * 2 + 2, m, rv);
tree[v] = merge(tree[v * 2 + 1], tree[v * 2 + 2]);
}
void set(int pos, int val)
{
set(pos, val, 0, 0, sz);
}
};
struct test
{
void solve(int testcase)
{
boost();
int n;
cin >> n;
vector<pair<pii, int>> els(n);
cin >> els;
sort(all(els), [](pair<pii, int> a, pair<pii, int> b)
{if(a.f.f != b.f.f) return a.f.f < b.f.f; return a.f.s > b.f.s; });
vector<pair<double, pii>> ks;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
{
double cur = (els[j].f.f - els[i].f.f) ? ((double)els[j].f.s - els[i].f.s) / (els[j].f.f - els[i].f.f) : -BIG;
ks.pb({cur, {i, j}});
}
sort(all(ks));
// vector<pair<pii, int>> bf;
// for (int i = 0; i < n; ++i)
// bf.pb({{els[i].f.s, els[i].f.f}, i});
// sort(all(bf));
vector<int> pos(n);
vector<int> cur(n), val(n);
segTree tree;
tree.init(n);
for (int i = 0; i < n; ++i)
{
pos[i] = i;
cur[i] = els[i].s;
val[i] = i;
// poses[bf[i].s] = i;
// cur[i] = els[bf[i].s].s;
tree.set(i, cur[i]);
}
int res = tree.tree[0].mxSum;
vector<vector<int>> bck(n);
vector<int> was(n, -1);
vector<pii> HELP;
for (int i = 0; i <= ks.size(); ++i)
{
if (i == ks.size() or (i != 0 and ks[i].f != ks[i - 1].f))
{
vector<int> vals;
for (auto [a, b] : HELP)
{
if (pos[a] > pos[b])
swap(a, b);
bck[pos[a]].pb(pos[b]);
vals.pb(pos[a]);
}
sort(all(vals));
HELP.clear();
int mx = -1;
for (int el : vals)
{
if (was[el] == i or el <= mx)
{
bck[el].clear();
continue;
}
was[el] = i;
for (int cur : bck[el])
mx = max(cur, mx);
int mn = el;
for (int i = 0; mn + i < mx - i; ++i)
{
tree.set(mn + i, cur[mx - i]);
tree.set(mx - i, cur[mn + i]);
swap(cur[mn + i], cur[mx - i]);
swap(val[mn + i], val[mx - i]);
swap(pos[val[mn + i]], pos[val[mx - i]]);
}
bck[el].clear();
}
// cout << cur << ": " << tree.tree[0].mxSum << "\n";
res = max(res, tree.tree[0].mxSum);
}
if (i != ks.size())
{
HELP.pb(ks[i].s);
}
}
cout << res << '\n';
}
};
main()
{
boost();
int q = 1;
// cin >> q;
for (int i = 0; i < q; i++)
{
test t;
t.solve(i);
}
return 0;
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
// //
// Coded by Der_Vlἀpos //
// //
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
Compilation message (stderr)
bulldozer.cpp: In member function 'void test::solve(long long int)':
bulldozer.cpp:191:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
191 | for (int i = 0; i <= ks.size(); ++i)
| ~~^~~~~~~~~~~~
bulldozer.cpp:193:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
193 | if (i == ks.size() or (i != 0 and ks[i].f != ks[i - 1].f))
| ~~^~~~~~~~~~~~
bulldozer.cpp:234:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
234 | if (i != ks.size())
| ~~^~~~~~~~~~~~
bulldozer.cpp: At global scope:
bulldozer.cpp:243:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
243 | main()
| ^~~~
# | 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... |