답안 #761995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761995 2023-06-20T13:57:32 Z KN200711 Mountains (NOI20_mountains) C++14
100 / 100
363 ms 34020 KB
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;

const int MXN = 3e5;
ll fen[300001];
map<ll, int> M;

void upd(int a) {
	while(a <= MXN) {
		fen[a]++;
		a += a&(-a);
	}
	return;
}

ll qry(int a) {
	int res = 0;
	while(a > 0) {
		res += fen[a];
		a -= a&(-a);
	}
	return res;
}

int main() {
	int N;
	scanf("%d", &N);
	
	vector<ll> arr(N);
	for(int i=0;i<N;i++) {
		scanf("%lld", &arr[i]);
		M[arr[i]] = 1;
	}
	int cnt = 1;
	for(auto p : M) {
		M[p.fi] = cnt;
		cnt++;
	}
	for(int i=0;i<N;i++) {
		arr[i] = M[arr[i]];
	//	cout<<arr[i]<<endl;
	}
	
	vector<ll> pref(N);
	for(int i=0;i<N;i++) {
		pref[i] = qry(arr[i] - 1);
		upd(arr[i]);
	}
	
	ll ans = 0ll;
	
	for(int i=0;i<=MXN;i++) fen[i] = 0;
	vector<ll> suff(N);
	for(int i=N-1;i>=0;i--) {
		suff[i] = qry(arr[i] - 1);
		upd(arr[i]);
		
	//	cout<<pref[i]<<" "<<suff[i]<<endl;
		
		ans += (1ll * pref[i]) * (1ll * suff[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Mountains.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%lld", &arr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 175 ms 28428 KB Output is correct
3 Correct 173 ms 34020 KB Output is correct
4 Correct 173 ms 33972 KB Output is correct
5 Correct 171 ms 33980 KB Output is correct
6 Correct 174 ms 34000 KB Output is correct
7 Correct 182 ms 33904 KB Output is correct
8 Correct 174 ms 33988 KB Output is correct
9 Correct 149 ms 24996 KB Output is correct
10 Correct 143 ms 24908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 9640 KB Output is correct
2 Correct 58 ms 9576 KB Output is correct
3 Correct 58 ms 9688 KB Output is correct
4 Correct 58 ms 9576 KB Output is correct
5 Correct 59 ms 9568 KB Output is correct
6 Correct 54 ms 9680 KB Output is correct
7 Correct 59 ms 9572 KB Output is correct
8 Correct 56 ms 9648 KB Output is correct
9 Correct 55 ms 9652 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 9640 KB Output is correct
2 Correct 58 ms 9576 KB Output is correct
3 Correct 58 ms 9688 KB Output is correct
4 Correct 58 ms 9576 KB Output is correct
5 Correct 59 ms 9568 KB Output is correct
6 Correct 54 ms 9680 KB Output is correct
7 Correct 59 ms 9572 KB Output is correct
8 Correct 56 ms 9648 KB Output is correct
9 Correct 55 ms 9652 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 61 ms 9692 KB Output is correct
12 Correct 61 ms 9676 KB Output is correct
13 Correct 61 ms 9692 KB Output is correct
14 Correct 61 ms 9688 KB Output is correct
15 Correct 61 ms 9572 KB Output is correct
16 Correct 61 ms 9688 KB Output is correct
17 Correct 61 ms 9692 KB Output is correct
18 Correct 45 ms 9708 KB Output is correct
19 Correct 45 ms 9664 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2568 KB Output is correct
11 Correct 7 ms 3624 KB Output is correct
12 Correct 7 ms 3620 KB Output is correct
13 Correct 7 ms 3668 KB Output is correct
14 Correct 7 ms 3668 KB Output is correct
15 Correct 7 ms 3644 KB Output is correct
16 Correct 7 ms 3640 KB Output is correct
17 Correct 7 ms 3676 KB Output is correct
18 Correct 7 ms 3344 KB Output is correct
19 Correct 4 ms 2888 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 9640 KB Output is correct
2 Correct 58 ms 9576 KB Output is correct
3 Correct 58 ms 9688 KB Output is correct
4 Correct 58 ms 9576 KB Output is correct
5 Correct 59 ms 9568 KB Output is correct
6 Correct 54 ms 9680 KB Output is correct
7 Correct 59 ms 9572 KB Output is correct
8 Correct 56 ms 9648 KB Output is correct
9 Correct 55 ms 9652 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 61 ms 9692 KB Output is correct
12 Correct 61 ms 9676 KB Output is correct
13 Correct 61 ms 9692 KB Output is correct
14 Correct 61 ms 9688 KB Output is correct
15 Correct 61 ms 9572 KB Output is correct
16 Correct 61 ms 9688 KB Output is correct
17 Correct 61 ms 9692 KB Output is correct
18 Correct 45 ms 9708 KB Output is correct
19 Correct 45 ms 9664 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 174 ms 15588 KB Output is correct
22 Correct 192 ms 15564 KB Output is correct
23 Correct 174 ms 15624 KB Output is correct
24 Correct 181 ms 15616 KB Output is correct
25 Correct 173 ms 15612 KB Output is correct
26 Correct 175 ms 15608 KB Output is correct
27 Correct 196 ms 15556 KB Output is correct
28 Correct 106 ms 15564 KB Output is correct
29 Correct 104 ms 15536 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 175 ms 28428 KB Output is correct
3 Correct 173 ms 34020 KB Output is correct
4 Correct 173 ms 33972 KB Output is correct
5 Correct 171 ms 33980 KB Output is correct
6 Correct 174 ms 34000 KB Output is correct
7 Correct 182 ms 33904 KB Output is correct
8 Correct 174 ms 33988 KB Output is correct
9 Correct 149 ms 24996 KB Output is correct
10 Correct 143 ms 24908 KB Output is correct
11 Correct 58 ms 9640 KB Output is correct
12 Correct 58 ms 9576 KB Output is correct
13 Correct 58 ms 9688 KB Output is correct
14 Correct 58 ms 9576 KB Output is correct
15 Correct 59 ms 9568 KB Output is correct
16 Correct 54 ms 9680 KB Output is correct
17 Correct 59 ms 9572 KB Output is correct
18 Correct 56 ms 9648 KB Output is correct
19 Correct 55 ms 9652 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 61 ms 9692 KB Output is correct
22 Correct 61 ms 9676 KB Output is correct
23 Correct 61 ms 9692 KB Output is correct
24 Correct 61 ms 9688 KB Output is correct
25 Correct 61 ms 9572 KB Output is correct
26 Correct 61 ms 9688 KB Output is correct
27 Correct 61 ms 9692 KB Output is correct
28 Correct 45 ms 9708 KB Output is correct
29 Correct 45 ms 9664 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 1 ms 2644 KB Output is correct
40 Correct 2 ms 2568 KB Output is correct
41 Correct 7 ms 3624 KB Output is correct
42 Correct 7 ms 3620 KB Output is correct
43 Correct 7 ms 3668 KB Output is correct
44 Correct 7 ms 3668 KB Output is correct
45 Correct 7 ms 3644 KB Output is correct
46 Correct 7 ms 3640 KB Output is correct
47 Correct 7 ms 3676 KB Output is correct
48 Correct 7 ms 3344 KB Output is correct
49 Correct 4 ms 2888 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 174 ms 15588 KB Output is correct
52 Correct 192 ms 15564 KB Output is correct
53 Correct 174 ms 15624 KB Output is correct
54 Correct 181 ms 15616 KB Output is correct
55 Correct 173 ms 15612 KB Output is correct
56 Correct 175 ms 15608 KB Output is correct
57 Correct 196 ms 15556 KB Output is correct
58 Correct 106 ms 15564 KB Output is correct
59 Correct 104 ms 15536 KB Output is correct
60 Correct 1 ms 2644 KB Output is correct
61 Correct 347 ms 34016 KB Output is correct
62 Correct 339 ms 33908 KB Output is correct
63 Correct 363 ms 34016 KB Output is correct
64 Correct 330 ms 33980 KB Output is correct
65 Correct 326 ms 34012 KB Output is correct
66 Correct 332 ms 33996 KB Output is correct
67 Correct 327 ms 33992 KB Output is correct
68 Correct 240 ms 24908 KB Output is correct
69 Correct 190 ms 19592 KB Output is correct
70 Correct 1 ms 2644 KB Output is correct