Submission #1300131

#TimeUsernameProblemLanguageResultExecution timeMemory
1300131ThanhsDischarging (NOI20_discharging)C++20
11 / 100
302 ms127092 KiB
#include <bits/stdc++.h> using namespace std; #define name "TENBAI" #define fi first #define se second #define int long long #define endl '\n' #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) #define all(x) x.begin(), x.end() mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 1e6 + 5; int a[NM], n, f[NM]; deque<pair<int, list<int>>> v; multiset<int> s; bool check(int k1, int m1, int k2, int m2, int k3, int m3) { int inter1 = (m2 - m1) / (k1 - k2), inter2 = (m3 - m1) / (k1 - k3); return inter1 >= inter2; } void solve() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; v.push_back({0, {}}); v.back().se.push_back(0); s.insert(0); for (int i = 1; i <= n; i++) { bool siu = 0; while (v.size() && v.back().fi <= a[i]) { int t = *v.back().se.begin(); s.erase(s.find(f[t] + v.back().fi * (n - t))); if (v.size() > 1 && v[v.size() - 2].fi <= a[i]) { v[v.size() - 2].se.splice(v[v.size() - 2].se.end(), v.back().se); v.pop_back(); } else break; } if (v.back().fi <= a[i]) { v.back().fi = a[i]; auto& li = v.back().se; while (li.size() >= 2) { auto beg = li.begin(); int x = *beg, y = *next(beg); if (li.size() >= 3 && check(f[x], n - x, f[y], n - y, f[*next(beg, 2)], n - *next(beg, 2))) { li.erase(next(beg)); continue; } if (f[x] + a[i] * (n - x) >= f[y] + a[i] * (n - y)) { li.erase(beg); continue; } break; } int x = *li.begin(); s.insert(f[x] + a[i] * (n - x)); li.push_back(i); } f[i] = *s.begin(); if (v.back().fi > a[i]) { v.push_back({a[i], {i}}); s.insert(f[i] + a[i] * (n - i)); } } cout << f[n]; } signed main() { if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } else if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tc = 1; // cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

Discharging.cpp: In function 'int main()':
Discharging.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Discharging.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Discharging.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Discharging.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...