답안 #676490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676490 2022-12-31T03:38:18 Z penguin133 Mountains (NOI20_mountains) C++17
100 / 100
290 ms 19904 KB
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, int> >pq;
long long ft[300005];
long long in1[300005];
long long in2[300005];
int cnt2 = 1;
int ls(int x){
	return x & -x;
}
int query(int x){
	long long sum = 0;
	for(;x;x -= ls(x)){
		sum += ft[x];
	}
	return sum;
}

void update(int x, int v){
	for(;x<=cnt2;x += ls(x)){
		ft[x] += v;
	}
}
int main(){
	int n;
	cin >> n;
	long long cnt = 0;
	cnt2 = 1;

	pair<long long, int> d[n+1];
	long long c[n+1];
	for(int i=1;i<=n;i++){
		cin >> c[i];
	}
	for(int i = 1; i <= n; i++){
		d[i].first = c[i];
		d[i].second = i;
	}
	sort(d + 1, d + n + 1);
	
	for(int i = 1; i <= n; i++){
		if (i > 1 && d[i].first != d[i-1].first) cnt2++;
		c[d[i].second] = cnt2;
	}
	for(int i=1;i<=n;i++){
		in1[i] = query(c[i] - 1);
		update(c[i], 1);
	}
	fill(ft, ft + n + 1, 0);
	for(int i=n;i>=1;i--){
		in2[i] = query(c[i]-1);
		update(c[i], 1);
	}
	for(int i=0;i<n;i++){
		cnt += in1[i]*in2[i];
	}
	cout << cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 256 ms 19904 KB Output is correct
3 Correct 246 ms 19856 KB Output is correct
4 Correct 243 ms 19860 KB Output is correct
5 Correct 220 ms 19856 KB Output is correct
6 Correct 252 ms 19856 KB Output is correct
7 Correct 231 ms 19864 KB Output is correct
8 Correct 233 ms 19860 KB Output is correct
9 Correct 224 ms 19892 KB Output is correct
10 Correct 236 ms 19864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 14864 KB Output is correct
2 Correct 133 ms 14952 KB Output is correct
3 Correct 86 ms 14960 KB Output is correct
4 Correct 87 ms 14952 KB Output is correct
5 Correct 79 ms 14924 KB Output is correct
6 Correct 136 ms 14872 KB Output is correct
7 Correct 97 ms 14860 KB Output is correct
8 Correct 56 ms 14908 KB Output is correct
9 Correct 60 ms 14880 KB Output is correct
10 Correct 1 ms 216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 14864 KB Output is correct
2 Correct 133 ms 14952 KB Output is correct
3 Correct 86 ms 14960 KB Output is correct
4 Correct 87 ms 14952 KB Output is correct
5 Correct 79 ms 14924 KB Output is correct
6 Correct 136 ms 14872 KB Output is correct
7 Correct 97 ms 14860 KB Output is correct
8 Correct 56 ms 14908 KB Output is correct
9 Correct 60 ms 14880 KB Output is correct
10 Correct 1 ms 216 KB Output is correct
11 Correct 102 ms 15148 KB Output is correct
12 Correct 159 ms 15116 KB Output is correct
13 Correct 99 ms 15136 KB Output is correct
14 Correct 112 ms 15160 KB Output is correct
15 Correct 101 ms 15220 KB Output is correct
16 Correct 124 ms 15124 KB Output is correct
17 Correct 98 ms 15124 KB Output is correct
18 Correct 74 ms 15180 KB Output is correct
19 Correct 78 ms 15132 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 9 ms 960 KB Output is correct
12 Correct 13 ms 896 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 9 ms 984 KB Output is correct
15 Correct 9 ms 904 KB Output is correct
16 Correct 12 ms 852 KB Output is correct
17 Correct 8 ms 852 KB Output is correct
18 Correct 21 ms 848 KB Output is correct
19 Correct 4 ms 708 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 14864 KB Output is correct
2 Correct 133 ms 14952 KB Output is correct
3 Correct 86 ms 14960 KB Output is correct
4 Correct 87 ms 14952 KB Output is correct
5 Correct 79 ms 14924 KB Output is correct
6 Correct 136 ms 14872 KB Output is correct
7 Correct 97 ms 14860 KB Output is correct
8 Correct 56 ms 14908 KB Output is correct
9 Correct 60 ms 14880 KB Output is correct
10 Correct 1 ms 216 KB Output is correct
11 Correct 102 ms 15148 KB Output is correct
12 Correct 159 ms 15116 KB Output is correct
13 Correct 99 ms 15136 KB Output is correct
14 Correct 112 ms 15160 KB Output is correct
15 Correct 101 ms 15220 KB Output is correct
16 Correct 124 ms 15124 KB Output is correct
17 Correct 98 ms 15124 KB Output is correct
18 Correct 74 ms 15180 KB Output is correct
19 Correct 78 ms 15132 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 142 ms 16012 KB Output is correct
22 Correct 139 ms 16012 KB Output is correct
23 Correct 145 ms 16016 KB Output is correct
24 Correct 152 ms 16016 KB Output is correct
25 Correct 150 ms 16012 KB Output is correct
26 Correct 163 ms 16168 KB Output is correct
27 Correct 142 ms 16032 KB Output is correct
28 Correct 139 ms 16096 KB Output is correct
29 Correct 122 ms 16016 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 256 ms 19904 KB Output is correct
3 Correct 246 ms 19856 KB Output is correct
4 Correct 243 ms 19860 KB Output is correct
5 Correct 220 ms 19856 KB Output is correct
6 Correct 252 ms 19856 KB Output is correct
7 Correct 231 ms 19864 KB Output is correct
8 Correct 233 ms 19860 KB Output is correct
9 Correct 224 ms 19892 KB Output is correct
10 Correct 236 ms 19864 KB Output is correct
11 Correct 76 ms 14864 KB Output is correct
12 Correct 133 ms 14952 KB Output is correct
13 Correct 86 ms 14960 KB Output is correct
14 Correct 87 ms 14952 KB Output is correct
15 Correct 79 ms 14924 KB Output is correct
16 Correct 136 ms 14872 KB Output is correct
17 Correct 97 ms 14860 KB Output is correct
18 Correct 56 ms 14908 KB Output is correct
19 Correct 60 ms 14880 KB Output is correct
20 Correct 1 ms 216 KB Output is correct
21 Correct 102 ms 15148 KB Output is correct
22 Correct 159 ms 15116 KB Output is correct
23 Correct 99 ms 15136 KB Output is correct
24 Correct 112 ms 15160 KB Output is correct
25 Correct 101 ms 15220 KB Output is correct
26 Correct 124 ms 15124 KB Output is correct
27 Correct 98 ms 15124 KB Output is correct
28 Correct 74 ms 15180 KB Output is correct
29 Correct 78 ms 15132 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 312 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 9 ms 960 KB Output is correct
42 Correct 13 ms 896 KB Output is correct
43 Correct 9 ms 852 KB Output is correct
44 Correct 9 ms 984 KB Output is correct
45 Correct 9 ms 904 KB Output is correct
46 Correct 12 ms 852 KB Output is correct
47 Correct 8 ms 852 KB Output is correct
48 Correct 21 ms 848 KB Output is correct
49 Correct 4 ms 708 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 142 ms 16012 KB Output is correct
52 Correct 139 ms 16012 KB Output is correct
53 Correct 145 ms 16016 KB Output is correct
54 Correct 152 ms 16016 KB Output is correct
55 Correct 150 ms 16012 KB Output is correct
56 Correct 163 ms 16168 KB Output is correct
57 Correct 142 ms 16032 KB Output is correct
58 Correct 139 ms 16096 KB Output is correct
59 Correct 122 ms 16016 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 283 ms 19860 KB Output is correct
62 Correct 288 ms 19860 KB Output is correct
63 Correct 266 ms 19860 KB Output is correct
64 Correct 281 ms 19860 KB Output is correct
65 Correct 272 ms 19880 KB Output is correct
66 Correct 264 ms 19800 KB Output is correct
67 Correct 252 ms 19848 KB Output is correct
68 Correct 290 ms 19860 KB Output is correct
69 Correct 145 ms 16208 KB Output is correct
70 Correct 1 ms 308 KB Output is correct