Submission #110006

#TimeUsernameProblemLanguageResultExecution timeMemory
110006popovicirobertBulldozer (JOI17_bulldozer)C++14
75 / 100
2056 ms33492 KiB
#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 { double s; int a, b; bool operator <(const Slope &other) const { return other.s - s > 0.0; } }; inline double get(Point &a, Point &b) { if(a.x == b.x) return 1.0 * INF; return 1.0 * (b.y - a.y) / (b.x - a.x); } 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++) { slp.push_back({get(pts[i], pts[j]), 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); for(auto it : slp) { int a = it.a, b = it.b; if(abs(pos[a] - pos[b]) > 1) { while(1) { } } st.update(1, 1, n, pos[a], pts[b].val); st.update(1, 1, n, pos[b], pts[a].val); swap(pos[a], pos[b]); ans = max(ans, st.aint[1].best); } cout << ans; //cin.close(); //cout.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...