Submission #1184367

#TimeUsernameProblemLanguageResultExecution timeMemory
1184367HaanhtienBigger segments (IZhO19_segments)C++17
0 / 100
1 ms328 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for(int i=(a), _b=(b); i<=_b; i++) #define FORD(i, a, b) for(int i=(a), _b=(b); i>=_b; i--) #define BIT(i, j) ((i>>j)&1) #define pb push_back #define ii pair<ll, ll> #define pii pair<ll, ii> #define all(x) x.begin(), x.end() #define fi first #define se second const ll inf = 1e18; const ll mod = 1e9+7; const ll N = 500005; const ll M = 50005; int n; ll a[N], pre[N]; deque<ii> dq; ii f[N]; void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pre[i] = pre[i - 1] + a[i]; } dq.push_back({0, 0}); int j = 1; for (int i = 1; i <= n; i++) { while (j < i && f[j].se + pre[j] <= pre[i]) { dq.push_back({f[j].se + pre[j], j}); j++; } auto [x, id] = dq.back(); //cout << x << ' ' << id << '\n'; f[i] = {f[id].fi + 1, pre[i] - pre[id]}; //cout << f[i].fi << ' ' << f[i].se << '\n'; while (!dq.empty() && f[dq.front().se].fi + 1 < f[i].fi) dq.pop_front(); } cout << f[n].fi; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "task" if(fopen(task".inp", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(task".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...