Submission #687570

# Submission time Handle Problem Language Result Execution time Memory
687570 2023-01-26T15:14:44 Z ksjsjsjsjsjsjs Mountains (NOI20_mountains) C++14
100 / 100
302 ms 12496 KB
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ers erase
#define bg begin
#define ed end
#define ft front
#define bk back
#define mtp make_tupl
#define sz(x) (int)(x).size()
#define all(x) (x).bg(), (x).ed()
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define str string
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
struct Fenwick {
    int n;
    vi f;
    Fenwick() {}
    Fenwick(int n) : n(n) { f.resize(n + 1, 0); }
    void upd(int pos, int v) { for (int i = pos; i <= n; i += (i & -i)) f[i] += v; }
    int get(int pos) { int rs = 0; for (int i = pos; i > 0; i -= (i & -i)) rs += f[i]; return rs; }
};
const int N = 3e5 + 5;
int n;
ll h[N];
void compress() {
    vll v;
    FOR(i, 1, n) v.pb(h[i]);
    sort(all(v));
    FOR(i, 1, n) h[i] = lb(all(v), h[i]) - v.bg() + 1;
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen(file".inp", "r", stdin);
//    freopen(file".out", "w", stdout);
    cin >> n;
    FOR(i, 1, n) cin >> h[i];
    compress();
    Fenwick f1(n), f2(n);
    FOR(i, 1, n) f2.upd(h[i], 1);
    ll rs = 0;
    FOR(i, 1, n) {
        f2.upd(h[i], -1);
        rs += 1LL * f1.get(h[i] - 1) * f2.get(h[i] - 1);
        f1.upd(h[i], 1);
    }
    cout << rs;
//    cerr << "\nTime: " << setprecision(5) << fixed << (ldb)clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 114 ms 12392 KB Output is correct
3 Correct 135 ms 12356 KB Output is correct
4 Correct 98 ms 12452 KB Output is correct
5 Correct 97 ms 12440 KB Output is correct
6 Correct 119 ms 12416 KB Output is correct
7 Correct 96 ms 12404 KB Output is correct
8 Correct 94 ms 12444 KB Output is correct
9 Correct 101 ms 12496 KB Output is correct
10 Correct 105 ms 12384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 7404 KB Output is correct
2 Correct 71 ms 7392 KB Output is correct
3 Correct 67 ms 7408 KB Output is correct
4 Correct 71 ms 7492 KB Output is correct
5 Correct 65 ms 7464 KB Output is correct
6 Correct 70 ms 7388 KB Output is correct
7 Correct 66 ms 7392 KB Output is correct
8 Correct 65 ms 7492 KB Output is correct
9 Correct 57 ms 7444 KB Output is correct
10 Correct 1 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 7404 KB Output is correct
2 Correct 71 ms 7392 KB Output is correct
3 Correct 67 ms 7408 KB Output is correct
4 Correct 71 ms 7492 KB Output is correct
5 Correct 65 ms 7464 KB Output is correct
6 Correct 70 ms 7388 KB Output is correct
7 Correct 66 ms 7392 KB Output is correct
8 Correct 65 ms 7492 KB Output is correct
9 Correct 57 ms 7444 KB Output is correct
10 Correct 1 ms 248 KB Output is correct
11 Correct 100 ms 7668 KB Output is correct
12 Correct 98 ms 7748 KB Output is correct
13 Correct 102 ms 7740 KB Output is correct
14 Correct 97 ms 7728 KB Output is correct
15 Correct 104 ms 7676 KB Output is correct
16 Correct 113 ms 7688 KB Output is correct
17 Correct 110 ms 7732 KB Output is correct
18 Correct 48 ms 7744 KB Output is correct
19 Correct 54 ms 7712 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 5 ms 732 KB Output is correct
15 Correct 5 ms 724 KB Output is correct
16 Correct 5 ms 708 KB Output is correct
17 Correct 5 ms 704 KB Output is correct
18 Correct 6 ms 724 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 7404 KB Output is correct
2 Correct 71 ms 7392 KB Output is correct
3 Correct 67 ms 7408 KB Output is correct
4 Correct 71 ms 7492 KB Output is correct
5 Correct 65 ms 7464 KB Output is correct
6 Correct 70 ms 7388 KB Output is correct
7 Correct 66 ms 7392 KB Output is correct
8 Correct 65 ms 7492 KB Output is correct
9 Correct 57 ms 7444 KB Output is correct
10 Correct 1 ms 248 KB Output is correct
11 Correct 100 ms 7668 KB Output is correct
12 Correct 98 ms 7748 KB Output is correct
13 Correct 102 ms 7740 KB Output is correct
14 Correct 97 ms 7728 KB Output is correct
15 Correct 104 ms 7676 KB Output is correct
16 Correct 113 ms 7688 KB Output is correct
17 Correct 110 ms 7732 KB Output is correct
18 Correct 48 ms 7744 KB Output is correct
19 Correct 54 ms 7712 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 149 ms 8632 KB Output is correct
22 Correct 147 ms 8560 KB Output is correct
23 Correct 135 ms 8580 KB Output is correct
24 Correct 128 ms 8604 KB Output is correct
25 Correct 128 ms 8568 KB Output is correct
26 Correct 129 ms 8608 KB Output is correct
27 Correct 128 ms 8544 KB Output is correct
28 Correct 67 ms 8584 KB Output is correct
29 Correct 95 ms 8584 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 114 ms 12392 KB Output is correct
3 Correct 135 ms 12356 KB Output is correct
4 Correct 98 ms 12452 KB Output is correct
5 Correct 97 ms 12440 KB Output is correct
6 Correct 119 ms 12416 KB Output is correct
7 Correct 96 ms 12404 KB Output is correct
8 Correct 94 ms 12444 KB Output is correct
9 Correct 101 ms 12496 KB Output is correct
10 Correct 105 ms 12384 KB Output is correct
11 Correct 74 ms 7404 KB Output is correct
12 Correct 71 ms 7392 KB Output is correct
13 Correct 67 ms 7408 KB Output is correct
14 Correct 71 ms 7492 KB Output is correct
15 Correct 65 ms 7464 KB Output is correct
16 Correct 70 ms 7388 KB Output is correct
17 Correct 66 ms 7392 KB Output is correct
18 Correct 65 ms 7492 KB Output is correct
19 Correct 57 ms 7444 KB Output is correct
20 Correct 1 ms 248 KB Output is correct
21 Correct 100 ms 7668 KB Output is correct
22 Correct 98 ms 7748 KB Output is correct
23 Correct 102 ms 7740 KB Output is correct
24 Correct 97 ms 7728 KB Output is correct
25 Correct 104 ms 7676 KB Output is correct
26 Correct 113 ms 7688 KB Output is correct
27 Correct 110 ms 7732 KB Output is correct
28 Correct 48 ms 7744 KB Output is correct
29 Correct 54 ms 7712 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 5 ms 724 KB Output is correct
42 Correct 5 ms 724 KB Output is correct
43 Correct 5 ms 724 KB Output is correct
44 Correct 5 ms 732 KB Output is correct
45 Correct 5 ms 724 KB Output is correct
46 Correct 5 ms 708 KB Output is correct
47 Correct 5 ms 704 KB Output is correct
48 Correct 6 ms 724 KB Output is correct
49 Correct 3 ms 596 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 149 ms 8632 KB Output is correct
52 Correct 147 ms 8560 KB Output is correct
53 Correct 135 ms 8580 KB Output is correct
54 Correct 128 ms 8604 KB Output is correct
55 Correct 128 ms 8568 KB Output is correct
56 Correct 129 ms 8608 KB Output is correct
57 Correct 128 ms 8544 KB Output is correct
58 Correct 67 ms 8584 KB Output is correct
59 Correct 95 ms 8584 KB Output is correct
60 Correct 1 ms 324 KB Output is correct
61 Correct 152 ms 12396 KB Output is correct
62 Correct 302 ms 12400 KB Output is correct
63 Correct 156 ms 12356 KB Output is correct
64 Correct 180 ms 12400 KB Output is correct
65 Correct 191 ms 12344 KB Output is correct
66 Correct 162 ms 12428 KB Output is correct
67 Correct 157 ms 12344 KB Output is correct
68 Correct 156 ms 12484 KB Output is correct
69 Correct 138 ms 8700 KB Output is correct
70 Correct 1 ms 340 KB Output is correct