Submission #710624

# Submission time Handle Problem Language Result Execution time Memory
710624 2023-03-15T12:36:33 Z PoonYaPat Bigger segments (IZhO19_segments) C++14
100 / 100
404 ms 44268 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;

int n;
ll qs[500001],dp[500001];
set<pii> s;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1; i<=n; ++i) {
        cin>>qs[i];
        qs[i]+=qs[i-1];
    }
    s.insert(pii(0,0));

    for (int i=1; i<=n; ++i) {
        auto it=s.upper_bound(pii(qs[i],INT_MAX));
        --it;

        ll pos=(*it).second, nw=2*qs[i]-qs[pos];
        dp[i]=dp[pos]+1;

        it=s.upper_bound(pii(nw,INT_MAX));
        auto h=it; --h;
        if (h!=s.begin() && dp[(*h).second]>dp[i]) continue;

        it=s.upper_bound(pii(nw,-INT_MAX));
        while (it!=s.end()) {
            if ((dp[(*it).second]<dp[i]) || (dp[(*it).second]==dp[i] && (*it).second<i)) {
                auto k=it++;
                s.erase(k);
            } else break;
        }

        s.insert(pii(nw,i));
    }
    cout<<dp[n];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 524 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 2 ms 464 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 524 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 2 ms 464 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 58 ms 8460 KB Output is correct
47 Correct 52 ms 6600 KB Output is correct
48 Correct 44 ms 3036 KB Output is correct
49 Correct 63 ms 6220 KB Output is correct
50 Correct 70 ms 9028 KB Output is correct
51 Correct 63 ms 7804 KB Output is correct
52 Correct 32 ms 4096 KB Output is correct
53 Correct 17 ms 2508 KB Output is correct
54 Correct 59 ms 6572 KB Output is correct
55 Correct 77 ms 8492 KB Output is correct
56 Correct 68 ms 8632 KB Output is correct
57 Correct 62 ms 8024 KB Output is correct
58 Correct 65 ms 7888 KB Output is correct
59 Correct 66 ms 8640 KB Output is correct
60 Correct 65 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 524 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 2 ms 464 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 58 ms 8460 KB Output is correct
47 Correct 52 ms 6600 KB Output is correct
48 Correct 44 ms 3036 KB Output is correct
49 Correct 63 ms 6220 KB Output is correct
50 Correct 70 ms 9028 KB Output is correct
51 Correct 63 ms 7804 KB Output is correct
52 Correct 32 ms 4096 KB Output is correct
53 Correct 17 ms 2508 KB Output is correct
54 Correct 59 ms 6572 KB Output is correct
55 Correct 77 ms 8492 KB Output is correct
56 Correct 68 ms 8632 KB Output is correct
57 Correct 62 ms 8024 KB Output is correct
58 Correct 65 ms 7888 KB Output is correct
59 Correct 66 ms 8640 KB Output is correct
60 Correct 65 ms 8652 KB Output is correct
61 Correct 351 ms 41420 KB Output is correct
62 Correct 324 ms 41284 KB Output is correct
63 Correct 328 ms 33228 KB Output is correct
64 Correct 338 ms 18864 KB Output is correct
65 Correct 400 ms 44268 KB Output is correct
66 Correct 385 ms 37784 KB Output is correct
67 Correct 285 ms 30312 KB Output is correct
68 Correct 150 ms 15256 KB Output is correct
69 Correct 337 ms 31920 KB Output is correct
70 Correct 404 ms 41772 KB Output is correct
71 Correct 374 ms 41372 KB Output is correct
72 Correct 364 ms 35424 KB Output is correct
73 Correct 365 ms 37616 KB Output is correct
74 Correct 398 ms 42636 KB Output is correct
75 Correct 377 ms 42728 KB Output is correct