Submission #339796

# Submission time Handle Problem Language Result Execution time Memory
339796 2020-12-26T08:36:49 Z mihai145 Mountains (NOI20_mountains) C++14
100 / 100
649 ms 27660 KB
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int NMAX = 3e5;

int N;
long long v[NMAX + 5], vv[NMAX + 5];

int k;
unordered_map <long long, int> norm;

int st[NMAX + 5], dr[NMAX + 5];

struct AIB
{
    int n, v[NMAX + 5];

    void Reset(int _n)
    {
        n = _n;
        for(int i = 0; i <= n; i++)
            v[i] = 0;
    }

    int Lsb(int x)
    {
        return x & (-x);
    }

    void Update(int pos, int val)
    {
        for(int i = pos; i <= n; i += Lsb(i))
            v[i] += val;
    }

    int Query(int pos)
    {
        int ans = 0;

        for(int i = pos; i > 0; i -= Lsb(i))
            ans += v[i];

        return ans;
    }
};

AIB aib;

int main()
{
    cin >> N;

    for(int i = 1; i <= N; i++)
    {
        cin >> v[i];
        vv[i] = v[i];
    }

    sort(vv + 1, vv + N + 1);

    for(int i = 2; i <= N; i++)
        if(vv[i] != vv[i - 1])
            norm[vv[i - 1]] = ++k;

    norm[vv[N]] = ++k;

    aib.Reset(N);
    for(int i = 1; i <= N; i++)
    {
        st[i] = aib.Query(norm[v[i]] - 1);
        aib.Update(norm[v[i]], 1);
    }

    aib.Reset(N);
    for(int i = N; i >= 1; i--)
    {
        dr[i] = aib.Query(norm[v[i]] - 1);
        aib.Update(norm[v[i]], 1);
    }

    long long sol = 0LL;
    for(int i = 1; i <= N; i++)
        sol += 1LL * st[i] * dr[i];

    cout << sol << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 512 ms 21980 KB Output is correct
3 Correct 503 ms 27484 KB Output is correct
4 Correct 498 ms 27484 KB Output is correct
5 Correct 493 ms 27612 KB Output is correct
6 Correct 486 ms 27612 KB Output is correct
7 Correct 573 ms 27484 KB Output is correct
8 Correct 531 ms 27484 KB Output is correct
9 Correct 288 ms 21024 KB Output is correct
10 Correct 280 ms 20916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 8556 KB Output is correct
2 Correct 99 ms 8592 KB Output is correct
3 Correct 98 ms 8556 KB Output is correct
4 Correct 101 ms 8684 KB Output is correct
5 Correct 102 ms 8556 KB Output is correct
6 Correct 101 ms 8600 KB Output is correct
7 Correct 98 ms 8556 KB Output is correct
8 Correct 92 ms 8556 KB Output is correct
9 Correct 91 ms 8556 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 8556 KB Output is correct
2 Correct 99 ms 8592 KB Output is correct
3 Correct 98 ms 8556 KB Output is correct
4 Correct 101 ms 8684 KB Output is correct
5 Correct 102 ms 8556 KB Output is correct
6 Correct 101 ms 8600 KB Output is correct
7 Correct 98 ms 8556 KB Output is correct
8 Correct 92 ms 8556 KB Output is correct
9 Correct 91 ms 8556 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 116 ms 8572 KB Output is correct
12 Correct 117 ms 8556 KB Output is correct
13 Correct 115 ms 8812 KB Output is correct
14 Correct 111 ms 8556 KB Output is correct
15 Correct 115 ms 8684 KB Output is correct
16 Correct 114 ms 8560 KB Output is correct
17 Correct 112 ms 8556 KB Output is correct
18 Correct 101 ms 8556 KB Output is correct
19 Correct 108 ms 8556 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 12 ms 1260 KB Output is correct
12 Correct 12 ms 1260 KB Output is correct
13 Correct 12 ms 1260 KB Output is correct
14 Correct 12 ms 1260 KB Output is correct
15 Correct 12 ms 1260 KB Output is correct
16 Correct 12 ms 1260 KB Output is correct
17 Correct 12 ms 1260 KB Output is correct
18 Correct 13 ms 1132 KB Output is correct
19 Correct 5 ms 620 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 8556 KB Output is correct
2 Correct 99 ms 8592 KB Output is correct
3 Correct 98 ms 8556 KB Output is correct
4 Correct 101 ms 8684 KB Output is correct
5 Correct 102 ms 8556 KB Output is correct
6 Correct 101 ms 8600 KB Output is correct
7 Correct 98 ms 8556 KB Output is correct
8 Correct 92 ms 8556 KB Output is correct
9 Correct 91 ms 8556 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 116 ms 8572 KB Output is correct
12 Correct 117 ms 8556 KB Output is correct
13 Correct 115 ms 8812 KB Output is correct
14 Correct 111 ms 8556 KB Output is correct
15 Correct 115 ms 8684 KB Output is correct
16 Correct 114 ms 8560 KB Output is correct
17 Correct 112 ms 8556 KB Output is correct
18 Correct 101 ms 8556 KB Output is correct
19 Correct 108 ms 8556 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 244 ms 12580 KB Output is correct
22 Correct 215 ms 12468 KB Output is correct
23 Correct 225 ms 12608 KB Output is correct
24 Correct 208 ms 12560 KB Output is correct
25 Correct 228 ms 12560 KB Output is correct
26 Correct 229 ms 12560 KB Output is correct
27 Correct 205 ms 12560 KB Output is correct
28 Correct 166 ms 12432 KB Output is correct
29 Correct 139 ms 12692 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 512 ms 21980 KB Output is correct
3 Correct 503 ms 27484 KB Output is correct
4 Correct 498 ms 27484 KB Output is correct
5 Correct 493 ms 27612 KB Output is correct
6 Correct 486 ms 27612 KB Output is correct
7 Correct 573 ms 27484 KB Output is correct
8 Correct 531 ms 27484 KB Output is correct
9 Correct 288 ms 21024 KB Output is correct
10 Correct 280 ms 20916 KB Output is correct
11 Correct 98 ms 8556 KB Output is correct
12 Correct 99 ms 8592 KB Output is correct
13 Correct 98 ms 8556 KB Output is correct
14 Correct 101 ms 8684 KB Output is correct
15 Correct 102 ms 8556 KB Output is correct
16 Correct 101 ms 8600 KB Output is correct
17 Correct 98 ms 8556 KB Output is correct
18 Correct 92 ms 8556 KB Output is correct
19 Correct 91 ms 8556 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 116 ms 8572 KB Output is correct
22 Correct 117 ms 8556 KB Output is correct
23 Correct 115 ms 8812 KB Output is correct
24 Correct 111 ms 8556 KB Output is correct
25 Correct 115 ms 8684 KB Output is correct
26 Correct 114 ms 8560 KB Output is correct
27 Correct 112 ms 8556 KB Output is correct
28 Correct 101 ms 8556 KB Output is correct
29 Correct 108 ms 8556 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 12 ms 1260 KB Output is correct
42 Correct 12 ms 1260 KB Output is correct
43 Correct 12 ms 1260 KB Output is correct
44 Correct 12 ms 1260 KB Output is correct
45 Correct 12 ms 1260 KB Output is correct
46 Correct 12 ms 1260 KB Output is correct
47 Correct 12 ms 1260 KB Output is correct
48 Correct 13 ms 1132 KB Output is correct
49 Correct 5 ms 620 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 244 ms 12580 KB Output is correct
52 Correct 215 ms 12468 KB Output is correct
53 Correct 225 ms 12608 KB Output is correct
54 Correct 208 ms 12560 KB Output is correct
55 Correct 228 ms 12560 KB Output is correct
56 Correct 229 ms 12560 KB Output is correct
57 Correct 205 ms 12560 KB Output is correct
58 Correct 166 ms 12432 KB Output is correct
59 Correct 139 ms 12692 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 602 ms 27660 KB Output is correct
62 Correct 587 ms 27612 KB Output is correct
63 Correct 597 ms 27580 KB Output is correct
64 Correct 605 ms 27612 KB Output is correct
65 Correct 649 ms 27596 KB Output is correct
66 Correct 619 ms 27612 KB Output is correct
67 Correct 620 ms 27612 KB Output is correct
68 Correct 411 ms 21044 KB Output is correct
69 Correct 258 ms 16436 KB Output is correct
70 Correct 1 ms 364 KB Output is correct