Submission #470467

# Submission time Handle Problem Language Result Execution time Memory
470467 2021-09-04T01:06:57 Z Killer2501 Bigger segments (IZhO19_segments) C++14
100 / 100
111 ms 40408 KB
#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 time Memory Grader output
1 Correct 15 ms 27724 KB Output is correct
2 Correct 15 ms 27724 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27648 KB Output is correct
5 Correct 15 ms 27724 KB Output is correct
6 Correct 15 ms 27724 KB Output is correct
7 Correct 15 ms 27724 KB Output is correct
8 Correct 15 ms 27724 KB Output is correct
9 Correct 15 ms 27724 KB Output is correct
10 Correct 15 ms 27724 KB Output is correct
11 Correct 15 ms 27720 KB Output is correct
12 Correct 15 ms 27720 KB Output is correct
13 Correct 15 ms 27724 KB Output is correct
14 Correct 15 ms 27660 KB Output is correct
15 Correct 15 ms 27712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27724 KB Output is correct
2 Correct 15 ms 27724 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27648 KB Output is correct
5 Correct 15 ms 27724 KB Output is correct
6 Correct 15 ms 27724 KB Output is correct
7 Correct 15 ms 27724 KB Output is correct
8 Correct 15 ms 27724 KB Output is correct
9 Correct 15 ms 27724 KB Output is correct
10 Correct 15 ms 27724 KB Output is correct
11 Correct 15 ms 27720 KB Output is correct
12 Correct 15 ms 27720 KB Output is correct
13 Correct 15 ms 27724 KB Output is correct
14 Correct 15 ms 27660 KB Output is correct
15 Correct 15 ms 27712 KB Output is correct
16 Correct 15 ms 27724 KB Output is correct
17 Correct 15 ms 27724 KB Output is correct
18 Correct 18 ms 27724 KB Output is correct
19 Correct 15 ms 27648 KB Output is correct
20 Correct 15 ms 27652 KB Output is correct
21 Correct 16 ms 27724 KB Output is correct
22 Correct 15 ms 27724 KB Output is correct
23 Correct 15 ms 27632 KB Output is correct
24 Correct 17 ms 27640 KB Output is correct
25 Correct 15 ms 27720 KB Output is correct
26 Correct 15 ms 27724 KB Output is correct
27 Correct 15 ms 27724 KB Output is correct
28 Correct 15 ms 27740 KB Output is correct
29 Correct 16 ms 27708 KB Output is correct
30 Correct 16 ms 27628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27724 KB Output is correct
2 Correct 15 ms 27724 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27648 KB Output is correct
5 Correct 15 ms 27724 KB Output is correct
6 Correct 15 ms 27724 KB Output is correct
7 Correct 15 ms 27724 KB Output is correct
8 Correct 15 ms 27724 KB Output is correct
9 Correct 15 ms 27724 KB Output is correct
10 Correct 15 ms 27724 KB Output is correct
11 Correct 15 ms 27720 KB Output is correct
12 Correct 15 ms 27720 KB Output is correct
13 Correct 15 ms 27724 KB Output is correct
14 Correct 15 ms 27660 KB Output is correct
15 Correct 15 ms 27712 KB Output is correct
16 Correct 15 ms 27724 KB Output is correct
17 Correct 15 ms 27724 KB Output is correct
18 Correct 18 ms 27724 KB Output is correct
19 Correct 15 ms 27648 KB Output is correct
20 Correct 15 ms 27652 KB Output is correct
21 Correct 16 ms 27724 KB Output is correct
22 Correct 15 ms 27724 KB Output is correct
23 Correct 15 ms 27632 KB Output is correct
24 Correct 17 ms 27640 KB Output is correct
25 Correct 15 ms 27720 KB Output is correct
26 Correct 15 ms 27724 KB Output is correct
27 Correct 15 ms 27724 KB Output is correct
28 Correct 15 ms 27740 KB Output is correct
29 Correct 16 ms 27708 KB Output is correct
30 Correct 16 ms 27628 KB Output is correct
31 Correct 15 ms 27728 KB Output is correct
32 Correct 15 ms 27736 KB Output is correct
33 Correct 15 ms 27736 KB Output is correct
34 Correct 16 ms 27756 KB Output is correct
35 Correct 16 ms 27720 KB Output is correct
36 Correct 17 ms 27772 KB Output is correct
37 Correct 16 ms 27796 KB Output is correct
38 Correct 16 ms 27748 KB Output is correct
39 Correct 17 ms 27720 KB Output is correct
40 Correct 16 ms 27724 KB Output is correct
41 Correct 16 ms 27724 KB Output is correct
42 Correct 16 ms 27852 KB Output is correct
43 Correct 16 ms 27704 KB Output is correct
44 Correct 16 ms 27732 KB Output is correct
45 Correct 16 ms 27744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27724 KB Output is correct
2 Correct 15 ms 27724 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27648 KB Output is correct
5 Correct 15 ms 27724 KB Output is correct
6 Correct 15 ms 27724 KB Output is correct
7 Correct 15 ms 27724 KB Output is correct
8 Correct 15 ms 27724 KB Output is correct
9 Correct 15 ms 27724 KB Output is correct
10 Correct 15 ms 27724 KB Output is correct
11 Correct 15 ms 27720 KB Output is correct
12 Correct 15 ms 27720 KB Output is correct
13 Correct 15 ms 27724 KB Output is correct
14 Correct 15 ms 27660 KB Output is correct
15 Correct 15 ms 27712 KB Output is correct
16 Correct 15 ms 27724 KB Output is correct
17 Correct 15 ms 27724 KB Output is correct
18 Correct 18 ms 27724 KB Output is correct
19 Correct 15 ms 27648 KB Output is correct
20 Correct 15 ms 27652 KB Output is correct
21 Correct 16 ms 27724 KB Output is correct
22 Correct 15 ms 27724 KB Output is correct
23 Correct 15 ms 27632 KB Output is correct
24 Correct 17 ms 27640 KB Output is correct
25 Correct 15 ms 27720 KB Output is correct
26 Correct 15 ms 27724 KB Output is correct
27 Correct 15 ms 27724 KB Output is correct
28 Correct 15 ms 27740 KB Output is correct
29 Correct 16 ms 27708 KB Output is correct
30 Correct 16 ms 27628 KB Output is correct
31 Correct 15 ms 27728 KB Output is correct
32 Correct 15 ms 27736 KB Output is correct
33 Correct 15 ms 27736 KB Output is correct
34 Correct 16 ms 27756 KB Output is correct
35 Correct 16 ms 27720 KB Output is correct
36 Correct 17 ms 27772 KB Output is correct
37 Correct 16 ms 27796 KB Output is correct
38 Correct 16 ms 27748 KB Output is correct
39 Correct 17 ms 27720 KB Output is correct
40 Correct 16 ms 27724 KB Output is correct
41 Correct 16 ms 27724 KB Output is correct
42 Correct 16 ms 27852 KB Output is correct
43 Correct 16 ms 27704 KB Output is correct
44 Correct 16 ms 27732 KB Output is correct
45 Correct 16 ms 27744 KB Output is correct
46 Correct 26 ms 29644 KB Output is correct
47 Correct 29 ms 29724 KB Output is correct
48 Correct 32 ms 30032 KB Output is correct
49 Correct 33 ms 30188 KB Output is correct
50 Correct 34 ms 30168 KB Output is correct
51 Correct 34 ms 30228 KB Output is correct
52 Correct 25 ms 28996 KB Output is correct
53 Correct 22 ms 28448 KB Output is correct
54 Correct 28 ms 29420 KB Output is correct
55 Correct 33 ms 30232 KB Output is correct
56 Correct 33 ms 29676 KB Output is correct
57 Correct 30 ms 29772 KB Output is correct
58 Correct 31 ms 29644 KB Output is correct
59 Correct 31 ms 29744 KB Output is correct
60 Correct 31 ms 29876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27724 KB Output is correct
2 Correct 15 ms 27724 KB Output is correct
3 Correct 15 ms 27628 KB Output is correct
4 Correct 15 ms 27648 KB Output is correct
5 Correct 15 ms 27724 KB Output is correct
6 Correct 15 ms 27724 KB Output is correct
7 Correct 15 ms 27724 KB Output is correct
8 Correct 15 ms 27724 KB Output is correct
9 Correct 15 ms 27724 KB Output is correct
10 Correct 15 ms 27724 KB Output is correct
11 Correct 15 ms 27720 KB Output is correct
12 Correct 15 ms 27720 KB Output is correct
13 Correct 15 ms 27724 KB Output is correct
14 Correct 15 ms 27660 KB Output is correct
15 Correct 15 ms 27712 KB Output is correct
16 Correct 15 ms 27724 KB Output is correct
17 Correct 15 ms 27724 KB Output is correct
18 Correct 18 ms 27724 KB Output is correct
19 Correct 15 ms 27648 KB Output is correct
20 Correct 15 ms 27652 KB Output is correct
21 Correct 16 ms 27724 KB Output is correct
22 Correct 15 ms 27724 KB Output is correct
23 Correct 15 ms 27632 KB Output is correct
24 Correct 17 ms 27640 KB Output is correct
25 Correct 15 ms 27720 KB Output is correct
26 Correct 15 ms 27724 KB Output is correct
27 Correct 15 ms 27724 KB Output is correct
28 Correct 15 ms 27740 KB Output is correct
29 Correct 16 ms 27708 KB Output is correct
30 Correct 16 ms 27628 KB Output is correct
31 Correct 15 ms 27728 KB Output is correct
32 Correct 15 ms 27736 KB Output is correct
33 Correct 15 ms 27736 KB Output is correct
34 Correct 16 ms 27756 KB Output is correct
35 Correct 16 ms 27720 KB Output is correct
36 Correct 17 ms 27772 KB Output is correct
37 Correct 16 ms 27796 KB Output is correct
38 Correct 16 ms 27748 KB Output is correct
39 Correct 17 ms 27720 KB Output is correct
40 Correct 16 ms 27724 KB Output is correct
41 Correct 16 ms 27724 KB Output is correct
42 Correct 16 ms 27852 KB Output is correct
43 Correct 16 ms 27704 KB Output is correct
44 Correct 16 ms 27732 KB Output is correct
45 Correct 16 ms 27744 KB Output is correct
46 Correct 26 ms 29644 KB Output is correct
47 Correct 29 ms 29724 KB Output is correct
48 Correct 32 ms 30032 KB Output is correct
49 Correct 33 ms 30188 KB Output is correct
50 Correct 34 ms 30168 KB Output is correct
51 Correct 34 ms 30228 KB Output is correct
52 Correct 25 ms 28996 KB Output is correct
53 Correct 22 ms 28448 KB Output is correct
54 Correct 28 ms 29420 KB Output is correct
55 Correct 33 ms 30232 KB Output is correct
56 Correct 33 ms 29676 KB Output is correct
57 Correct 30 ms 29772 KB Output is correct
58 Correct 31 ms 29644 KB Output is correct
59 Correct 31 ms 29744 KB Output is correct
60 Correct 31 ms 29876 KB Output is correct
61 Correct 71 ms 37452 KB Output is correct
62 Correct 73 ms 37480 KB Output is correct
63 Correct 83 ms 37816 KB Output is correct
64 Correct 111 ms 40176 KB Output is correct
65 Correct 106 ms 40388 KB Output is correct
66 Correct 106 ms 40268 KB Output is correct
67 Correct 91 ms 37840 KB Output is correct
68 Correct 54 ms 32704 KB Output is correct
69 Correct 82 ms 36564 KB Output is correct
70 Correct 109 ms 40408 KB Output is correct
71 Correct 88 ms 37464 KB Output is correct
72 Correct 83 ms 37840 KB Output is correct
73 Correct 92 ms 38400 KB Output is correct
74 Correct 96 ms 38832 KB Output is correct
75 Correct 99 ms 38724 KB Output is correct