답안 #285485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285485 2020-08-29T07:03:26 Z akobi Mountains (NOI20_mountains) C++
100 / 100
141 ms 16524 KB
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
using namespace std;
ll n,a[300005],id[300005],ans,f1[300005],f2[300005],x;
pair<ll,ll> b[300005];
void upd1(ll u,ll x)
{
    u++;
    while (u<=n)
    {
        f1[u]+=x;
        u+=(u&(-u));
    }
    return;
}
ll get1(ll u)
{
    u++;
    ll res=0;
    u--;
    while (u>0)
    {
        res+=f1[u];
        u-=(u&(-u));
    }
    return res;
}
void upd2(ll u,ll x)
{
    u++;
    while (u<=n)
    {
        f2[u]+=x;
        u+=(u&(-u));
    }
    return;
}
ll get2(ll u)
{
    u++;
    ll res=0;
    u--;
    while (u>0)
    {
        res+=f2[u];
        u-=(u&(-u));
    }
    return res;
}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
        b[i]=mp(a[i],i);
    }
    sort(b,b+n);
    x=0;
    id[b[0].S]=x;
    for (int i=1; i<n; i++)
    {
        if (b[i].F>b[i-1].F)
            x++;
        id[b[i].S]=x;
    }
    for (int i=2; i<n; i++)
        upd2(id[i],1);
    upd1(id[0],1);
    for (int i=1; i<=n-2; i++)
    {
        ans+=get1(id[i])*get2(id[i]);
        upd1(id[i],1);
        upd2(id[i+1],-1);
    }
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 93 ms 16248 KB Output is correct
3 Correct 108 ms 16376 KB Output is correct
4 Correct 97 ms 16524 KB Output is correct
5 Correct 105 ms 16376 KB Output is correct
6 Correct 92 ms 16376 KB Output is correct
7 Correct 94 ms 16376 KB Output is correct
8 Correct 112 ms 16376 KB Output is correct
9 Correct 97 ms 14200 KB Output is correct
10 Correct 95 ms 14200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 10420 KB Output is correct
2 Correct 103 ms 10364 KB Output is correct
3 Correct 98 ms 10488 KB Output is correct
4 Correct 95 ms 10360 KB Output is correct
5 Correct 96 ms 10460 KB Output is correct
6 Correct 96 ms 10452 KB Output is correct
7 Correct 95 ms 10364 KB Output is correct
8 Correct 73 ms 10416 KB Output is correct
9 Correct 72 ms 10368 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 10420 KB Output is correct
2 Correct 103 ms 10364 KB Output is correct
3 Correct 98 ms 10488 KB Output is correct
4 Correct 95 ms 10360 KB Output is correct
5 Correct 96 ms 10460 KB Output is correct
6 Correct 96 ms 10452 KB Output is correct
7 Correct 95 ms 10364 KB Output is correct
8 Correct 73 ms 10416 KB Output is correct
9 Correct 72 ms 10368 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 109 ms 10724 KB Output is correct
12 Correct 110 ms 10636 KB Output is correct
13 Correct 103 ms 10728 KB Output is correct
14 Correct 104 ms 10616 KB Output is correct
15 Correct 111 ms 10616 KB Output is correct
16 Correct 121 ms 10744 KB Output is correct
17 Correct 105 ms 10616 KB Output is correct
18 Correct 86 ms 10616 KB Output is correct
19 Correct 80 ms 10616 KB Output is correct
20 Correct 1 ms 396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 6 ms 1024 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 6 ms 1024 KB Output is correct
15 Correct 5 ms 1024 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 4 ms 1024 KB Output is correct
19 Correct 3 ms 768 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 10420 KB Output is correct
2 Correct 103 ms 10364 KB Output is correct
3 Correct 98 ms 10488 KB Output is correct
4 Correct 95 ms 10360 KB Output is correct
5 Correct 96 ms 10460 KB Output is correct
6 Correct 96 ms 10452 KB Output is correct
7 Correct 95 ms 10364 KB Output is correct
8 Correct 73 ms 10416 KB Output is correct
9 Correct 72 ms 10368 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 109 ms 10724 KB Output is correct
12 Correct 110 ms 10636 KB Output is correct
13 Correct 103 ms 10728 KB Output is correct
14 Correct 104 ms 10616 KB Output is correct
15 Correct 111 ms 10616 KB Output is correct
16 Correct 121 ms 10744 KB Output is correct
17 Correct 105 ms 10616 KB Output is correct
18 Correct 86 ms 10616 KB Output is correct
19 Correct 80 ms 10616 KB Output is correct
20 Correct 1 ms 396 KB Output is correct
21 Correct 97 ms 12920 KB Output is correct
22 Correct 111 ms 13176 KB Output is correct
23 Correct 111 ms 12920 KB Output is correct
24 Correct 99 ms 12920 KB Output is correct
25 Correct 99 ms 12920 KB Output is correct
26 Correct 101 ms 12920 KB Output is correct
27 Correct 105 ms 12960 KB Output is correct
28 Correct 66 ms 12920 KB Output is correct
29 Correct 67 ms 12948 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 93 ms 16248 KB Output is correct
3 Correct 108 ms 16376 KB Output is correct
4 Correct 97 ms 16524 KB Output is correct
5 Correct 105 ms 16376 KB Output is correct
6 Correct 92 ms 16376 KB Output is correct
7 Correct 94 ms 16376 KB Output is correct
8 Correct 112 ms 16376 KB Output is correct
9 Correct 97 ms 14200 KB Output is correct
10 Correct 95 ms 14200 KB Output is correct
11 Correct 95 ms 10420 KB Output is correct
12 Correct 103 ms 10364 KB Output is correct
13 Correct 98 ms 10488 KB Output is correct
14 Correct 95 ms 10360 KB Output is correct
15 Correct 96 ms 10460 KB Output is correct
16 Correct 96 ms 10452 KB Output is correct
17 Correct 95 ms 10364 KB Output is correct
18 Correct 73 ms 10416 KB Output is correct
19 Correct 72 ms 10368 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 109 ms 10724 KB Output is correct
22 Correct 110 ms 10636 KB Output is correct
23 Correct 103 ms 10728 KB Output is correct
24 Correct 104 ms 10616 KB Output is correct
25 Correct 111 ms 10616 KB Output is correct
26 Correct 121 ms 10744 KB Output is correct
27 Correct 105 ms 10616 KB Output is correct
28 Correct 86 ms 10616 KB Output is correct
29 Correct 80 ms 10616 KB Output is correct
30 Correct 1 ms 396 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 5 ms 1024 KB Output is correct
42 Correct 6 ms 1024 KB Output is correct
43 Correct 5 ms 1024 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 5 ms 1024 KB Output is correct
46 Correct 4 ms 1024 KB Output is correct
47 Correct 5 ms 1024 KB Output is correct
48 Correct 4 ms 1024 KB Output is correct
49 Correct 3 ms 768 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 97 ms 12920 KB Output is correct
52 Correct 111 ms 13176 KB Output is correct
53 Correct 111 ms 12920 KB Output is correct
54 Correct 99 ms 12920 KB Output is correct
55 Correct 99 ms 12920 KB Output is correct
56 Correct 101 ms 12920 KB Output is correct
57 Correct 105 ms 12960 KB Output is correct
58 Correct 66 ms 12920 KB Output is correct
59 Correct 67 ms 12948 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 130 ms 16376 KB Output is correct
62 Correct 133 ms 16376 KB Output is correct
63 Correct 130 ms 16376 KB Output is correct
64 Correct 124 ms 16376 KB Output is correct
65 Correct 125 ms 16376 KB Output is correct
66 Correct 137 ms 16316 KB Output is correct
67 Correct 141 ms 16376 KB Output is correct
68 Correct 126 ms 14200 KB Output is correct
69 Correct 101 ms 13560 KB Output is correct
70 Correct 1 ms 384 KB Output is correct