답안 #439016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439016 2021-06-29T04:40:00 Z Hausdorf Mountains (NOI20_mountains) C++17
100 / 100
897 ms 27460 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define itn int
#define fi first
#define se second
#pragma optimizatiob ("O3")
#pragma GCC target ("avx2")
#pragma optimization ("unroll_loops")

struct segtree {
    vector<int> tree;
    vector<int> promise;
    segtree (int n) {
        tree.resize(4 * n, 0);
        promise.resize(4 * n, 0);
    }
    void push (int id, int l, int r) {
        tree[id] += (r - l) * promise[id];
        if (r - l > 1) {
            promise[2 * id + 1] += promise[id];
            promise[2 * id + 2] += promise[id];
        }
        promise[id] = 0;
    }
    void upd (int id, int l, int r, int lq, int rq, int up) {
        push(id, l, r);
        if (l >= lq && r <= rq) {
            promise[id] += up;
            push(id, l, r);
            return;
        }
        if (l >= rq || r <= lq) {
            return;
        }
        int m = (r + l) / 2;
        upd(2 * id + 1, l, m, lq, rq, up);
        upd(2 * id + 2, m, r, lq, rq, up);
        tree[id] = tree[id * 2 + 1] + tree[id * 2 + 2];
    }
    int get (int id, int l, int r, int q) {
        push(id, l, r);
        if (r - l == 1 && l == q) {
            return tree[id];
        }
        if (q >= r || q < l)
            return 0;
        int m = (r + l) / 2;
        return get(id * 2 + 1, l, m, q) + get(id * 2 + 2, m, r, q);
    }
};

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector<pair<ll, int>> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i].fi;
        h[i].se = i;
    }
    sort(h.begin(), h.end());
    vector<int> lessleft(n, 0), lessright(n, 0), been(n, 0);
    segtree templeft(n), tempright(n);
    for (int i = 1;  i < n; ++i) {
        if (h[i].fi == h[i - 1].fi) {
            been[i] = 1 + been[i - 1];
        }
    }
    //for (int i = n - 2; i > -1; --i) {
    //    if (a[i] == a[i + 1])
    //        been[i] = been[i + 1];
    //}
    for (int i = 0; i < n; ++i) {
        int ind = h[i].se;
        lessleft[ind] = templeft.get(0, 0, n, ind) - been[i];
        lessright[ind] = tempright.get(0, 0, n, ind);
        //cout << lessleft[ind] << ' ' << lessright[ind] << '\n';
        if (ind == 0) {
            templeft.upd(0, 0, n, ind + 1, n, 1);
        }
        else if (ind == n - 1) {
            tempright.upd(0, 0, n, 0, ind, 1);
        }
        else {
            templeft.upd(0, 0, n, ind + 1, n, 1);
            tempright.upd(0, 0, n, 0, ind, 1);
        }
    }
    /*lessleft[0] = lessright[n - 1] = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            if (h[j] < h[i])
                ++lessleft[i];
        }
    }
    for (int i = n - 2; i >= 0; --i) {
        for (int j = n - 1; j > i; --j) {
            if (h[j] < h[i])
                ++lessright[i];
        }
    }*/
    ll ans = 0;
    for (int i = 0; i < n; ++i)
        ans += 1ll * lessleft[i] * lessright[i];
    cout << ans;
}

Compilation message

Mountains.cpp:8: warning: ignoring '#pragma optimizatiob ' [-Wunknown-pragmas]
    8 | #pragma optimizatiob ("O3")
      | 
Mountains.cpp:10: warning: ignoring '#pragma optimization ' [-Wunknown-pragmas]
   10 | #pragma optimization ("unroll_loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 508 ms 27312 KB Output is correct
3 Correct 522 ms 27312 KB Output is correct
4 Correct 562 ms 27312 KB Output is correct
5 Correct 563 ms 27316 KB Output is correct
6 Correct 527 ms 27312 KB Output is correct
7 Correct 512 ms 27316 KB Output is correct
8 Correct 513 ms 27204 KB Output is correct
9 Correct 524 ms 27284 KB Output is correct
10 Correct 517 ms 27204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 508 ms 27400 KB Output is correct
2 Correct 512 ms 27316 KB Output is correct
3 Correct 504 ms 27460 KB Output is correct
4 Correct 497 ms 27332 KB Output is correct
5 Correct 508 ms 27312 KB Output is correct
6 Correct 497 ms 27336 KB Output is correct
7 Correct 505 ms 27308 KB Output is correct
8 Correct 467 ms 27412 KB Output is correct
9 Correct 476 ms 27312 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 508 ms 27400 KB Output is correct
2 Correct 512 ms 27316 KB Output is correct
3 Correct 504 ms 27460 KB Output is correct
4 Correct 497 ms 27332 KB Output is correct
5 Correct 508 ms 27312 KB Output is correct
6 Correct 497 ms 27336 KB Output is correct
7 Correct 505 ms 27308 KB Output is correct
8 Correct 467 ms 27412 KB Output is correct
9 Correct 476 ms 27312 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 681 ms 27308 KB Output is correct
12 Correct 729 ms 27336 KB Output is correct
13 Correct 686 ms 27332 KB Output is correct
14 Correct 706 ms 27284 KB Output is correct
15 Correct 706 ms 27316 KB Output is correct
16 Correct 712 ms 27332 KB Output is correct
17 Correct 739 ms 27412 KB Output is correct
18 Correct 487 ms 27320 KB Output is correct
19 Correct 476 ms 27284 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 15 ms 1236 KB Output is correct
12 Correct 16 ms 1240 KB Output is correct
13 Correct 15 ms 1244 KB Output is correct
14 Correct 15 ms 1236 KB Output is correct
15 Correct 15 ms 1228 KB Output is correct
16 Correct 16 ms 1244 KB Output is correct
17 Correct 16 ms 1236 KB Output is correct
18 Correct 16 ms 1240 KB Output is correct
19 Correct 14 ms 1244 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 508 ms 27400 KB Output is correct
2 Correct 512 ms 27316 KB Output is correct
3 Correct 504 ms 27460 KB Output is correct
4 Correct 497 ms 27332 KB Output is correct
5 Correct 508 ms 27312 KB Output is correct
6 Correct 497 ms 27336 KB Output is correct
7 Correct 505 ms 27308 KB Output is correct
8 Correct 467 ms 27412 KB Output is correct
9 Correct 476 ms 27312 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 681 ms 27308 KB Output is correct
12 Correct 729 ms 27336 KB Output is correct
13 Correct 686 ms 27332 KB Output is correct
14 Correct 706 ms 27284 KB Output is correct
15 Correct 706 ms 27316 KB Output is correct
16 Correct 712 ms 27332 KB Output is correct
17 Correct 739 ms 27412 KB Output is correct
18 Correct 487 ms 27320 KB Output is correct
19 Correct 476 ms 27284 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 819 ms 27308 KB Output is correct
22 Correct 798 ms 27332 KB Output is correct
23 Correct 837 ms 27312 KB Output is correct
24 Correct 790 ms 27408 KB Output is correct
25 Correct 791 ms 27312 KB Output is correct
26 Correct 822 ms 27204 KB Output is correct
27 Correct 823 ms 27312 KB Output is correct
28 Correct 479 ms 27292 KB Output is correct
29 Correct 481 ms 27308 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 508 ms 27312 KB Output is correct
3 Correct 522 ms 27312 KB Output is correct
4 Correct 562 ms 27312 KB Output is correct
5 Correct 563 ms 27316 KB Output is correct
6 Correct 527 ms 27312 KB Output is correct
7 Correct 512 ms 27316 KB Output is correct
8 Correct 513 ms 27204 KB Output is correct
9 Correct 524 ms 27284 KB Output is correct
10 Correct 517 ms 27204 KB Output is correct
11 Correct 508 ms 27400 KB Output is correct
12 Correct 512 ms 27316 KB Output is correct
13 Correct 504 ms 27460 KB Output is correct
14 Correct 497 ms 27332 KB Output is correct
15 Correct 508 ms 27312 KB Output is correct
16 Correct 497 ms 27336 KB Output is correct
17 Correct 505 ms 27308 KB Output is correct
18 Correct 467 ms 27412 KB Output is correct
19 Correct 476 ms 27312 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 681 ms 27308 KB Output is correct
22 Correct 729 ms 27336 KB Output is correct
23 Correct 686 ms 27332 KB Output is correct
24 Correct 706 ms 27284 KB Output is correct
25 Correct 706 ms 27316 KB Output is correct
26 Correct 712 ms 27332 KB Output is correct
27 Correct 739 ms 27412 KB Output is correct
28 Correct 487 ms 27320 KB Output is correct
29 Correct 476 ms 27284 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 15 ms 1236 KB Output is correct
42 Correct 16 ms 1240 KB Output is correct
43 Correct 15 ms 1244 KB Output is correct
44 Correct 15 ms 1236 KB Output is correct
45 Correct 15 ms 1228 KB Output is correct
46 Correct 16 ms 1244 KB Output is correct
47 Correct 16 ms 1236 KB Output is correct
48 Correct 16 ms 1240 KB Output is correct
49 Correct 14 ms 1244 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 819 ms 27308 KB Output is correct
52 Correct 798 ms 27332 KB Output is correct
53 Correct 837 ms 27312 KB Output is correct
54 Correct 790 ms 27408 KB Output is correct
55 Correct 791 ms 27312 KB Output is correct
56 Correct 822 ms 27204 KB Output is correct
57 Correct 823 ms 27312 KB Output is correct
58 Correct 479 ms 27292 KB Output is correct
59 Correct 481 ms 27308 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 864 ms 27312 KB Output is correct
62 Correct 836 ms 27312 KB Output is correct
63 Correct 897 ms 27312 KB Output is correct
64 Correct 849 ms 27312 KB Output is correct
65 Correct 832 ms 27308 KB Output is correct
66 Correct 851 ms 27332 KB Output is correct
67 Correct 826 ms 27288 KB Output is correct
68 Correct 870 ms 27312 KB Output is correct
69 Correct 822 ms 27332 KB Output is correct
70 Correct 1 ms 204 KB Output is correct