제출 #470467

#제출 시각아이디문제언어결과실행 시간메모리
470467Killer2501Bigger segments (IZhO19_segments)C++14
100 / 100
111 ms40408 KiB
#include <bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define pi pair<ll, pll>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 5e5 + 5;
const int M = 1300;
const ll mod = 1e9 + 7;
ll n, m, t, k, ans, b[N], dp[N];
long long a[N];
vector<pll> adj[N];
vector<ll> kq;
string s[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        a[i] += a[i-1];
    }
    for(int i = 1; i <= n; i ++)
    {
        b[i] = max(b[i], b[i-1]);
        dp[i] = dp[b[i]] + 1;
        int j = lower_bound(a+1, a+1+n, 2*a[i]-a[b[i]]) - a;
        if(j <= n)b[j] = max(b[j], i);
    }
    cout << dp[n];
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int test = 1;
    //cin >> test;
    while (test-- > 0)
        sol();
    return 0;
}
/*
10
4 10 2
1 2 21
1 3 13
6 7 1
7 9 5
2 4 3
2 5 8
1 6 55
6 8 34
*/
// ctrl + F8 = compile
// ctrl + F9 = run
#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...