답안 #962210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962210 2024-04-13T08:59:43 Z vjudge1 Mountains (NOI20_mountains) C++17
100 / 100
204 ms 21704 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }

const int MAX = 3e5 + 5;
int nArr;
int a[MAX];

struct SegmentTree{
    int n;
    vector<int> f;
    SegmentTree(int _n = 0){
        this -> n = _n;
        f.resize((n << 1));
    }
    void modify(int p, int val){
        for (f[p += n] += val; p > 0; p >>= 1){
            f[p >> 1] = f[p] + f[p ^ 1];
        }
    }
    int query(int l, int r){
        int ans = 0;
        for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1){
            if(l & 1) ans += f[l++];
            if(r & 1) ans += f[--r];
        }
        return ans;
    }
}l, r;
void Whisper(){
    cin >> nArr;
    for (int i = 1; i <= nArr; ++i) cin >> a[i];
    vector<int> compress;
    for (int i = 1; i <= nArr; ++i){
        compress.push_back(a[i]);
    }

    sort(compress.begin(), compress.end());
    compress.resize(unique(compress.begin(), compress.end()) - compress.begin());
    for (int i = 1; i <= nArr; ++i){
        a[i] = lower_bound(compress.begin(), compress.end(), a[i]) - compress.begin() + 1;
    }

    l = SegmentTree(nArr + 1), r = SegmentTree(nArr + 1);
    for (int i = 1; i <= nArr; ++i){
        r.modify(a[i], 1);
    }
    int ans = 0;
    for (int i = 1; i <= nArr; ++i){
        r.modify(a[i], -1);
        int left = l.query(1, a[i] - 1);
        int right = r.query(1, a[i] - 1);
        ans += left * right;
        l.modify(a[i], 1);
    }
    cout << ans;
}


signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 113 ms 20944 KB Output is correct
3 Correct 122 ms 20188 KB Output is correct
4 Correct 139 ms 20056 KB Output is correct
5 Correct 149 ms 20352 KB Output is correct
6 Correct 110 ms 20668 KB Output is correct
7 Correct 124 ms 21092 KB Output is correct
8 Correct 112 ms 20696 KB Output is correct
9 Correct 110 ms 21628 KB Output is correct
10 Correct 96 ms 20680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 15844 KB Output is correct
2 Correct 51 ms 15568 KB Output is correct
3 Correct 35 ms 16748 KB Output is correct
4 Correct 42 ms 16692 KB Output is correct
5 Correct 51 ms 15896 KB Output is correct
6 Correct 34 ms 16068 KB Output is correct
7 Correct 35 ms 16900 KB Output is correct
8 Correct 46 ms 15664 KB Output is correct
9 Correct 30 ms 16100 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 15844 KB Output is correct
2 Correct 51 ms 15568 KB Output is correct
3 Correct 35 ms 16748 KB Output is correct
4 Correct 42 ms 16692 KB Output is correct
5 Correct 51 ms 15896 KB Output is correct
6 Correct 34 ms 16068 KB Output is correct
7 Correct 35 ms 16900 KB Output is correct
8 Correct 46 ms 15664 KB Output is correct
9 Correct 30 ms 16100 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 58 ms 16836 KB Output is correct
12 Correct 64 ms 17208 KB Output is correct
13 Correct 57 ms 16956 KB Output is correct
14 Correct 63 ms 16064 KB Output is correct
15 Correct 77 ms 15456 KB Output is correct
16 Correct 61 ms 15424 KB Output is correct
17 Correct 57 ms 16968 KB Output is correct
18 Correct 52 ms 16284 KB Output is correct
19 Correct 53 ms 15812 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 480 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 480 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 5 ms 1204 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 5 ms 1224 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 5 ms 1116 KB Output is correct
16 Correct 5 ms 1116 KB Output is correct
17 Correct 5 ms 1116 KB Output is correct
18 Correct 4 ms 1196 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 15844 KB Output is correct
2 Correct 51 ms 15568 KB Output is correct
3 Correct 35 ms 16748 KB Output is correct
4 Correct 42 ms 16692 KB Output is correct
5 Correct 51 ms 15896 KB Output is correct
6 Correct 34 ms 16068 KB Output is correct
7 Correct 35 ms 16900 KB Output is correct
8 Correct 46 ms 15664 KB Output is correct
9 Correct 30 ms 16100 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 58 ms 16836 KB Output is correct
12 Correct 64 ms 17208 KB Output is correct
13 Correct 57 ms 16956 KB Output is correct
14 Correct 63 ms 16064 KB Output is correct
15 Correct 77 ms 15456 KB Output is correct
16 Correct 61 ms 15424 KB Output is correct
17 Correct 57 ms 16968 KB Output is correct
18 Correct 52 ms 16284 KB Output is correct
19 Correct 53 ms 15812 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 134 ms 17084 KB Output is correct
22 Correct 136 ms 16824 KB Output is correct
23 Correct 133 ms 17588 KB Output is correct
24 Correct 136 ms 17760 KB Output is correct
25 Correct 136 ms 17496 KB Output is correct
26 Correct 133 ms 17224 KB Output is correct
27 Correct 137 ms 16824 KB Output is correct
28 Correct 75 ms 17808 KB Output is correct
29 Correct 71 ms 17824 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 113 ms 20944 KB Output is correct
3 Correct 122 ms 20188 KB Output is correct
4 Correct 139 ms 20056 KB Output is correct
5 Correct 149 ms 20352 KB Output is correct
6 Correct 110 ms 20668 KB Output is correct
7 Correct 124 ms 21092 KB Output is correct
8 Correct 112 ms 20696 KB Output is correct
9 Correct 110 ms 21628 KB Output is correct
10 Correct 96 ms 20680 KB Output is correct
11 Correct 35 ms 15844 KB Output is correct
12 Correct 51 ms 15568 KB Output is correct
13 Correct 35 ms 16748 KB Output is correct
14 Correct 42 ms 16692 KB Output is correct
15 Correct 51 ms 15896 KB Output is correct
16 Correct 34 ms 16068 KB Output is correct
17 Correct 35 ms 16900 KB Output is correct
18 Correct 46 ms 15664 KB Output is correct
19 Correct 30 ms 16100 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 58 ms 16836 KB Output is correct
22 Correct 64 ms 17208 KB Output is correct
23 Correct 57 ms 16956 KB Output is correct
24 Correct 63 ms 16064 KB Output is correct
25 Correct 77 ms 15456 KB Output is correct
26 Correct 61 ms 15424 KB Output is correct
27 Correct 57 ms 16968 KB Output is correct
28 Correct 52 ms 16284 KB Output is correct
29 Correct 53 ms 15812 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 480 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 5 ms 1204 KB Output is correct
42 Correct 5 ms 1116 KB Output is correct
43 Correct 5 ms 1224 KB Output is correct
44 Correct 5 ms 1116 KB Output is correct
45 Correct 5 ms 1116 KB Output is correct
46 Correct 5 ms 1116 KB Output is correct
47 Correct 5 ms 1116 KB Output is correct
48 Correct 4 ms 1196 KB Output is correct
49 Correct 3 ms 1116 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 134 ms 17084 KB Output is correct
52 Correct 136 ms 16824 KB Output is correct
53 Correct 133 ms 17588 KB Output is correct
54 Correct 136 ms 17760 KB Output is correct
55 Correct 136 ms 17496 KB Output is correct
56 Correct 133 ms 17224 KB Output is correct
57 Correct 137 ms 16824 KB Output is correct
58 Correct 75 ms 17808 KB Output is correct
59 Correct 71 ms 17824 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 169 ms 21704 KB Output is correct
62 Correct 172 ms 20384 KB Output is correct
63 Correct 201 ms 21392 KB Output is correct
64 Correct 169 ms 21500 KB Output is correct
65 Correct 198 ms 21588 KB Output is correct
66 Correct 204 ms 20568 KB Output is correct
67 Correct 185 ms 21088 KB Output is correct
68 Correct 157 ms 20256 KB Output is correct
69 Correct 141 ms 17088 KB Output is correct
70 Correct 0 ms 344 KB Output is correct