답안 #343393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343393 2021-01-03T20:58:42 Z zapan4 Mountains (NOI20_mountains) C++17
100 / 100
694 ms 36632 KB
#include <iostream>
#include <cmath> 
#include <stdio.h>
#include <array>
#include <vector>
#include <list>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#define pp pair<int,int>
#define pll pair<ll, ll>
#define ll long long
using namespace std;

map<ll, ll> normalizing;

ll bit[300003];
ll mountains[300001];
ll mountains1[300001];
ll left1[300001];
ll right1[300001];

ll calculate(int a) {
	ll amount = 0;
	while (a > 0) {
		amount += bit[a];
		a -= (a & -a);
	}
	return amount;
}

void update(int a) {
	while (a <= 300003) {
		bit[a] += 1;
		a += (a & -a);
	}
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		mountains[i] = a;
		mountains1[i] = a;
	}
	sort(mountains1, mountains1+n);
	ll counter = 1;
	for (int i = 0; i < n; i++) {
		if (normalizing.find(mountains1[i]) == normalizing.end()) {
			normalizing[mountains1[i]] = counter;
			counter++;
		}
	}
	for (int i = 0; i < n; i++) {
		mountains[i] = normalizing[mountains[i]];
	}
	/*for (int i = 0; i < n; i++) {
		cout << mountains[i] << endl;
	}*/
	for (int i = 0; i < n; i++) {
		left1[i] = calculate(mountains[i]-1);
		update(mountains[i]);
	}
	/*for (int i = 0; i < n; i++) {
		cout << left1[i] << endl;
	}*/
	for (int i = 0; i < 300003; i++) {
		bit[i] = 0;
	}
	for (int i = n-1; i >= 0; i--) {
		right1[i] = calculate(mountains[i]-1);
		update(mountains[i]);
	}
	/*for (int i = 0; i < n; i++) {
		cout << right1[i] << endl;
	}*/
	ll answer = 0;
	for (int i = 0; i < n; i++) {
		answer += left1[i]*right1[i];
	}
	cout << answer << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 381 ms 36480 KB Output is correct
3 Correct 388 ms 36408 KB Output is correct
4 Correct 392 ms 36332 KB Output is correct
5 Correct 385 ms 36332 KB Output is correct
6 Correct 385 ms 36484 KB Output is correct
7 Correct 381 ms 36348 KB Output is correct
8 Correct 388 ms 36332 KB Output is correct
9 Correct 358 ms 27372 KB Output is correct
10 Correct 355 ms 27392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 12652 KB Output is correct
2 Correct 97 ms 12652 KB Output is correct
3 Correct 113 ms 12780 KB Output is correct
4 Correct 103 ms 12672 KB Output is correct
5 Correct 111 ms 12652 KB Output is correct
6 Correct 106 ms 12652 KB Output is correct
7 Correct 100 ms 12652 KB Output is correct
8 Correct 93 ms 12656 KB Output is correct
9 Correct 97 ms 12596 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 12652 KB Output is correct
2 Correct 97 ms 12652 KB Output is correct
3 Correct 113 ms 12780 KB Output is correct
4 Correct 103 ms 12672 KB Output is correct
5 Correct 111 ms 12652 KB Output is correct
6 Correct 106 ms 12652 KB Output is correct
7 Correct 100 ms 12652 KB Output is correct
8 Correct 93 ms 12656 KB Output is correct
9 Correct 97 ms 12596 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 120 ms 12996 KB Output is correct
12 Correct 117 ms 12908 KB Output is correct
13 Correct 122 ms 12908 KB Output is correct
14 Correct 118 ms 12908 KB Output is correct
15 Correct 118 ms 13036 KB Output is correct
16 Correct 115 ms 12908 KB Output is correct
17 Correct 125 ms 12908 KB Output is correct
18 Correct 108 ms 12908 KB Output is correct
19 Correct 95 ms 13036 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2796 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Correct 2 ms 2796 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 3 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2796 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Correct 2 ms 2796 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 3 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 17 ms 3820 KB Output is correct
12 Correct 14 ms 3820 KB Output is correct
13 Correct 14 ms 3820 KB Output is correct
14 Correct 18 ms 3840 KB Output is correct
15 Correct 14 ms 3820 KB Output is correct
16 Correct 14 ms 3820 KB Output is correct
17 Correct 20 ms 3820 KB Output is correct
18 Correct 13 ms 3628 KB Output is correct
19 Correct 6 ms 3052 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 12652 KB Output is correct
2 Correct 97 ms 12652 KB Output is correct
3 Correct 113 ms 12780 KB Output is correct
4 Correct 103 ms 12672 KB Output is correct
5 Correct 111 ms 12652 KB Output is correct
6 Correct 106 ms 12652 KB Output is correct
7 Correct 100 ms 12652 KB Output is correct
8 Correct 93 ms 12656 KB Output is correct
9 Correct 97 ms 12596 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 120 ms 12996 KB Output is correct
12 Correct 117 ms 12908 KB Output is correct
13 Correct 122 ms 12908 KB Output is correct
14 Correct 118 ms 12908 KB Output is correct
15 Correct 118 ms 13036 KB Output is correct
16 Correct 115 ms 12908 KB Output is correct
17 Correct 125 ms 12908 KB Output is correct
18 Correct 108 ms 12908 KB Output is correct
19 Correct 95 ms 13036 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 313 ms 19856 KB Output is correct
22 Correct 317 ms 19712 KB Output is correct
23 Correct 317 ms 19820 KB Output is correct
24 Correct 332 ms 19692 KB Output is correct
25 Correct 364 ms 19820 KB Output is correct
26 Correct 315 ms 19820 KB Output is correct
27 Correct 345 ms 19692 KB Output is correct
28 Correct 192 ms 19692 KB Output is correct
29 Correct 192 ms 19724 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 381 ms 36480 KB Output is correct
3 Correct 388 ms 36408 KB Output is correct
4 Correct 392 ms 36332 KB Output is correct
5 Correct 385 ms 36332 KB Output is correct
6 Correct 385 ms 36484 KB Output is correct
7 Correct 381 ms 36348 KB Output is correct
8 Correct 388 ms 36332 KB Output is correct
9 Correct 358 ms 27372 KB Output is correct
10 Correct 355 ms 27392 KB Output is correct
11 Correct 100 ms 12652 KB Output is correct
12 Correct 97 ms 12652 KB Output is correct
13 Correct 113 ms 12780 KB Output is correct
14 Correct 103 ms 12672 KB Output is correct
15 Correct 111 ms 12652 KB Output is correct
16 Correct 106 ms 12652 KB Output is correct
17 Correct 100 ms 12652 KB Output is correct
18 Correct 93 ms 12656 KB Output is correct
19 Correct 97 ms 12596 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 120 ms 12996 KB Output is correct
22 Correct 117 ms 12908 KB Output is correct
23 Correct 122 ms 12908 KB Output is correct
24 Correct 118 ms 12908 KB Output is correct
25 Correct 118 ms 13036 KB Output is correct
26 Correct 115 ms 12908 KB Output is correct
27 Correct 125 ms 12908 KB Output is correct
28 Correct 108 ms 12908 KB Output is correct
29 Correct 95 ms 13036 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
31 Correct 3 ms 2796 KB Output is correct
32 Correct 2 ms 2796 KB Output is correct
33 Correct 2 ms 2796 KB Output is correct
34 Correct 2 ms 2796 KB Output is correct
35 Correct 3 ms 2796 KB Output is correct
36 Correct 3 ms 2796 KB Output is correct
37 Correct 2 ms 2796 KB Output is correct
38 Correct 2 ms 2796 KB Output is correct
39 Correct 3 ms 2668 KB Output is correct
40 Correct 2 ms 2668 KB Output is correct
41 Correct 17 ms 3820 KB Output is correct
42 Correct 14 ms 3820 KB Output is correct
43 Correct 14 ms 3820 KB Output is correct
44 Correct 18 ms 3840 KB Output is correct
45 Correct 14 ms 3820 KB Output is correct
46 Correct 14 ms 3820 KB Output is correct
47 Correct 20 ms 3820 KB Output is correct
48 Correct 13 ms 3628 KB Output is correct
49 Correct 6 ms 3052 KB Output is correct
50 Correct 2 ms 2668 KB Output is correct
51 Correct 313 ms 19856 KB Output is correct
52 Correct 317 ms 19712 KB Output is correct
53 Correct 317 ms 19820 KB Output is correct
54 Correct 332 ms 19692 KB Output is correct
55 Correct 364 ms 19820 KB Output is correct
56 Correct 315 ms 19820 KB Output is correct
57 Correct 345 ms 19692 KB Output is correct
58 Correct 192 ms 19692 KB Output is correct
59 Correct 192 ms 19724 KB Output is correct
60 Correct 2 ms 2668 KB Output is correct
61 Correct 679 ms 36372 KB Output is correct
62 Correct 686 ms 36632 KB Output is correct
63 Correct 674 ms 36460 KB Output is correct
64 Correct 664 ms 36380 KB Output is correct
65 Correct 671 ms 36332 KB Output is correct
66 Correct 683 ms 36332 KB Output is correct
67 Correct 694 ms 36332 KB Output is correct
68 Correct 550 ms 27372 KB Output is correct
69 Correct 390 ms 21996 KB Output is correct
70 Correct 2 ms 2668 KB Output is correct