Submission #299755

# Submission time Handle Problem Language Result Execution time Memory
299755 2020-09-15T15:04:06 Z dantoh000 Bigger segments (IZhO19_segments) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, int> li;
ii dp[500005];
int n;
ll p[500005];
ll k[500005];
priority_queue<li, vector<li>, greater<li> > pq;
int main(){
    scanf("%d",&n);
    pq.push({0,0});
    for (int i = 1; i <= n; i++){
        scanf("%lld",&p[i]);
        p[i]+=p[i-1];
        int j;
        for (j = i-1; j >= 0; j--){
            if (p[i] >= k[j]) break;
        }

        /*li cur;
        while (pq.size() && pq.top().fi <= p[i]){
            cur = pq.top(); pq.pop();
        }*/

        pq.push(cur);
        int j = cur.se;
        dp[i] = {dp[j].fi+1, j};
        k[i] = 2*p[i]-p[j];
        //printf("%lld: ",2*p[i]-p[j]);
        pq.push({k[i],i});
    }
    for (int i = 1; i <= n; i++){
        assert(k[i] >= k[i-1]);
    }
    printf("%d",dp[n].fi);
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:29:17: error: 'cur' was not declared in this scope
   29 |         pq.push(cur);
      |                 ^~~
segments.cpp:30:13: error: redeclaration of 'int j'
   30 |         int j = cur.se;
      |             ^
segments.cpp:19:13: note: 'int j' previously declared here
   19 |         int j;
      |             ^
segments.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
segments.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |         scanf("%lld",&p[i]);
      |         ~~~~~^~~~~~~~~~~~~~