답안 #968485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968485 2024-04-23T13:25:21 Z weakweakweak Real Mountains (CCO23_day1problem2) C++17
18 / 25
2295 ms 104260 KB
//我好笨,聽解了
/*
x + 
*/
#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 + h + 1 + right + h);
            ans += z % M;
            ans += (st.size() - 2)  *  (h + h + 1LL + h + 1)  %  M;
        }
        ans %= M;
    }
 
    cout << ans << '\n';
return 0;}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 9 ms 24924 KB Output is correct
3 Correct 9 ms 25176 KB Output is correct
4 Correct 12 ms 27360 KB Output is correct
5 Correct 11 ms 27228 KB Output is correct
6 Correct 11 ms 27276 KB Output is correct
7 Correct 11 ms 27224 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 27080 KB Output is correct
11 Correct 11 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 9 ms 24924 KB Output is correct
3 Correct 9 ms 25176 KB Output is correct
4 Correct 12 ms 27360 KB Output is correct
5 Correct 11 ms 27228 KB Output is correct
6 Correct 11 ms 27276 KB Output is correct
7 Correct 11 ms 27224 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 27080 KB Output is correct
11 Correct 11 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 12 ms 27228 KB Output is correct
14 Correct 9 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 11 ms 27480 KB Output is correct
17 Correct 12 ms 27228 KB Output is correct
18 Correct 12 ms 27464 KB Output is correct
19 Correct 11 ms 27224 KB Output is correct
20 Correct 11 ms 27428 KB Output is correct
21 Correct 11 ms 27316 KB Output is correct
22 Correct 11 ms 27480 KB Output is correct
23 Correct 11 ms 27228 KB Output is correct
24 Correct 12 ms 27228 KB Output is correct
25 Correct 12 ms 27224 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 11 ms 27228 KB Output is correct
28 Correct 12 ms 27228 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 9 ms 24924 KB Output is correct
31 Correct 9 ms 24924 KB Output is correct
32 Correct 9 ms 24924 KB Output is correct
33 Correct 9 ms 25052 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 9 ms 24924 KB Output is correct
3 Correct 9 ms 25176 KB Output is correct
4 Correct 12 ms 27360 KB Output is correct
5 Correct 11 ms 27228 KB Output is correct
6 Correct 11 ms 27276 KB Output is correct
7 Correct 11 ms 27224 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 27080 KB Output is correct
11 Correct 11 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 12 ms 27228 KB Output is correct
14 Correct 9 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 11 ms 27480 KB Output is correct
17 Correct 12 ms 27228 KB Output is correct
18 Correct 12 ms 27464 KB Output is correct
19 Correct 11 ms 27224 KB Output is correct
20 Correct 11 ms 27428 KB Output is correct
21 Correct 11 ms 27316 KB Output is correct
22 Correct 11 ms 27480 KB Output is correct
23 Correct 11 ms 27228 KB Output is correct
24 Correct 12 ms 27228 KB Output is correct
25 Correct 12 ms 27224 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 11 ms 27228 KB Output is correct
28 Correct 12 ms 27228 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 9 ms 24924 KB Output is correct
31 Correct 9 ms 24924 KB Output is correct
32 Correct 9 ms 24924 KB Output is correct
33 Correct 9 ms 25052 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 380 ms 27744 KB Output is correct
36 Correct 362 ms 27628 KB Output is correct
37 Correct 380 ms 27400 KB Output is correct
38 Correct 359 ms 27524 KB Output is correct
39 Correct 361 ms 27732 KB Output is correct
40 Correct 362 ms 27452 KB Output is correct
41 Correct 375 ms 27228 KB Output is correct
42 Correct 371 ms 27456 KB Output is correct
43 Correct 409 ms 27364 KB Output is correct
44 Correct 388 ms 27516 KB Output is correct
45 Correct 388 ms 27372 KB Output is correct
46 Correct 368 ms 27360 KB Output is correct
47 Correct 365 ms 27488 KB Output is correct
48 Correct 366 ms 27364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 9 ms 24924 KB Output is correct
3 Correct 9 ms 25176 KB Output is correct
4 Correct 12 ms 27360 KB Output is correct
5 Correct 11 ms 27228 KB Output is correct
6 Correct 11 ms 27276 KB Output is correct
7 Correct 11 ms 27224 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 27080 KB Output is correct
11 Correct 11 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 12 ms 27228 KB Output is correct
14 Correct 9 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 11 ms 27480 KB Output is correct
17 Correct 12 ms 27228 KB Output is correct
18 Correct 12 ms 27464 KB Output is correct
19 Correct 11 ms 27224 KB Output is correct
20 Correct 11 ms 27428 KB Output is correct
21 Correct 11 ms 27316 KB Output is correct
22 Correct 11 ms 27480 KB Output is correct
23 Correct 11 ms 27228 KB Output is correct
24 Correct 12 ms 27228 KB Output is correct
25 Correct 12 ms 27224 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 11 ms 27228 KB Output is correct
28 Correct 12 ms 27228 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 9 ms 24924 KB Output is correct
31 Correct 9 ms 24924 KB Output is correct
32 Correct 9 ms 24924 KB Output is correct
33 Correct 9 ms 25052 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 380 ms 27744 KB Output is correct
36 Correct 362 ms 27628 KB Output is correct
37 Correct 380 ms 27400 KB Output is correct
38 Correct 359 ms 27524 KB Output is correct
39 Correct 361 ms 27732 KB Output is correct
40 Correct 362 ms 27452 KB Output is correct
41 Correct 375 ms 27228 KB Output is correct
42 Correct 371 ms 27456 KB Output is correct
43 Correct 409 ms 27364 KB Output is correct
44 Correct 388 ms 27516 KB Output is correct
45 Correct 388 ms 27372 KB Output is correct
46 Correct 368 ms 27360 KB Output is correct
47 Correct 365 ms 27488 KB Output is correct
48 Correct 366 ms 27364 KB Output is correct
49 Runtime error 24 ms 50520 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 9 ms 24924 KB Output is correct
3 Correct 9 ms 25176 KB Output is correct
4 Correct 12 ms 27360 KB Output is correct
5 Correct 11 ms 27228 KB Output is correct
6 Correct 11 ms 27276 KB Output is correct
7 Correct 11 ms 27224 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 27080 KB Output is correct
11 Correct 11 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 12 ms 27228 KB Output is correct
14 Correct 9 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 11 ms 27480 KB Output is correct
17 Correct 12 ms 27228 KB Output is correct
18 Correct 12 ms 27464 KB Output is correct
19 Correct 11 ms 27224 KB Output is correct
20 Correct 11 ms 27428 KB Output is correct
21 Correct 11 ms 27316 KB Output is correct
22 Correct 11 ms 27480 KB Output is correct
23 Correct 11 ms 27228 KB Output is correct
24 Correct 12 ms 27228 KB Output is correct
25 Correct 12 ms 27224 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 11 ms 27228 KB Output is correct
28 Correct 12 ms 27228 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 9 ms 24924 KB Output is correct
31 Correct 9 ms 24924 KB Output is correct
32 Correct 9 ms 24924 KB Output is correct
33 Correct 9 ms 25052 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 1044 ms 89680 KB Output is correct
36 Correct 1062 ms 89700 KB Output is correct
37 Correct 1101 ms 89804 KB Output is correct
38 Correct 1048 ms 89680 KB Output is correct
39 Correct 1075 ms 89808 KB Output is correct
40 Correct 9 ms 24924 KB Output is correct
41 Correct 9 ms 24920 KB Output is correct
42 Correct 606 ms 88404 KB Output is correct
43 Correct 573 ms 88260 KB Output is correct
44 Correct 611 ms 88240 KB Output is correct
45 Correct 530 ms 89940 KB Output is correct
46 Correct 525 ms 89388 KB Output is correct
47 Correct 532 ms 89428 KB Output is correct
48 Correct 619 ms 89940 KB Output is correct
49 Correct 631 ms 89592 KB Output is correct
50 Correct 633 ms 89428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 9 ms 24924 KB Output is correct
3 Correct 9 ms 25176 KB Output is correct
4 Correct 12 ms 27360 KB Output is correct
5 Correct 11 ms 27228 KB Output is correct
6 Correct 11 ms 27276 KB Output is correct
7 Correct 11 ms 27224 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 27080 KB Output is correct
11 Correct 11 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 12 ms 27228 KB Output is correct
14 Correct 9 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 11 ms 27480 KB Output is correct
17 Correct 12 ms 27228 KB Output is correct
18 Correct 12 ms 27464 KB Output is correct
19 Correct 11 ms 27224 KB Output is correct
20 Correct 11 ms 27428 KB Output is correct
21 Correct 11 ms 27316 KB Output is correct
22 Correct 11 ms 27480 KB Output is correct
23 Correct 11 ms 27228 KB Output is correct
24 Correct 12 ms 27228 KB Output is correct
25 Correct 12 ms 27224 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 11 ms 27228 KB Output is correct
28 Correct 12 ms 27228 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 9 ms 24924 KB Output is correct
31 Correct 9 ms 24924 KB Output is correct
32 Correct 9 ms 24924 KB Output is correct
33 Correct 9 ms 25052 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 380 ms 27744 KB Output is correct
36 Correct 362 ms 27628 KB Output is correct
37 Correct 380 ms 27400 KB Output is correct
38 Correct 359 ms 27524 KB Output is correct
39 Correct 361 ms 27732 KB Output is correct
40 Correct 362 ms 27452 KB Output is correct
41 Correct 375 ms 27228 KB Output is correct
42 Correct 371 ms 27456 KB Output is correct
43 Correct 409 ms 27364 KB Output is correct
44 Correct 388 ms 27516 KB Output is correct
45 Correct 388 ms 27372 KB Output is correct
46 Correct 368 ms 27360 KB Output is correct
47 Correct 365 ms 27488 KB Output is correct
48 Correct 366 ms 27364 KB Output is correct
49 Correct 1044 ms 89680 KB Output is correct
50 Correct 1062 ms 89700 KB Output is correct
51 Correct 1101 ms 89804 KB Output is correct
52 Correct 1048 ms 89680 KB Output is correct
53 Correct 1075 ms 89808 KB Output is correct
54 Correct 9 ms 24924 KB Output is correct
55 Correct 9 ms 24920 KB Output is correct
56 Correct 606 ms 88404 KB Output is correct
57 Correct 573 ms 88260 KB Output is correct
58 Correct 611 ms 88240 KB Output is correct
59 Correct 530 ms 89940 KB Output is correct
60 Correct 525 ms 89388 KB Output is correct
61 Correct 532 ms 89428 KB Output is correct
62 Correct 619 ms 89940 KB Output is correct
63 Correct 631 ms 89592 KB Output is correct
64 Correct 633 ms 89428 KB Output is correct
65 Correct 2295 ms 104244 KB Output is correct
66 Correct 2253 ms 104024 KB Output is correct
67 Correct 2254 ms 103964 KB Output is correct
68 Correct 2290 ms 104044 KB Output is correct
69 Correct 2187 ms 103968 KB Output is correct
70 Correct 1172 ms 88260 KB Output is correct
71 Correct 1155 ms 88360 KB Output is correct
72 Correct 1153 ms 88044 KB Output is correct
73 Correct 1301 ms 104156 KB Output is correct
74 Correct 1359 ms 104172 KB Output is correct
75 Correct 1308 ms 104260 KB Output is correct
76 Correct 1459 ms 103984 KB Output is correct
77 Correct 1450 ms 103820 KB Output is correct
78 Correct 1512 ms 103964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 9 ms 24924 KB Output is correct
3 Correct 9 ms 25176 KB Output is correct
4 Correct 12 ms 27360 KB Output is correct
5 Correct 11 ms 27228 KB Output is correct
6 Correct 11 ms 27276 KB Output is correct
7 Correct 11 ms 27224 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 27080 KB Output is correct
11 Correct 11 ms 27228 KB Output is correct
12 Correct 11 ms 27228 KB Output is correct
13 Correct 12 ms 27228 KB Output is correct
14 Correct 9 ms 24924 KB Output is correct
15 Correct 9 ms 24924 KB Output is correct
16 Correct 11 ms 27480 KB Output is correct
17 Correct 12 ms 27228 KB Output is correct
18 Correct 12 ms 27464 KB Output is correct
19 Correct 11 ms 27224 KB Output is correct
20 Correct 11 ms 27428 KB Output is correct
21 Correct 11 ms 27316 KB Output is correct
22 Correct 11 ms 27480 KB Output is correct
23 Correct 11 ms 27228 KB Output is correct
24 Correct 12 ms 27228 KB Output is correct
25 Correct 12 ms 27224 KB Output is correct
26 Correct 12 ms 27228 KB Output is correct
27 Correct 11 ms 27228 KB Output is correct
28 Correct 12 ms 27228 KB Output is correct
29 Correct 9 ms 24924 KB Output is correct
30 Correct 9 ms 24924 KB Output is correct
31 Correct 9 ms 24924 KB Output is correct
32 Correct 9 ms 24924 KB Output is correct
33 Correct 9 ms 25052 KB Output is correct
34 Correct 10 ms 24924 KB Output is correct
35 Correct 380 ms 27744 KB Output is correct
36 Correct 362 ms 27628 KB Output is correct
37 Correct 380 ms 27400 KB Output is correct
38 Correct 359 ms 27524 KB Output is correct
39 Correct 361 ms 27732 KB Output is correct
40 Correct 362 ms 27452 KB Output is correct
41 Correct 375 ms 27228 KB Output is correct
42 Correct 371 ms 27456 KB Output is correct
43 Correct 409 ms 27364 KB Output is correct
44 Correct 388 ms 27516 KB Output is correct
45 Correct 388 ms 27372 KB Output is correct
46 Correct 368 ms 27360 KB Output is correct
47 Correct 365 ms 27488 KB Output is correct
48 Correct 366 ms 27364 KB Output is correct
49 Runtime error 24 ms 50520 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -