답안 #285477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285477 2020-08-29T06:53:54 Z wildturtle Mountains (NOI20_mountains) C++14
100 / 100
548 ms 10744 KB
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,A[300005],BITree[400005],ans;
pair <long long,long long> B[300005];
long long getSum(long long index) {
    long long sum = 0;
    index = index + 1; 
    while (index>0) { 
        sum += BITree[index]; 
        index -= index & (-index); 
    } 
    return sum; 
} 
void updateBIT(long long index, long long val) { 
    index = index + 1; 
    while (index <= 300005) { 
        BITree[index] += val; 
        index += index & (-index); 
    } 
} 
int main() {
    cin>>n;
    for(long long i=1;i<=n;i++) {
        cin>>A[i];
        B[i].first=A[i]; B[i].second=i;
    }
    sort(B+1,B+1+n);
    k=1;
    A[B[1].second]=k;
    for(long long i=2;i<=n;i++) {
        if(B[i].first!=B[i-1].first) k++;
        A[B[i].second]=k;
    }
    for(long long i=1;i<=n;i++) {
        B[i].first=getSum(A[i]-1);
        updateBIT(A[i],1);
    }
    for(long long i=1;i<=300005;i++)
    BITree[i]=0;
    for(long long i=n;i>=1;i--) {
        B[i].second=getSum(A[i]-1);
        updateBIT(A[i],1);
    }
    for(long long i=1;i<=n;i++) {
        //cout<<B[i].first<<" "<<B[i].second<<endl;
        ans+=(B[i].first*B[i].second);
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 483 ms 9732 KB Output is correct
3 Correct 478 ms 9852 KB Output is correct
4 Correct 484 ms 9776 KB Output is correct
5 Correct 485 ms 9796 KB Output is correct
6 Correct 491 ms 9848 KB Output is correct
7 Correct 479 ms 9720 KB Output is correct
8 Correct 472 ms 10616 KB Output is correct
9 Correct 489 ms 10524 KB Output is correct
10 Correct 487 ms 10616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 9720 KB Output is correct
2 Correct 156 ms 10232 KB Output is correct
3 Correct 149 ms 10284 KB Output is correct
4 Correct 147 ms 10360 KB Output is correct
5 Correct 158 ms 10232 KB Output is correct
6 Correct 161 ms 10352 KB Output is correct
7 Correct 151 ms 10264 KB Output is correct
8 Correct 144 ms 10304 KB Output is correct
9 Correct 128 ms 10352 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 9720 KB Output is correct
2 Correct 156 ms 10232 KB Output is correct
3 Correct 149 ms 10284 KB Output is correct
4 Correct 147 ms 10360 KB Output is correct
5 Correct 158 ms 10232 KB Output is correct
6 Correct 161 ms 10352 KB Output is correct
7 Correct 151 ms 10264 KB Output is correct
8 Correct 144 ms 10304 KB Output is correct
9 Correct 128 ms 10352 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 169 ms 10572 KB Output is correct
12 Correct 172 ms 10488 KB Output is correct
13 Correct 170 ms 10488 KB Output is correct
14 Correct 171 ms 10488 KB Output is correct
15 Correct 169 ms 10616 KB Output is correct
16 Correct 173 ms 10616 KB Output is correct
17 Correct 183 ms 10492 KB Output is correct
18 Correct 148 ms 10488 KB Output is correct
19 Correct 153 ms 10488 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 18 ms 3072 KB Output is correct
12 Correct 19 ms 3072 KB Output is correct
13 Correct 19 ms 3072 KB Output is correct
14 Correct 20 ms 3200 KB Output is correct
15 Correct 19 ms 3072 KB Output is correct
16 Correct 20 ms 3072 KB Output is correct
17 Correct 19 ms 3072 KB Output is correct
18 Correct 19 ms 3072 KB Output is correct
19 Correct 8 ms 2944 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 9720 KB Output is correct
2 Correct 156 ms 10232 KB Output is correct
3 Correct 149 ms 10284 KB Output is correct
4 Correct 147 ms 10360 KB Output is correct
5 Correct 158 ms 10232 KB Output is correct
6 Correct 161 ms 10352 KB Output is correct
7 Correct 151 ms 10264 KB Output is correct
8 Correct 144 ms 10304 KB Output is correct
9 Correct 128 ms 10352 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 169 ms 10572 KB Output is correct
12 Correct 172 ms 10488 KB Output is correct
13 Correct 170 ms 10488 KB Output is correct
14 Correct 171 ms 10488 KB Output is correct
15 Correct 169 ms 10616 KB Output is correct
16 Correct 173 ms 10616 KB Output is correct
17 Correct 183 ms 10492 KB Output is correct
18 Correct 148 ms 10488 KB Output is correct
19 Correct 153 ms 10488 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 237 ms 10744 KB Output is correct
22 Correct 237 ms 10744 KB Output is correct
23 Correct 232 ms 10616 KB Output is correct
24 Correct 241 ms 10744 KB Output is correct
25 Correct 236 ms 10744 KB Output is correct
26 Correct 229 ms 10616 KB Output is correct
27 Correct 232 ms 10744 KB Output is correct
28 Correct 200 ms 10564 KB Output is correct
29 Correct 202 ms 10616 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 483 ms 9732 KB Output is correct
3 Correct 478 ms 9852 KB Output is correct
4 Correct 484 ms 9776 KB Output is correct
5 Correct 485 ms 9796 KB Output is correct
6 Correct 491 ms 9848 KB Output is correct
7 Correct 479 ms 9720 KB Output is correct
8 Correct 472 ms 10616 KB Output is correct
9 Correct 489 ms 10524 KB Output is correct
10 Correct 487 ms 10616 KB Output is correct
11 Correct 147 ms 9720 KB Output is correct
12 Correct 156 ms 10232 KB Output is correct
13 Correct 149 ms 10284 KB Output is correct
14 Correct 147 ms 10360 KB Output is correct
15 Correct 158 ms 10232 KB Output is correct
16 Correct 161 ms 10352 KB Output is correct
17 Correct 151 ms 10264 KB Output is correct
18 Correct 144 ms 10304 KB Output is correct
19 Correct 128 ms 10352 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 169 ms 10572 KB Output is correct
22 Correct 172 ms 10488 KB Output is correct
23 Correct 170 ms 10488 KB Output is correct
24 Correct 171 ms 10488 KB Output is correct
25 Correct 169 ms 10616 KB Output is correct
26 Correct 173 ms 10616 KB Output is correct
27 Correct 183 ms 10492 KB Output is correct
28 Correct 148 ms 10488 KB Output is correct
29 Correct 153 ms 10488 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 3 ms 2688 KB Output is correct
33 Correct 3 ms 2688 KB Output is correct
34 Correct 3 ms 2688 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
36 Correct 3 ms 2688 KB Output is correct
37 Correct 3 ms 2688 KB Output is correct
38 Correct 3 ms 2688 KB Output is correct
39 Correct 2 ms 2688 KB Output is correct
40 Correct 2 ms 2688 KB Output is correct
41 Correct 18 ms 3072 KB Output is correct
42 Correct 19 ms 3072 KB Output is correct
43 Correct 19 ms 3072 KB Output is correct
44 Correct 20 ms 3200 KB Output is correct
45 Correct 19 ms 3072 KB Output is correct
46 Correct 20 ms 3072 KB Output is correct
47 Correct 19 ms 3072 KB Output is correct
48 Correct 19 ms 3072 KB Output is correct
49 Correct 8 ms 2944 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 237 ms 10744 KB Output is correct
52 Correct 237 ms 10744 KB Output is correct
53 Correct 232 ms 10616 KB Output is correct
54 Correct 241 ms 10744 KB Output is correct
55 Correct 236 ms 10744 KB Output is correct
56 Correct 229 ms 10616 KB Output is correct
57 Correct 232 ms 10744 KB Output is correct
58 Correct 200 ms 10564 KB Output is correct
59 Correct 202 ms 10616 KB Output is correct
60 Correct 2 ms 2688 KB Output is correct
61 Correct 499 ms 10616 KB Output is correct
62 Correct 501 ms 10744 KB Output is correct
63 Correct 505 ms 10616 KB Output is correct
64 Correct 548 ms 10612 KB Output is correct
65 Correct 519 ms 10532 KB Output is correct
66 Correct 530 ms 10592 KB Output is correct
67 Correct 521 ms 10616 KB Output is correct
68 Correct 516 ms 10616 KB Output is correct
69 Correct 245 ms 10616 KB Output is correct
70 Correct 2 ms 2688 KB Output is correct