Submission #1294507

#TimeUsernameProblemLanguageResultExecution timeMemory
1294507hiepsimauhongBigger segments (IZhO19_segments)C++20
100 / 100
52 ms16084 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define FOR(I, L, R) for(int I(L) ; I <= (int)R ; ++I)
#define FOD(I, R, L) for(int I(R) ; I >= (int)L ; --I)
#define FOA(I, A) for(auto &I : A)

#define print(A,L,R) FOR(OK, L, R){if(A[OK]<=-oo / 10||A[OK]>=oo)cout<<"- ";else cout<<A[OK]<<' ';}cout<<'\n';
#define prints(A) FOA(OK, A){cout<<OK<<' ';}cout << '\n';
#define printz(A,L,R) FOR(OK, 1, L){FOR(KO, 0, R){if(A[OK][KO]>-oo&&A[OK][KO]<oo)cout<<A[OK][KO]<<' ';else cout << "- ";} cout << '\n';}cout << '\n';

#define fs first
#define sd second
#define ii pair<int,int>
#define iii pair<int, ii>
#define all(A) A.begin(), A.end()
#define quickly ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE "FILE"

const int N = 5e5 + 5;
const int mod = 1e9 + 7;
const int oo = 1e12;

struct Modint{
        int x;

        Modint(){x = 0;}
        Modint(int _x){ x = (_x % mod + mod) % mod; }

        Modint operator + (const Modint &other) const{ return (x + other.x) % mod; }
        Modint operator - (const Modint &other) const{ return (x - other.x + mod) % mod; }
        Modint operator * (const Modint &other) const{ return (1LL * x * other.x) % mod; }

        void operator += (const Modint &other){ *this = *this + other; }
        void operator -= (const Modint &other){ *this = *this - other; }
        void operator *= (const Modint &other){ *this = *this * other; }

        friend istream& operator >> (istream& is, Modint &t){ return is >> t.x; }
        friend ostream& operator << (ostream& os, Modint &t){ return os << t.x; }
};

int n, k;
int a[N], pre[N], dp[N], it[N];

signed main(){ quickly
        if(fopen(FILE".inp", "r")){
                freopen(FILE".inp", "r", stdin);
                freopen(FILE".out", "w", stdout);
        }

        cin >> n;

        FOR(i, 1, n){
                cin >> a[i];
                pre[i] = pre[i - 1] + a[i];
        }

        FOR(i, 1, n){
                it[i] = max(it[i], it[i - 1]);
                dp[i] = dp[it[i]] + 1;

                int opt = lower_bound(pre + i, pre + 1 + n, 2 * pre[i] - pre[it[i]]) - pre;
                it[opt] = i;
        }

        cout << dp[n];
}

Compilation message (stderr)

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