Submission #376940

#TimeUsernameProblemLanguageResultExecution timeMemory
376940jamezzzBigger segments (IZhO19_segments)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; //less_equal for identical elements //#define DEBUG #ifdef DEBUG #define debug(...) printf(__VA_ARGS__); #else #define debug(...) #endif #define fi first #define se second #define pb emplace_back #define sz(x) (int)x.size() #define mnto(x,y) x=min(x,(__typeof__(x))y) #define mxto(x,y) x=max(x,(__typeof__(x))y) #define INF 1023456789 #define LINF 1023456789123456789 #define all(x) x.begin(), x.end() typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<pll> vll; int n,a[500005],ans[500005]; ll pfx[500005]; deque<pll> dq; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i){ scanf("%d",&a[i]); pfx[i]=pfx[i-1]+a[i]; } dq.push_back(pll(0,0)); for(int i=1;i<=n;++i){ while(dq.size()>=2&&dq[1].fi<=pfx[i])dq.pop_front(); int l=dq.front().se; debug("%d\n",l); ans[i]=ans[l]+1; ll sz=pfx[i]-pfx[l]; dq.push_back(pll(sz+pfx[i],i)); } printf("%d\n",ans[n]); }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
segments.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |   scanf("%d",&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...