Submission #1092023

# Submission time Handle Problem Language Result Execution time Memory
1092023 2024-09-23T00:51:13 Z underwaterkillerwhale Mountains (NOI20_mountains) C++17
100 / 100
72 ms 14164 KB
#include <bits/stdc++.h>
#define ll              long long
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)
#define iter(id, v)     for(auto id : v)
#define fs              first
#define se              second
#define MP              make_pair
#define pb              push_back
#define bit(msk, i)     ((msk >> i) & 1)
#define SZ(v)           (ll)v.size()
#define ALL(v)          v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 3e5 + 2;
const int Mod = 1e9 + 7;
const ll INF = 1e16;
const ll BASE = 137;
const int szBL = 350;

struct fenwick_Tree {
    int m;
    int fen[N];

    void init (int n) {
        m = n;
    }
    void update (int pos, int val) {
        for (; pos <= m; pos += pos & -pos) fen[pos] += val;
    }

    int get (int pos) {
        int res = 0;
        for (;pos > 0; pos -= pos & -pos) res += fen[pos];
        return res;
    }
    int get (int u, int v) {
        if (u > v) return 0;
        return get(v) - get(u - 1);
    }
}BIT;

int n;
ll a[N];
pll b[N];

void solution () {
    cin >> n;
    rep (i, 1, n) cin >> a[i];
    BIT.init(n);
    rep (i, 1, n) b[i] = MP(a[i], i);
    sort (b + 1, b + 1 + n);
    ll res = 0;
    rep (i, 1, n) {
        int L = i, R = i;
        while (R < n && b[R].fs == b[R + 1].fs) ++R;
        rep (j, L, R) {
            int val, pos;
            tie(val, pos) = b[j];
            res += 1LL * BIT.get(1, pos - 1) * BIT.get(pos + 1, n);
        }
        rep (j, L, R) {
            int val, pos;
            tie(val, pos) = b[j];
            BIT.update(pos, 1);
        }
        i = R;
    }
    cout << res <<"\n";

}

#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
//    file("DTREE");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug +5
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 47 ms 13992 KB Output is correct
3 Correct 46 ms 14160 KB Output is correct
4 Correct 45 ms 14164 KB Output is correct
5 Correct 45 ms 14160 KB Output is correct
6 Correct 45 ms 14160 KB Output is correct
7 Correct 45 ms 14036 KB Output is correct
8 Correct 49 ms 14164 KB Output is correct
9 Correct 59 ms 14160 KB Output is correct
10 Correct 48 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 8536 KB Output is correct
2 Correct 47 ms 8540 KB Output is correct
3 Correct 45 ms 8532 KB Output is correct
4 Correct 42 ms 8524 KB Output is correct
5 Correct 47 ms 8532 KB Output is correct
6 Correct 43 ms 8528 KB Output is correct
7 Correct 43 ms 8540 KB Output is correct
8 Correct 30 ms 8528 KB Output is correct
9 Correct 27 ms 8532 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 8536 KB Output is correct
2 Correct 47 ms 8540 KB Output is correct
3 Correct 45 ms 8532 KB Output is correct
4 Correct 42 ms 8524 KB Output is correct
5 Correct 47 ms 8532 KB Output is correct
6 Correct 43 ms 8528 KB Output is correct
7 Correct 43 ms 8540 KB Output is correct
8 Correct 30 ms 8528 KB Output is correct
9 Correct 27 ms 8532 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 51 ms 8528 KB Output is correct
12 Correct 52 ms 8652 KB Output is correct
13 Correct 52 ms 8528 KB Output is correct
14 Correct 51 ms 8656 KB Output is correct
15 Correct 52 ms 8532 KB Output is correct
16 Correct 52 ms 8532 KB Output is correct
17 Correct 52 ms 8532 KB Output is correct
18 Correct 27 ms 8536 KB Output is correct
19 Correct 25 ms 8528 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 3 ms 1112 KB Output is correct
14 Correct 2 ms 852 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 8536 KB Output is correct
2 Correct 47 ms 8540 KB Output is correct
3 Correct 45 ms 8532 KB Output is correct
4 Correct 42 ms 8524 KB Output is correct
5 Correct 47 ms 8532 KB Output is correct
6 Correct 43 ms 8528 KB Output is correct
7 Correct 43 ms 8540 KB Output is correct
8 Correct 30 ms 8528 KB Output is correct
9 Correct 27 ms 8532 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 51 ms 8528 KB Output is correct
12 Correct 52 ms 8652 KB Output is correct
13 Correct 52 ms 8528 KB Output is correct
14 Correct 51 ms 8656 KB Output is correct
15 Correct 52 ms 8532 KB Output is correct
16 Correct 52 ms 8532 KB Output is correct
17 Correct 52 ms 8532 KB Output is correct
18 Correct 27 ms 8536 KB Output is correct
19 Correct 25 ms 8528 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 55 ms 8528 KB Output is correct
22 Correct 60 ms 8656 KB Output is correct
23 Correct 56 ms 8660 KB Output is correct
24 Correct 68 ms 8532 KB Output is correct
25 Correct 56 ms 8528 KB Output is correct
26 Correct 55 ms 8528 KB Output is correct
27 Correct 55 ms 8552 KB Output is correct
28 Correct 40 ms 8528 KB Output is correct
29 Correct 32 ms 8536 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 47 ms 13992 KB Output is correct
3 Correct 46 ms 14160 KB Output is correct
4 Correct 45 ms 14164 KB Output is correct
5 Correct 45 ms 14160 KB Output is correct
6 Correct 45 ms 14160 KB Output is correct
7 Correct 45 ms 14036 KB Output is correct
8 Correct 49 ms 14164 KB Output is correct
9 Correct 59 ms 14160 KB Output is correct
10 Correct 48 ms 14164 KB Output is correct
11 Correct 42 ms 8536 KB Output is correct
12 Correct 47 ms 8540 KB Output is correct
13 Correct 45 ms 8532 KB Output is correct
14 Correct 42 ms 8524 KB Output is correct
15 Correct 47 ms 8532 KB Output is correct
16 Correct 43 ms 8528 KB Output is correct
17 Correct 43 ms 8540 KB Output is correct
18 Correct 30 ms 8528 KB Output is correct
19 Correct 27 ms 8532 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 51 ms 8528 KB Output is correct
22 Correct 52 ms 8652 KB Output is correct
23 Correct 52 ms 8528 KB Output is correct
24 Correct 51 ms 8656 KB Output is correct
25 Correct 52 ms 8532 KB Output is correct
26 Correct 52 ms 8532 KB Output is correct
27 Correct 52 ms 8532 KB Output is correct
28 Correct 27 ms 8536 KB Output is correct
29 Correct 25 ms 8528 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 476 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 3 ms 856 KB Output is correct
42 Correct 3 ms 860 KB Output is correct
43 Correct 3 ms 1112 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 2 ms 736 KB Output is correct
48 Correct 3 ms 856 KB Output is correct
49 Correct 2 ms 600 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 55 ms 8528 KB Output is correct
52 Correct 60 ms 8656 KB Output is correct
53 Correct 56 ms 8660 KB Output is correct
54 Correct 68 ms 8532 KB Output is correct
55 Correct 56 ms 8528 KB Output is correct
56 Correct 55 ms 8528 KB Output is correct
57 Correct 55 ms 8552 KB Output is correct
58 Correct 40 ms 8528 KB Output is correct
59 Correct 32 ms 8536 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 66 ms 14164 KB Output is correct
62 Correct 67 ms 14164 KB Output is correct
63 Correct 66 ms 14164 KB Output is correct
64 Correct 69 ms 14052 KB Output is correct
65 Correct 67 ms 14164 KB Output is correct
66 Correct 66 ms 14160 KB Output is correct
67 Correct 67 ms 14164 KB Output is correct
68 Correct 72 ms 14164 KB Output is correct
69 Correct 57 ms 10324 KB Output is correct
70 Correct 0 ms 348 KB Output is correct