Submission #376952

#TimeUsernameProblemLanguageResultExecution timeMemory
376952joelauBigger segments (IZhO19_segments)C++14
100 / 100
81 ms12272 KiB
#include <bits/stdc++.h> using namespace std; int N,ans[500001]; long long A[500001], sz[500001]; deque<int> dq; int main() { scanf("%d", &N); A[0] = 0; for (int i = 1; i <= N; ++i) { scanf("%lld", &A[i]); A[i] += A[i-1]; } ans[0] = 0, sz[0] = 0; for (int i = 1; i <= N; ++i) { while (dq.size() > 1 && sz[dq[1]] + A[dq[1]] <= A[i]) dq.pop_front(); if (!dq.empty() && sz[dq.front()] + A[dq.front()] <= A[i]) ans[i] = ans[dq.front()]+1, sz[i] = A[i] - A[dq.front()]; else ans[i] = 1, sz[i] = A[i]; while (!dq.empty() && sz[i] + A[i] <= sz[dq.back()] + A[dq.back()]) dq.pop_back(); dq.push_back(i); } printf("%d", ans[N]); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
segments.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         scanf("%lld", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
#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...