Submission #288124

#TimeUsernameProblemLanguageResultExecution timeMemory
288124SomeoneUnknownBigger segments (IZhO19_segments)C++14
100 / 100
149 ms13816 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    long long pfs[n+1];
    int segs[n+1];
    long long hval[n+1];
    segs[0] = 0;
    hval[0] = 1;
    for(int i = 1; i <= n; ++i){
        scanf("%lld", &pfs[i]);
        pfs[i] += pfs[i-1];
        segs[i] = 0;
        hval[i] = (long long)n*1000000009;
    }
    for(int i = 0; i < n; ++i){
        segs[i+1] = max(segs[i], segs[i+1]);
        hval[i+1] = min(pfs[i+1]-pfs[i]+hval[i], hval[i+1]);
        int lo = 0;
        int hi = n+1;
        while(hi-lo>1){
            int mid = (hi+lo)/2;
            if(pfs[mid] >= pfs[i] + hval[i]){
                hi = mid;
            }else{
                lo = mid;
            }
        }
        if(hi <= n){
            segs[hi] = segs[i]+1;
            hval[hi] = min(pfs[hi]-pfs[i], hval[hi]);
            //printf("Updating %d to %d ", hi, hval[hi]);
        }
        //printf("%d %d\n", segs[i], hval[i]);
    }
    printf("%d", segs[n]);
}

Compilation message (stderr)

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