Submission #792600

# Submission time Handle Problem Language Result Execution time Memory
792600 2023-07-25T07:17:21 Z 이성호(#10053) Real Mountains (CCO23_day1problem2) C++17
25 / 25
1563 ms 102924 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define int long long
using namespace std;

const int sz = 1 << 20;
const int inf = 1e18;
const int mod = 1000003;

int N, H[1000005], goal[1000005], tree[1<<21];

int init(int s = 1, int e = N, int node = 1)
{
    if (s == e) return tree[node] = H[s];
    return tree[node] = min(init(s, (s+e)/2, 2*node), init((s+e)/2+1, e, 2*node+1));
}

int query(int l, int r, int s = 1, int e = N, int node = 1)
{
    if (e < l || r < s) return inf;
    if (l <= s && e <= r) return tree[node];
    return min(query(l, r, s, (s+e)/2, 2*node), query(l, r, (s+e)/2+1, e, 2*node+1));
}


int calc(int h, int k, int m1, int m2, int m)
{
    if (k == 1) return (m1 + m2) * (m - h) + (m + h - 1) * (m - h) / 2;
    else return (m1 + m2 + m + 2 * k - 3) * (m - h) + (3 * k - 3) * (((h + m - 1) * (m - h) / 2) % mod);
}
vector<int> cpx;
int nxt(int k)
{
    return *++lower_bound(cpx.begin(), cpx.end(), k);
}
signed main()
{
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> H[i];
    cpx.clear();
    for (int i = 1; i <= N; i++) cpx.push_back(H[i]);
    sort(cpx.begin(), cpx.end());
    cpx.erase(unique(cpx.begin(), cpx.end()), cpx.end());
    int peak = max_element(H+1, H+N+1) - H;
    for (int i = 1; i <= peak; i++) {
        goal[i] = max(goal[i-1], H[i]);
    }
    for (int i = N; i >= peak + 1; i--) {
        goal[i] = max(goal[i+1], H[i]);
    }
    int gl = 1, gr = N;
    vector<pair<int, int>> vc;
    for (int i = 1; i <= N; i++) {
        vc.push_back(make_pair(H[i], i));
    }
    sort(vc.begin(), vc.end());
    int cur = vc[0].first;
    int pv = 0;
    set<int> st;
    int ans = 0;
    init();
    while (pv < N && vc[pv].first == cur) st.insert(vc[pv++].second);
    while (1) {
        while (gl <= gr && goal[gl] == cur) gl++;
        while (gl <= gr && goal[gr] == cur) gr--;
        if (gl > gr) break;
        while (!st.empty() && *st.begin() <= gl) st.erase(st.begin());
        while (!st.empty() && *--st.end() >= gr) st.erase(--st.end());
        if (!st.empty()) {
            int m = nxt(cur);
            int m1 = query(gl, *st.begin() - 1);
            int m2 = query(*--st.end() + 1, gr);
            int k = st.size();
            ans += calc(cur, k, m1, m2, m);
            ans %= mod;
        }
        cur = nxt(cur);
        while (pv < N && vc[pv].first == cur) st.insert(vc[pv++].second);
    }
    cout << (ans % mod + mod) % mod << '\n';
    return 0;
}
# 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 2 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 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 2 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 812 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 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 2 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 812 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 4 ms 852 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 4 ms 852 KB Output is correct
38 Correct 4 ms 868 KB Output is correct
39 Correct 5 ms 852 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 3 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 6 ms 788 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 4 ms 852 KB Output is correct
46 Correct 4 ms 852 KB Output is correct
47 Correct 4 ms 852 KB Output is correct
48 Correct 4 ms 852 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 2 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 812 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 4 ms 852 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 4 ms 852 KB Output is correct
38 Correct 4 ms 868 KB Output is correct
39 Correct 5 ms 852 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 3 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 6 ms 788 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 4 ms 852 KB Output is correct
46 Correct 4 ms 852 KB Output is correct
47 Correct 4 ms 852 KB Output is correct
48 Correct 4 ms 852 KB Output is correct
49 Correct 4 ms 852 KB Output is correct
50 Correct 4 ms 812 KB Output is correct
51 Correct 4 ms 852 KB Output is correct
52 Correct 4 ms 836 KB Output is correct
53 Correct 4 ms 852 KB Output is correct
54 Correct 2 ms 852 KB Output is correct
55 Correct 2 ms 852 KB Output is correct
56 Correct 2 ms 852 KB Output is correct
57 Correct 4 ms 852 KB Output is correct
58 Correct 4 ms 852 KB Output is correct
59 Correct 4 ms 852 KB Output is correct
60 Correct 4 ms 856 KB Output is correct
61 Correct 4 ms 852 KB Output is correct
62 Correct 4 ms 852 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 2 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 812 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 694 ms 102796 KB Output is correct
36 Correct 734 ms 102768 KB Output is correct
37 Correct 718 ms 102756 KB Output is correct
38 Correct 786 ms 102792 KB Output is correct
39 Correct 704 ms 102824 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 454 ms 102820 KB Output is correct
43 Correct 460 ms 102748 KB Output is correct
44 Correct 463 ms 102720 KB Output is correct
45 Correct 392 ms 102776 KB Output is correct
46 Correct 396 ms 102912 KB Output is correct
47 Correct 389 ms 102828 KB Output is correct
48 Correct 453 ms 102776 KB Output is correct
49 Correct 487 ms 102656 KB Output is correct
50 Correct 446 ms 102688 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 2 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 812 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 4 ms 852 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 4 ms 852 KB Output is correct
38 Correct 4 ms 868 KB Output is correct
39 Correct 5 ms 852 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 3 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 6 ms 788 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 4 ms 852 KB Output is correct
46 Correct 4 ms 852 KB Output is correct
47 Correct 4 ms 852 KB Output is correct
48 Correct 4 ms 852 KB Output is correct
49 Correct 694 ms 102796 KB Output is correct
50 Correct 734 ms 102768 KB Output is correct
51 Correct 718 ms 102756 KB Output is correct
52 Correct 786 ms 102792 KB Output is correct
53 Correct 704 ms 102824 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 454 ms 102820 KB Output is correct
57 Correct 460 ms 102748 KB Output is correct
58 Correct 463 ms 102720 KB Output is correct
59 Correct 392 ms 102776 KB Output is correct
60 Correct 396 ms 102912 KB Output is correct
61 Correct 389 ms 102828 KB Output is correct
62 Correct 453 ms 102776 KB Output is correct
63 Correct 487 ms 102656 KB Output is correct
64 Correct 446 ms 102688 KB Output is correct
65 Correct 1388 ms 102740 KB Output is correct
66 Correct 1278 ms 102816 KB Output is correct
67 Correct 1355 ms 102780 KB Output is correct
68 Correct 1322 ms 102848 KB Output is correct
69 Correct 1372 ms 102768 KB Output is correct
70 Correct 458 ms 102724 KB Output is correct
71 Correct 484 ms 102776 KB Output is correct
72 Correct 480 ms 102752 KB Output is correct
73 Correct 877 ms 102804 KB Output is correct
74 Correct 860 ms 102768 KB Output is correct
75 Correct 837 ms 102740 KB Output is correct
76 Correct 842 ms 102624 KB Output is correct
77 Correct 895 ms 102488 KB Output is correct
78 Correct 898 ms 102428 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 2 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 812 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 4 ms 852 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 4 ms 852 KB Output is correct
38 Correct 4 ms 868 KB Output is correct
39 Correct 5 ms 852 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 3 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 6 ms 788 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 4 ms 852 KB Output is correct
46 Correct 4 ms 852 KB Output is correct
47 Correct 4 ms 852 KB Output is correct
48 Correct 4 ms 852 KB Output is correct
49 Correct 4 ms 852 KB Output is correct
50 Correct 4 ms 812 KB Output is correct
51 Correct 4 ms 852 KB Output is correct
52 Correct 4 ms 836 KB Output is correct
53 Correct 4 ms 852 KB Output is correct
54 Correct 2 ms 852 KB Output is correct
55 Correct 2 ms 852 KB Output is correct
56 Correct 2 ms 852 KB Output is correct
57 Correct 4 ms 852 KB Output is correct
58 Correct 4 ms 852 KB Output is correct
59 Correct 4 ms 852 KB Output is correct
60 Correct 4 ms 856 KB Output is correct
61 Correct 4 ms 852 KB Output is correct
62 Correct 4 ms 852 KB Output is correct
63 Correct 694 ms 102796 KB Output is correct
64 Correct 734 ms 102768 KB Output is correct
65 Correct 718 ms 102756 KB Output is correct
66 Correct 786 ms 102792 KB Output is correct
67 Correct 704 ms 102824 KB Output is correct
68 Correct 0 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 454 ms 102820 KB Output is correct
71 Correct 460 ms 102748 KB Output is correct
72 Correct 463 ms 102720 KB Output is correct
73 Correct 392 ms 102776 KB Output is correct
74 Correct 396 ms 102912 KB Output is correct
75 Correct 389 ms 102828 KB Output is correct
76 Correct 453 ms 102776 KB Output is correct
77 Correct 487 ms 102656 KB Output is correct
78 Correct 446 ms 102688 KB Output is correct
79 Correct 1388 ms 102740 KB Output is correct
80 Correct 1278 ms 102816 KB Output is correct
81 Correct 1355 ms 102780 KB Output is correct
82 Correct 1322 ms 102848 KB Output is correct
83 Correct 1372 ms 102768 KB Output is correct
84 Correct 458 ms 102724 KB Output is correct
85 Correct 484 ms 102776 KB Output is correct
86 Correct 480 ms 102752 KB Output is correct
87 Correct 877 ms 102804 KB Output is correct
88 Correct 860 ms 102768 KB Output is correct
89 Correct 837 ms 102740 KB Output is correct
90 Correct 842 ms 102624 KB Output is correct
91 Correct 895 ms 102488 KB Output is correct
92 Correct 898 ms 102428 KB Output is correct
93 Correct 458 ms 102824 KB Output is correct
94 Correct 1092 ms 102924 KB Output is correct
95 Correct 1062 ms 102716 KB Output is correct
96 Correct 1090 ms 102712 KB Output is correct
97 Correct 1042 ms 102476 KB Output is correct
98 Correct 1033 ms 102556 KB Output is correct
99 Correct 1053 ms 102420 KB Output is correct
100 Correct 1533 ms 102812 KB Output is correct
101 Correct 1548 ms 102612 KB Output is correct
102 Correct 1535 ms 102656 KB Output is correct
103 Correct 1563 ms 102696 KB Output is correct
104 Correct 1522 ms 102684 KB Output is correct
105 Correct 450 ms 102768 KB Output is correct
106 Correct 485 ms 102728 KB Output is correct