Submission #968482

# Submission time Handle Problem Language Result Execution time Memory
968482 2024-04-23T13:19:33 Z weakweakweak Real Mountains (CCO23_day1problem2) C++17
18 / 25
2423 ms 111336 KB
//我好笨,聽解了
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
const int M = 1e6 + 3, N = M + 20, INF = N * 10;
 
int o[N], n;
vector <int> v[N];
 
struct segmenttree {
    int a[N << 2];
    void build (int l, int r, int id) {
        if (l == r) {
            a[id] = o[l];
            return;
        }
        int mid = (l + r) >> 1;
        build (l, mid, id << 1); build (mid + 1, r, id << 1 | 1);
        a[id] = min(a[id << 1], a[id << 1 | 1]);
    }
    int query (int l, int r, int ql, int qr, int id) {
        if (ql < 1 or qr > n or ql > qr) return INF;
        if (ql <= l and r <= qr) return a[id];
        int mid = (l + r) >> 1, ans = INT_MAX;
        if (ql <= mid) ans = min(ans, query(l, mid, ql, qr, id << 1));
        if (qr > mid)  ans = min(ans, query(mid + 1, r, ql, qr, id << 1 | 1));
        return ans;
    }
    void update (int l, int r, int pos, int val, int id) {
        if (l == r) {
            a[id] = o[pos] = val;
            return;
        }
        int mid = (l + r) >> 1;
        if (pos <= mid) update(l, mid, pos, val, id << 1);
        else update(mid + 1, r, pos, val, id << 1 | 1);
        a[id] = min(a[id << 1], a[id << 1 | 1]);
    }
}seg;
 
 
int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> o[i];
        v[o[i]].push_back(i);
    }
 
    seg.build(1, n, 1);
 
    set<int> st;
    ll ans = 0;
    for (int h = 1; h <= 1000000; h++) {
        for (int x : v[h]) {
            st.insert(x);
            seg.update(1, n, x, INF, 1);
        }
        while (st.size()) {
            int i = *st.begin();
            int left = seg.query(1, n, 1, i - 1, 1),   right = seg.query(1, n, i + 1, n, 1);
            if (left == INF or right == INF) st.erase(i);
            else break;
        }
        while (st.size()) {
            int i = *st.rbegin();
            int left = seg.query(1, n, 1, i - 1, 1),   right = seg.query(1, n, i + 1, n, 1);
            if (left == INF or right == INF) st.erase(i);
            else break;
        }
        if (st.size() == 1) {
            int i = *st.begin();
            int left = seg.query(1, n, 1, i - 1, 1),   right = seg.query(1, n, i + 1, n, 1);
            ans += (left + h + right) % M;
        }
        else if (st.size() >= 2) {
            int il = *st.begin(), ir = *st.rbegin();
            ll left = seg.query(1, n, 1, il - 1, 1),   right = seg.query(1, n, ir + 1, n, 1);
            ll mid = seg.query(1, n, il + 1, ir - 1, 1);
            ll z = min( left + right + h  +  min(left, right) + (h + 1) + h ,
                        left + mid + h + right + mid + h );
            z = min (z,  left + mid + h + h + 1 + right + h);
            ans += z % M;
            ans += (st.size() - 2)  *  (h + h + 1LL + h + 1)  %  M;
        }
        ans %= M;
    }
 
    cout << ans << '\n';
return 0;}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24924 KB Output is correct
2 Correct 9 ms 24920 KB Output is correct
3 Correct 9 ms 24924 KB Output is correct
4 Correct 11 ms 27228 KB Output is correct
5 Correct 11 ms 27472 KB Output is correct
6 Correct 11 ms 27228 KB Output is correct
7 Correct 11 ms 27228 KB Output is correct
8 Correct 11 ms 27228 KB Output is correct
9 Correct 11 ms 27228 KB Output is correct
10 Correct 11 ms 27100 KB Output is correct
11 Correct 12 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24924 KB Output is correct
2 Correct 9 ms 24920 KB Output is correct
3 Correct 9 ms 24924 KB Output is correct
4 Correct 11 ms 27228 KB Output is correct
5 Correct 11 ms 27472 KB Output is correct
6 Correct 11 ms 27228 KB Output is correct
7 Correct 11 ms 27228 KB Output is correct
8 Correct 11 ms 27228 KB Output is correct
9 Correct 11 ms 27228 KB Output is correct
10 Correct 11 ms 27100 KB Output is correct
11 Correct 12 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 13 ms 27228 KB Output is correct
14 Correct 10 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 12 ms 27484 KB Output is correct
17 Correct 11 ms 27488 KB Output is correct
18 Correct 12 ms 27408 KB Output is correct
19 Correct 12 ms 27484 KB Output is correct
20 Correct 12 ms 27340 KB Output is correct
21 Correct 11 ms 27484 KB Output is correct
22 Correct 11 ms 27492 KB Output is correct
23 Correct 12 ms 27484 KB Output is correct
24 Correct 11 ms 27484 KB Output is correct
25 Correct 11 ms 27484 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 13 ms 27612 KB Output is correct
28 Correct 11 ms 27224 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 10 ms 25040 KB Output is correct
31 Correct 9 ms 25176 KB Output is correct
32 Correct 10 ms 24924 KB Output is correct
33 Correct 10 ms 24920 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24924 KB Output is correct
2 Correct 9 ms 24920 KB Output is correct
3 Correct 9 ms 24924 KB Output is correct
4 Correct 11 ms 27228 KB Output is correct
5 Correct 11 ms 27472 KB Output is correct
6 Correct 11 ms 27228 KB Output is correct
7 Correct 11 ms 27228 KB Output is correct
8 Correct 11 ms 27228 KB Output is correct
9 Correct 11 ms 27228 KB Output is correct
10 Correct 11 ms 27100 KB Output is correct
11 Correct 12 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 13 ms 27228 KB Output is correct
14 Correct 10 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 12 ms 27484 KB Output is correct
17 Correct 11 ms 27488 KB Output is correct
18 Correct 12 ms 27408 KB Output is correct
19 Correct 12 ms 27484 KB Output is correct
20 Correct 12 ms 27340 KB Output is correct
21 Correct 11 ms 27484 KB Output is correct
22 Correct 11 ms 27492 KB Output is correct
23 Correct 12 ms 27484 KB Output is correct
24 Correct 11 ms 27484 KB Output is correct
25 Correct 11 ms 27484 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 13 ms 27612 KB Output is correct
28 Correct 11 ms 27224 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 10 ms 25040 KB Output is correct
31 Correct 9 ms 25176 KB Output is correct
32 Correct 10 ms 24924 KB Output is correct
33 Correct 10 ms 24920 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 414 ms 27476 KB Output is correct
36 Correct 384 ms 27476 KB Output is correct
37 Correct 394 ms 27484 KB Output is correct
38 Correct 395 ms 27472 KB Output is correct
39 Correct 387 ms 27404 KB Output is correct
40 Correct 406 ms 27484 KB Output is correct
41 Correct 411 ms 27484 KB Output is correct
42 Correct 456 ms 27480 KB Output is correct
43 Correct 414 ms 27400 KB Output is correct
44 Correct 411 ms 27656 KB Output is correct
45 Correct 424 ms 27476 KB Output is correct
46 Correct 404 ms 27732 KB Output is correct
47 Correct 385 ms 27580 KB Output is correct
48 Correct 392 ms 27436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24924 KB Output is correct
2 Correct 9 ms 24920 KB Output is correct
3 Correct 9 ms 24924 KB Output is correct
4 Correct 11 ms 27228 KB Output is correct
5 Correct 11 ms 27472 KB Output is correct
6 Correct 11 ms 27228 KB Output is correct
7 Correct 11 ms 27228 KB Output is correct
8 Correct 11 ms 27228 KB Output is correct
9 Correct 11 ms 27228 KB Output is correct
10 Correct 11 ms 27100 KB Output is correct
11 Correct 12 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 13 ms 27228 KB Output is correct
14 Correct 10 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 12 ms 27484 KB Output is correct
17 Correct 11 ms 27488 KB Output is correct
18 Correct 12 ms 27408 KB Output is correct
19 Correct 12 ms 27484 KB Output is correct
20 Correct 12 ms 27340 KB Output is correct
21 Correct 11 ms 27484 KB Output is correct
22 Correct 11 ms 27492 KB Output is correct
23 Correct 12 ms 27484 KB Output is correct
24 Correct 11 ms 27484 KB Output is correct
25 Correct 11 ms 27484 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 13 ms 27612 KB Output is correct
28 Correct 11 ms 27224 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 10 ms 25040 KB Output is correct
31 Correct 9 ms 25176 KB Output is correct
32 Correct 10 ms 24924 KB Output is correct
33 Correct 10 ms 24920 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 414 ms 27476 KB Output is correct
36 Correct 384 ms 27476 KB Output is correct
37 Correct 394 ms 27484 KB Output is correct
38 Correct 395 ms 27472 KB Output is correct
39 Correct 387 ms 27404 KB Output is correct
40 Correct 406 ms 27484 KB Output is correct
41 Correct 411 ms 27484 KB Output is correct
42 Correct 456 ms 27480 KB Output is correct
43 Correct 414 ms 27400 KB Output is correct
44 Correct 411 ms 27656 KB Output is correct
45 Correct 424 ms 27476 KB Output is correct
46 Correct 404 ms 27732 KB Output is correct
47 Correct 385 ms 27580 KB Output is correct
48 Correct 392 ms 27436 KB Output is correct
49 Runtime error 23 ms 50520 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24924 KB Output is correct
2 Correct 9 ms 24920 KB Output is correct
3 Correct 9 ms 24924 KB Output is correct
4 Correct 11 ms 27228 KB Output is correct
5 Correct 11 ms 27472 KB Output is correct
6 Correct 11 ms 27228 KB Output is correct
7 Correct 11 ms 27228 KB Output is correct
8 Correct 11 ms 27228 KB Output is correct
9 Correct 11 ms 27228 KB Output is correct
10 Correct 11 ms 27100 KB Output is correct
11 Correct 12 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 13 ms 27228 KB Output is correct
14 Correct 10 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 12 ms 27484 KB Output is correct
17 Correct 11 ms 27488 KB Output is correct
18 Correct 12 ms 27408 KB Output is correct
19 Correct 12 ms 27484 KB Output is correct
20 Correct 12 ms 27340 KB Output is correct
21 Correct 11 ms 27484 KB Output is correct
22 Correct 11 ms 27492 KB Output is correct
23 Correct 12 ms 27484 KB Output is correct
24 Correct 11 ms 27484 KB Output is correct
25 Correct 11 ms 27484 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 13 ms 27612 KB Output is correct
28 Correct 11 ms 27224 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 10 ms 25040 KB Output is correct
31 Correct 9 ms 25176 KB Output is correct
32 Correct 10 ms 24924 KB Output is correct
33 Correct 10 ms 24920 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 1063 ms 92452 KB Output is correct
36 Correct 1078 ms 92476 KB Output is correct
37 Correct 1085 ms 92320 KB Output is correct
38 Correct 1069 ms 92408 KB Output is correct
39 Correct 1038 ms 92452 KB Output is correct
40 Correct 10 ms 24924 KB Output is correct
41 Correct 11 ms 25180 KB Output is correct
42 Correct 616 ms 90396 KB Output is correct
43 Correct 590 ms 90312 KB Output is correct
44 Correct 614 ms 90168 KB Output is correct
45 Correct 545 ms 92384 KB Output is correct
46 Correct 543 ms 92288 KB Output is correct
47 Correct 591 ms 92408 KB Output is correct
48 Correct 614 ms 92532 KB Output is correct
49 Correct 667 ms 92240 KB Output is correct
50 Correct 623 ms 92476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24924 KB Output is correct
2 Correct 9 ms 24920 KB Output is correct
3 Correct 9 ms 24924 KB Output is correct
4 Correct 11 ms 27228 KB Output is correct
5 Correct 11 ms 27472 KB Output is correct
6 Correct 11 ms 27228 KB Output is correct
7 Correct 11 ms 27228 KB Output is correct
8 Correct 11 ms 27228 KB Output is correct
9 Correct 11 ms 27228 KB Output is correct
10 Correct 11 ms 27100 KB Output is correct
11 Correct 12 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 13 ms 27228 KB Output is correct
14 Correct 10 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 12 ms 27484 KB Output is correct
17 Correct 11 ms 27488 KB Output is correct
18 Correct 12 ms 27408 KB Output is correct
19 Correct 12 ms 27484 KB Output is correct
20 Correct 12 ms 27340 KB Output is correct
21 Correct 11 ms 27484 KB Output is correct
22 Correct 11 ms 27492 KB Output is correct
23 Correct 12 ms 27484 KB Output is correct
24 Correct 11 ms 27484 KB Output is correct
25 Correct 11 ms 27484 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 13 ms 27612 KB Output is correct
28 Correct 11 ms 27224 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 10 ms 25040 KB Output is correct
31 Correct 9 ms 25176 KB Output is correct
32 Correct 10 ms 24924 KB Output is correct
33 Correct 10 ms 24920 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 414 ms 27476 KB Output is correct
36 Correct 384 ms 27476 KB Output is correct
37 Correct 394 ms 27484 KB Output is correct
38 Correct 395 ms 27472 KB Output is correct
39 Correct 387 ms 27404 KB Output is correct
40 Correct 406 ms 27484 KB Output is correct
41 Correct 411 ms 27484 KB Output is correct
42 Correct 456 ms 27480 KB Output is correct
43 Correct 414 ms 27400 KB Output is correct
44 Correct 411 ms 27656 KB Output is correct
45 Correct 424 ms 27476 KB Output is correct
46 Correct 404 ms 27732 KB Output is correct
47 Correct 385 ms 27580 KB Output is correct
48 Correct 392 ms 27436 KB Output is correct
49 Correct 1063 ms 92452 KB Output is correct
50 Correct 1078 ms 92476 KB Output is correct
51 Correct 1085 ms 92320 KB Output is correct
52 Correct 1069 ms 92408 KB Output is correct
53 Correct 1038 ms 92452 KB Output is correct
54 Correct 10 ms 24924 KB Output is correct
55 Correct 11 ms 25180 KB Output is correct
56 Correct 616 ms 90396 KB Output is correct
57 Correct 590 ms 90312 KB Output is correct
58 Correct 614 ms 90168 KB Output is correct
59 Correct 545 ms 92384 KB Output is correct
60 Correct 543 ms 92288 KB Output is correct
61 Correct 591 ms 92408 KB Output is correct
62 Correct 614 ms 92532 KB Output is correct
63 Correct 667 ms 92240 KB Output is correct
64 Correct 623 ms 92476 KB Output is correct
65 Correct 2381 ms 111160 KB Output is correct
66 Correct 2418 ms 110652 KB Output is correct
67 Correct 2386 ms 110684 KB Output is correct
68 Correct 2400 ms 110972 KB Output is correct
69 Correct 2423 ms 110864 KB Output is correct
70 Correct 1244 ms 90532 KB Output is correct
71 Correct 1219 ms 90516 KB Output is correct
72 Correct 1263 ms 90316 KB Output is correct
73 Correct 1357 ms 110928 KB Output is correct
74 Correct 1380 ms 110740 KB Output is correct
75 Correct 1430 ms 111336 KB Output is correct
76 Correct 1528 ms 110672 KB Output is correct
77 Correct 1545 ms 110524 KB Output is correct
78 Correct 1669 ms 110556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24924 KB Output is correct
2 Correct 9 ms 24920 KB Output is correct
3 Correct 9 ms 24924 KB Output is correct
4 Correct 11 ms 27228 KB Output is correct
5 Correct 11 ms 27472 KB Output is correct
6 Correct 11 ms 27228 KB Output is correct
7 Correct 11 ms 27228 KB Output is correct
8 Correct 11 ms 27228 KB Output is correct
9 Correct 11 ms 27228 KB Output is correct
10 Correct 11 ms 27100 KB Output is correct
11 Correct 12 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 13 ms 27228 KB Output is correct
14 Correct 10 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 12 ms 27484 KB Output is correct
17 Correct 11 ms 27488 KB Output is correct
18 Correct 12 ms 27408 KB Output is correct
19 Correct 12 ms 27484 KB Output is correct
20 Correct 12 ms 27340 KB Output is correct
21 Correct 11 ms 27484 KB Output is correct
22 Correct 11 ms 27492 KB Output is correct
23 Correct 12 ms 27484 KB Output is correct
24 Correct 11 ms 27484 KB Output is correct
25 Correct 11 ms 27484 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 13 ms 27612 KB Output is correct
28 Correct 11 ms 27224 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 10 ms 25040 KB Output is correct
31 Correct 9 ms 25176 KB Output is correct
32 Correct 10 ms 24924 KB Output is correct
33 Correct 10 ms 24920 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 414 ms 27476 KB Output is correct
36 Correct 384 ms 27476 KB Output is correct
37 Correct 394 ms 27484 KB Output is correct
38 Correct 395 ms 27472 KB Output is correct
39 Correct 387 ms 27404 KB Output is correct
40 Correct 406 ms 27484 KB Output is correct
41 Correct 411 ms 27484 KB Output is correct
42 Correct 456 ms 27480 KB Output is correct
43 Correct 414 ms 27400 KB Output is correct
44 Correct 411 ms 27656 KB Output is correct
45 Correct 424 ms 27476 KB Output is correct
46 Correct 404 ms 27732 KB Output is correct
47 Correct 385 ms 27580 KB Output is correct
48 Correct 392 ms 27436 KB Output is correct
49 Runtime error 23 ms 50520 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -