답안 #1087902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087902 2024-09-13T11:30:13 Z vuavisao Mountains (NOI20_mountains) C++14
100 / 100
121 ms 7064 KB
#include <bits/stdc++.h>
using namespace std;

const int N = (int) 3e5 + 10;

int n;
long long a[N];

int L[N], R[N];
int tree[N];

void Update(int idx, int val) {
	for( ; idx <= n; idx += (idx & - idx)) tree[idx] += val;
}

int Query(int idx) {
	int res = 0;
	for( ; idx > 0; idx -= (idx & - idx)) res += tree[idx];
	return res;
}

void compress() {
	vector<long long> Pos = {};
	for (int i = 1; i <= n; ++ i) {
		Pos.push_back(a[i]);
	}
	
	sort(Pos.begin(), Pos.end());
	Pos.resize(unique(Pos.begin(), Pos.end()) - Pos.begin());

	for (int i = 1; i <= n; ++ i) {
		a[i] = lower_bound(Pos.begin(), Pos.end(), a[i]) - Pos.begin() + 1;
	}
}

void calc(int cnt[]) {
	for (int i = 0; i <= n; ++ i) tree[i] = 0;
	for (int i = 1; i <= n; ++ i) {
		cnt[i] = Query(a[i]);
		Update(a[i] + 1, 1);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; ++ i) cin >> a[i];
	compress();
	calc(L);
	reverse(a + 1, a + 1 + n);
	calc(R);
	long long res = 0;
	for (int i = 1; i <= n; ++ i) res += 1ll * L[i] * R[n - i + 1];
	cout << res;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 60 ms 6932 KB Output is correct
3 Correct 59 ms 6864 KB Output is correct
4 Correct 60 ms 6940 KB Output is correct
5 Correct 62 ms 6864 KB Output is correct
6 Correct 60 ms 6856 KB Output is correct
7 Correct 59 ms 6868 KB Output is correct
8 Correct 59 ms 6860 KB Output is correct
9 Correct 59 ms 6856 KB Output is correct
10 Correct 60 ms 6864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 6868 KB Output is correct
2 Correct 52 ms 6992 KB Output is correct
3 Correct 44 ms 7048 KB Output is correct
4 Correct 42 ms 6864 KB Output is correct
5 Correct 43 ms 6860 KB Output is correct
6 Correct 46 ms 7012 KB Output is correct
7 Correct 39 ms 6868 KB Output is correct
8 Correct 37 ms 6856 KB Output is correct
9 Correct 36 ms 6864 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 6868 KB Output is correct
2 Correct 52 ms 6992 KB Output is correct
3 Correct 44 ms 7048 KB Output is correct
4 Correct 42 ms 6864 KB Output is correct
5 Correct 43 ms 6860 KB Output is correct
6 Correct 46 ms 7012 KB Output is correct
7 Correct 39 ms 6868 KB Output is correct
8 Correct 37 ms 6856 KB Output is correct
9 Correct 36 ms 6864 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 55 ms 7064 KB Output is correct
12 Correct 47 ms 6864 KB Output is correct
13 Correct 51 ms 7028 KB Output is correct
14 Correct 48 ms 6868 KB Output is correct
15 Correct 49 ms 6864 KB Output is correct
16 Correct 50 ms 6868 KB Output is correct
17 Correct 49 ms 6864 KB Output is correct
18 Correct 33 ms 6868 KB Output is correct
19 Correct 33 ms 6864 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 3 ms 780 KB Output is correct
12 Correct 4 ms 780 KB Output is correct
13 Correct 3 ms 780 KB Output is correct
14 Correct 3 ms 780 KB Output is correct
15 Correct 3 ms 780 KB Output is correct
16 Correct 3 ms 652 KB Output is correct
17 Correct 3 ms 776 KB Output is correct
18 Correct 3 ms 780 KB Output is correct
19 Correct 2 ms 780 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 6868 KB Output is correct
2 Correct 52 ms 6992 KB Output is correct
3 Correct 44 ms 7048 KB Output is correct
4 Correct 42 ms 6864 KB Output is correct
5 Correct 43 ms 6860 KB Output is correct
6 Correct 46 ms 7012 KB Output is correct
7 Correct 39 ms 6868 KB Output is correct
8 Correct 37 ms 6856 KB Output is correct
9 Correct 36 ms 6864 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 55 ms 7064 KB Output is correct
12 Correct 47 ms 6864 KB Output is correct
13 Correct 51 ms 7028 KB Output is correct
14 Correct 48 ms 6868 KB Output is correct
15 Correct 49 ms 6864 KB Output is correct
16 Correct 50 ms 6868 KB Output is correct
17 Correct 49 ms 6864 KB Output is correct
18 Correct 33 ms 6868 KB Output is correct
19 Correct 33 ms 6864 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 92 ms 6868 KB Output is correct
22 Correct 98 ms 6868 KB Output is correct
23 Correct 93 ms 6864 KB Output is correct
24 Correct 95 ms 6868 KB Output is correct
25 Correct 97 ms 6864 KB Output is correct
26 Correct 93 ms 6868 KB Output is correct
27 Correct 92 ms 6864 KB Output is correct
28 Correct 41 ms 6868 KB Output is correct
29 Correct 43 ms 6904 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 60 ms 6932 KB Output is correct
3 Correct 59 ms 6864 KB Output is correct
4 Correct 60 ms 6940 KB Output is correct
5 Correct 62 ms 6864 KB Output is correct
6 Correct 60 ms 6856 KB Output is correct
7 Correct 59 ms 6868 KB Output is correct
8 Correct 59 ms 6860 KB Output is correct
9 Correct 59 ms 6856 KB Output is correct
10 Correct 60 ms 6864 KB Output is correct
11 Correct 41 ms 6868 KB Output is correct
12 Correct 52 ms 6992 KB Output is correct
13 Correct 44 ms 7048 KB Output is correct
14 Correct 42 ms 6864 KB Output is correct
15 Correct 43 ms 6860 KB Output is correct
16 Correct 46 ms 7012 KB Output is correct
17 Correct 39 ms 6868 KB Output is correct
18 Correct 37 ms 6856 KB Output is correct
19 Correct 36 ms 6864 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 55 ms 7064 KB Output is correct
22 Correct 47 ms 6864 KB Output is correct
23 Correct 51 ms 7028 KB Output is correct
24 Correct 48 ms 6868 KB Output is correct
25 Correct 49 ms 6864 KB Output is correct
26 Correct 50 ms 6868 KB Output is correct
27 Correct 49 ms 6864 KB Output is correct
28 Correct 33 ms 6868 KB Output is correct
29 Correct 33 ms 6864 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 3 ms 780 KB Output is correct
42 Correct 4 ms 780 KB Output is correct
43 Correct 3 ms 780 KB Output is correct
44 Correct 3 ms 780 KB Output is correct
45 Correct 3 ms 780 KB Output is correct
46 Correct 3 ms 652 KB Output is correct
47 Correct 3 ms 776 KB Output is correct
48 Correct 3 ms 780 KB Output is correct
49 Correct 2 ms 780 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 92 ms 6868 KB Output is correct
52 Correct 98 ms 6868 KB Output is correct
53 Correct 93 ms 6864 KB Output is correct
54 Correct 95 ms 6868 KB Output is correct
55 Correct 97 ms 6864 KB Output is correct
56 Correct 93 ms 6868 KB Output is correct
57 Correct 92 ms 6864 KB Output is correct
58 Correct 41 ms 6868 KB Output is correct
59 Correct 43 ms 6904 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 121 ms 6996 KB Output is correct
62 Correct 114 ms 6884 KB Output is correct
63 Correct 115 ms 6856 KB Output is correct
64 Correct 118 ms 6868 KB Output is correct
65 Correct 115 ms 6856 KB Output is correct
66 Correct 115 ms 6856 KB Output is correct
67 Correct 117 ms 6860 KB Output is correct
68 Correct 113 ms 6856 KB Output is correct
69 Correct 93 ms 6880 KB Output is correct
70 Correct 0 ms 348 KB Output is correct