제출 #1110090

#제출 시각아이디문제언어결과실행 시간메모리
1110090vladiliusBulldozer (JOI17_bulldozer)C++17
55 / 100
755 ms35796 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second struct ST{ struct node{ ll pr, sf, mx, s; }; vector<node> t; int n; ST(int ns){ n = ns; t.resize(4 * n); } void upd(int v, int tl, int tr, int& p, int& x){ if (tl == tr){ t[v].s = x; t[v].pr = t[v].sf = t[v].mx = max(0, x); return; } int tm = (tl + tr) / 2, vv = 2 * v; if (p <= tm){ upd(vv, tl, tm, p, x); } else { upd(vv + 1, tm + 1, tr, p, x); } t[v].s = t[vv].s + t[vv + 1].s; t[v].mx = max({t[vv].mx, t[vv + 1].mx, t[vv].sf + t[vv + 1].pr}); t[v].pr = max(t[vv].pr, t[vv].s + t[vv + 1].pr); t[v].sf = max(t[vv + 1].sf, t[vv + 1].s + t[vv].sf); } void upd(int p, int x){ upd(1, 1, n, p, x); } ll get(){ return t[1].mx; } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int> x(n + 1), y(n + 1), a(n + 1), f = {0}; for (int i = 1; i <= n; i++){ cin>>x[i]>>y[i]>>a[i]; f.pb(i); } auto cmp = [&](int i, int j){ return x[i] < x[j]; }; sort(f.begin() + 1, f.end(), cmp); vector<int> p(n + 1); for (int i = 1; i <= n; i++){ p[f[i]] = i; } ST T(n); for (int i = 1; i <= n; i++){ T.upd(p[i], a[i]); } ll out = T.get(); vector<pair<pii, pii>> all; for (int i = 1; i <= n; i++){ for (int j = i + 1; j <= n; j++){ if (x[f[i]] != x[f[j]]){ all.pb({{y[f[j]] - y[f[i]], x[f[j]] - x[f[i]]}, {f[i], f[j]}}); } } } auto cmp1 = [&](pair<pii, pii> a, pair<pii, pii> b){ auto [u1, v1] = a.ff; auto [u2, v2] = b.ff; return 1LL * u1 * v2 < 1LL * u2 * v1; }; sort(all.begin(), all.end(), cmp1); vector<int> rem; vector<bool> used(n + 1); int i = 0; while (i < all.size()){ int j = i; while (j < all.size() && (1LL * all[i].ff.ff * all[j].ff.ss) == (1LL * all[i].ff.ss * all[j].ff.ff)){ auto [u, v] = all[j].ss; assert(!used[u] && !used[v]); used[u] = used[v] = 1; rem.pb(u); rem.pb(v); swap(p[u], p[v]); T.upd(p[u], a[u]); T.upd(p[v], a[v]); j++; } for (int j: rem) used[j] = 0; rem.clear(); out = max(out, T.get()); i = j; } cout<<out<<"\n"; }

컴파일 시 표준 에러 (stderr) 메시지

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:91:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     while (i < all.size()){
      |            ~~^~~~~~~~~~~~
bulldozer.cpp:93:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         while (j < all.size() && (1LL * all[i].ff.ff * all[j].ff.ss) == (1LL * all[i].ff.ss * all[j].ff.ff)){
      |                ~~^~~~~~~~~~~~
#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...