답안 #339795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339795 2020-12-26T08:33:56 Z mihai145 Mountains (NOI20_mountains) C++14
22 / 100
2000 ms 28136 KB
#include <iostream>
#include <set>
#include <map>

using namespace std;

const int NMAX = 3e5;

int N;
long long v[NMAX + 5];
set <long long> xs;

int k;
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];
        xs.insert(v[i]);
    }

    while(!xs.empty())
    {
        int val = *xs.begin();
        xs.erase(xs.begin());
        norm[val] = ++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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Execution timed out 2087 ms 28136 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 6124 KB Output is correct
2 Correct 85 ms 6124 KB Output is correct
3 Correct 82 ms 6124 KB Output is correct
4 Correct 83 ms 6124 KB Output is correct
5 Correct 85 ms 6124 KB Output is correct
6 Correct 82 ms 6124 KB Output is correct
7 Correct 105 ms 6124 KB Output is correct
8 Correct 79 ms 6124 KB Output is correct
9 Correct 81 ms 6124 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 6124 KB Output is correct
2 Correct 85 ms 6124 KB Output is correct
3 Correct 82 ms 6124 KB Output is correct
4 Correct 83 ms 6124 KB Output is correct
5 Correct 85 ms 6124 KB Output is correct
6 Correct 82 ms 6124 KB Output is correct
7 Correct 105 ms 6124 KB Output is correct
8 Correct 79 ms 6124 KB Output is correct
9 Correct 81 ms 6124 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 130 ms 6252 KB Output is correct
12 Correct 129 ms 6252 KB Output is correct
13 Correct 132 ms 6252 KB Output is correct
14 Correct 132 ms 6252 KB Output is correct
15 Correct 129 ms 6252 KB Output is correct
16 Correct 152 ms 6252 KB Output is correct
17 Correct 130 ms 6252 KB Output is correct
18 Correct 112 ms 6256 KB Output is correct
19 Correct 94 ms 6252 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 6124 KB Output is correct
2 Correct 85 ms 6124 KB Output is correct
3 Correct 82 ms 6124 KB Output is correct
4 Correct 83 ms 6124 KB Output is correct
5 Correct 85 ms 6124 KB Output is correct
6 Correct 82 ms 6124 KB Output is correct
7 Correct 105 ms 6124 KB Output is correct
8 Correct 79 ms 6124 KB Output is correct
9 Correct 81 ms 6124 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 130 ms 6252 KB Output is correct
12 Correct 129 ms 6252 KB Output is correct
13 Correct 132 ms 6252 KB Output is correct
14 Correct 132 ms 6252 KB Output is correct
15 Correct 129 ms 6252 KB Output is correct
16 Correct 152 ms 6252 KB Output is correct
17 Correct 130 ms 6252 KB Output is correct
18 Correct 112 ms 6256 KB Output is correct
19 Correct 94 ms 6252 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 575 ms 12976 KB Output is correct
22 Correct 583 ms 13036 KB Output is correct
23 Correct 598 ms 13036 KB Output is correct
24 Correct 650 ms 13164 KB Output is correct
25 Correct 686 ms 13164 KB Output is correct
26 Correct 657 ms 13028 KB Output is correct
27 Correct 685 ms 13036 KB Output is correct
28 Correct 248 ms 12268 KB Output is correct
29 Correct 259 ms 12140 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Execution timed out 2087 ms 28136 KB Time limit exceeded
3 Halted 0 ms 0 KB -