Submission #1118709

# Submission time Handle Problem Language Result Execution time Memory
1118709 2024-11-26T03:11:59 Z HuyAT Bigger segments (IZhO19_segments) C++14
100 / 100
270 ms 42316 KB
#include<bits/stdc++.h>
#define newl '\n'

const int N = 5e5 + 10;
const int V = 1e7 + 10;
const long long S = 1e16;
const long long INF = 1e18;
const long long M = 1e9 + 7;

struct Node{
    int ans;
    long long s;
    Node() : ans(0),s(0){

    }
    Node(int ans,long long s) : ans(ans),s(s){

    }
    bool operator < (const Node &other){
        return (ans < other.ans || (ans == other.ans && s < other.s));
    }
};

int a[N + 1],n;
long long s[N + 1];

void readData(){
    std::cin >> n;
    for(int i = 1;i <= n;++i){
        std::cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
}
int solve(){
    std::map<long long,Node> m;
    auto add = [&](long long pos,Node val){
        auto it = m.lower_bound(pos);
        if(it != m.end() && val < it->second){
            return;
        }
        it = m.insert(it,{pos,val});
        it->second = val;
        while(next(it) != m.end() && next(it)->second < val){
            m.erase(next(it));
        }
    };
    auto query = [&](long long pos)-> Node{
        auto it = m.upper_bound(pos);
        return prev(it)->second;
    };
    add(0,Node());
    int ans = 0;
    for(int i = 1;i <= n;++i){
//        std::cout << st.root->ans << newl;
        Node t = query(s[i]);
//        std::cerr << t.ans << " " << t.s << " " << s[i] - t.s + s[i] << " " << s[i] << newl;
        ans = std::max(ans,t.ans + 1);
        add(s[i] - t.s + s[i],Node(t.ans + 1,s[i]));
    }
    return ans;
}
int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);std::cout.tie(nullptr);
    readData();
    std::cout << solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 2 ms 2400 KB Output is correct
18 Correct 2 ms 2400 KB Output is correct
19 Correct 1 ms 2400 KB Output is correct
20 Correct 2 ms 2400 KB Output is correct
21 Correct 2 ms 2400 KB Output is correct
22 Correct 1 ms 2388 KB Output is correct
23 Correct 1 ms 2516 KB Output is correct
24 Correct 2 ms 2388 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 504 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 428 KB Output is correct
30 Correct 1 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 2 ms 2400 KB Output is correct
18 Correct 2 ms 2400 KB Output is correct
19 Correct 1 ms 2400 KB Output is correct
20 Correct 2 ms 2400 KB Output is correct
21 Correct 2 ms 2400 KB Output is correct
22 Correct 1 ms 2388 KB Output is correct
23 Correct 1 ms 2516 KB Output is correct
24 Correct 2 ms 2388 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 504 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 428 KB Output is correct
30 Correct 1 ms 2388 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 476 KB Output is correct
33 Correct 2 ms 508 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 2 ms 608 KB Output is correct
40 Correct 3 ms 608 KB Output is correct
41 Correct 2 ms 608 KB Output is correct
42 Correct 2 ms 608 KB Output is correct
43 Correct 2 ms 608 KB Output is correct
44 Correct 2 ms 608 KB Output is correct
45 Correct 1 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 2 ms 2400 KB Output is correct
18 Correct 2 ms 2400 KB Output is correct
19 Correct 1 ms 2400 KB Output is correct
20 Correct 2 ms 2400 KB Output is correct
21 Correct 2 ms 2400 KB Output is correct
22 Correct 1 ms 2388 KB Output is correct
23 Correct 1 ms 2516 KB Output is correct
24 Correct 2 ms 2388 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 504 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 428 KB Output is correct
30 Correct 1 ms 2388 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 476 KB Output is correct
33 Correct 2 ms 508 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 2 ms 608 KB Output is correct
40 Correct 3 ms 608 KB Output is correct
41 Correct 2 ms 608 KB Output is correct
42 Correct 2 ms 608 KB Output is correct
43 Correct 2 ms 608 KB Output is correct
44 Correct 2 ms 608 KB Output is correct
45 Correct 1 ms 608 KB Output is correct
46 Correct 40 ms 11360 KB Output is correct
47 Correct 38 ms 9304 KB Output is correct
48 Correct 26 ms 6000 KB Output is correct
49 Correct 32 ms 9036 KB Output is correct
50 Correct 41 ms 11944 KB Output is correct
51 Correct 42 ms 10572 KB Output is correct
52 Correct 24 ms 3924 KB Output is correct
53 Correct 11 ms 2388 KB Output is correct
54 Correct 37 ms 6240 KB Output is correct
55 Correct 44 ms 8200 KB Output is correct
56 Correct 40 ms 8276 KB Output is correct
57 Correct 37 ms 7756 KB Output is correct
58 Correct 35 ms 7500 KB Output is correct
59 Correct 42 ms 8268 KB Output is correct
60 Correct 42 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 2 ms 2400 KB Output is correct
18 Correct 2 ms 2400 KB Output is correct
19 Correct 1 ms 2400 KB Output is correct
20 Correct 2 ms 2400 KB Output is correct
21 Correct 2 ms 2400 KB Output is correct
22 Correct 1 ms 2388 KB Output is correct
23 Correct 1 ms 2516 KB Output is correct
24 Correct 2 ms 2388 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 504 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 428 KB Output is correct
30 Correct 1 ms 2388 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 476 KB Output is correct
33 Correct 2 ms 508 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 2 ms 608 KB Output is correct
40 Correct 3 ms 608 KB Output is correct
41 Correct 2 ms 608 KB Output is correct
42 Correct 2 ms 608 KB Output is correct
43 Correct 2 ms 608 KB Output is correct
44 Correct 2 ms 608 KB Output is correct
45 Correct 1 ms 608 KB Output is correct
46 Correct 40 ms 11360 KB Output is correct
47 Correct 38 ms 9304 KB Output is correct
48 Correct 26 ms 6000 KB Output is correct
49 Correct 32 ms 9036 KB Output is correct
50 Correct 41 ms 11944 KB Output is correct
51 Correct 42 ms 10572 KB Output is correct
52 Correct 24 ms 3924 KB Output is correct
53 Correct 11 ms 2388 KB Output is correct
54 Correct 37 ms 6240 KB Output is correct
55 Correct 44 ms 8200 KB Output is correct
56 Correct 40 ms 8276 KB Output is correct
57 Correct 37 ms 7756 KB Output is correct
58 Correct 35 ms 7500 KB Output is correct
59 Correct 42 ms 8268 KB Output is correct
60 Correct 42 ms 8268 KB Output is correct
61 Correct 221 ms 39500 KB Output is correct
62 Correct 247 ms 39500 KB Output is correct
63 Correct 222 ms 31308 KB Output is correct
64 Correct 216 ms 16936 KB Output is correct
65 Correct 261 ms 42316 KB Output is correct
66 Correct 244 ms 35916 KB Output is correct
67 Correct 198 ms 28868 KB Output is correct
68 Correct 81 ms 14516 KB Output is correct
69 Correct 196 ms 30108 KB Output is correct
70 Correct 257 ms 39776 KB Output is correct
71 Correct 256 ms 39480 KB Output is correct
72 Correct 227 ms 33508 KB Output is correct
73 Correct 225 ms 35660 KB Output is correct
74 Correct 246 ms 40916 KB Output is correct
75 Correct 270 ms 40780 KB Output is correct