Submission #1091569

# Submission time Handle Problem Language Result Execution time Memory
1091569 2024-09-21T09:47:34 Z _rain_ Mountains (NOI20_mountains) C++14
100 / 100
123 ms 14352 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fixbug true

const int maxn = 3e5;
int BIT[maxn+2],ans[maxn+2],n;
ll h[maxn+2];
int Right[maxn+2],Left[maxn+2];
void add(int p , int val){
	for (; p <= n; p += p&-p)
		BIT[p] += val;
	return;
}
int Get(int p){
	int sum = 0;
	for (; p; p -= p&-p)
		sum += BIT[p];
	return sum;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	cin >> n;
	vector<ll>v;
	for (int i = 1; i <= n; ++i){
		cin >> h[i];
		v.push_back(h[i]);
	}
	sort(v.begin(),v.end());
	v.resize(unique(v.begin(),v.end())-v.begin());
	for (int i = 1; i <= n; ++i)
		h[i] = upper_bound(v.begin(),v.end(),h[i])-v.begin();
	for (int i = 1; i <= n; ++i){
		add(h[i],1);
		Left[i] += Get(h[i]-1);
	}
	memset(BIT,0,sizeof BIT);
	for (int i = n; i >= 1; --i){
		add(h[i],1);
		Right[i] += Get(h[i]-1);
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i){
		ans += (ll)Left[i]*Right[i];
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 74 ms 14160 KB Output is correct
3 Correct 63 ms 14120 KB Output is correct
4 Correct 61 ms 14272 KB Output is correct
5 Correct 59 ms 14280 KB Output is correct
6 Correct 60 ms 14276 KB Output is correct
7 Correct 61 ms 14268 KB Output is correct
8 Correct 60 ms 14268 KB Output is correct
9 Correct 68 ms 14224 KB Output is correct
10 Correct 61 ms 14260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 8664 KB Output is correct
2 Correct 40 ms 8576 KB Output is correct
3 Correct 42 ms 8644 KB Output is correct
4 Correct 39 ms 8636 KB Output is correct
5 Correct 40 ms 8648 KB Output is correct
6 Correct 43 ms 8656 KB Output is correct
7 Correct 40 ms 8648 KB Output is correct
8 Correct 36 ms 8640 KB Output is correct
9 Correct 39 ms 8656 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 8664 KB Output is correct
2 Correct 40 ms 8576 KB Output is correct
3 Correct 42 ms 8644 KB Output is correct
4 Correct 39 ms 8636 KB Output is correct
5 Correct 40 ms 8648 KB Output is correct
6 Correct 43 ms 8656 KB Output is correct
7 Correct 40 ms 8648 KB Output is correct
8 Correct 36 ms 8640 KB Output is correct
9 Correct 39 ms 8656 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 50 ms 8560 KB Output is correct
12 Correct 53 ms 8636 KB Output is correct
13 Correct 50 ms 8600 KB Output is correct
14 Correct 50 ms 8644 KB Output is correct
15 Correct 54 ms 8660 KB Output is correct
16 Correct 54 ms 8632 KB Output is correct
17 Correct 51 ms 8632 KB Output is correct
18 Correct 33 ms 8656 KB Output is correct
19 Correct 33 ms 8808 KB Output is correct
20 Correct 1 ms 1624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 3 ms 2136 KB Output is correct
12 Correct 4 ms 2136 KB Output is correct
13 Correct 5 ms 2392 KB Output is correct
14 Correct 4 ms 2008 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 4 ms 2160 KB Output is correct
17 Correct 3 ms 2140 KB Output is correct
18 Correct 4 ms 1976 KB Output is correct
19 Correct 3 ms 1884 KB Output is correct
20 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 8664 KB Output is correct
2 Correct 40 ms 8576 KB Output is correct
3 Correct 42 ms 8644 KB Output is correct
4 Correct 39 ms 8636 KB Output is correct
5 Correct 40 ms 8648 KB Output is correct
6 Correct 43 ms 8656 KB Output is correct
7 Correct 40 ms 8648 KB Output is correct
8 Correct 36 ms 8640 KB Output is correct
9 Correct 39 ms 8656 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 50 ms 8560 KB Output is correct
12 Correct 53 ms 8636 KB Output is correct
13 Correct 50 ms 8600 KB Output is correct
14 Correct 50 ms 8644 KB Output is correct
15 Correct 54 ms 8660 KB Output is correct
16 Correct 54 ms 8632 KB Output is correct
17 Correct 51 ms 8632 KB Output is correct
18 Correct 33 ms 8656 KB Output is correct
19 Correct 33 ms 8808 KB Output is correct
20 Correct 1 ms 1624 KB Output is correct
21 Correct 92 ms 8620 KB Output is correct
22 Correct 91 ms 8620 KB Output is correct
23 Correct 91 ms 8636 KB Output is correct
24 Correct 90 ms 8640 KB Output is correct
25 Correct 92 ms 8632 KB Output is correct
26 Correct 91 ms 8636 KB Output is correct
27 Correct 91 ms 8640 KB Output is correct
28 Correct 44 ms 8640 KB Output is correct
29 Correct 45 ms 8636 KB Output is correct
30 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 74 ms 14160 KB Output is correct
3 Correct 63 ms 14120 KB Output is correct
4 Correct 61 ms 14272 KB Output is correct
5 Correct 59 ms 14280 KB Output is correct
6 Correct 60 ms 14276 KB Output is correct
7 Correct 61 ms 14268 KB Output is correct
8 Correct 60 ms 14268 KB Output is correct
9 Correct 68 ms 14224 KB Output is correct
10 Correct 61 ms 14260 KB Output is correct
11 Correct 41 ms 8664 KB Output is correct
12 Correct 40 ms 8576 KB Output is correct
13 Correct 42 ms 8644 KB Output is correct
14 Correct 39 ms 8636 KB Output is correct
15 Correct 40 ms 8648 KB Output is correct
16 Correct 43 ms 8656 KB Output is correct
17 Correct 40 ms 8648 KB Output is correct
18 Correct 36 ms 8640 KB Output is correct
19 Correct 39 ms 8656 KB Output is correct
20 Correct 1 ms 1628 KB Output is correct
21 Correct 50 ms 8560 KB Output is correct
22 Correct 53 ms 8636 KB Output is correct
23 Correct 50 ms 8600 KB Output is correct
24 Correct 50 ms 8644 KB Output is correct
25 Correct 54 ms 8660 KB Output is correct
26 Correct 54 ms 8632 KB Output is correct
27 Correct 51 ms 8632 KB Output is correct
28 Correct 33 ms 8656 KB Output is correct
29 Correct 33 ms 8808 KB Output is correct
30 Correct 1 ms 1624 KB Output is correct
31 Correct 2 ms 1628 KB Output is correct
32 Correct 1 ms 1628 KB Output is correct
33 Correct 1 ms 1628 KB Output is correct
34 Correct 1 ms 1628 KB Output is correct
35 Correct 1 ms 1628 KB Output is correct
36 Correct 1 ms 1628 KB Output is correct
37 Correct 1 ms 1628 KB Output is correct
38 Correct 1 ms 1628 KB Output is correct
39 Correct 1 ms 1628 KB Output is correct
40 Correct 1 ms 1484 KB Output is correct
41 Correct 3 ms 2136 KB Output is correct
42 Correct 4 ms 2136 KB Output is correct
43 Correct 5 ms 2392 KB Output is correct
44 Correct 4 ms 2008 KB Output is correct
45 Correct 3 ms 2140 KB Output is correct
46 Correct 4 ms 2160 KB Output is correct
47 Correct 3 ms 2140 KB Output is correct
48 Correct 4 ms 1976 KB Output is correct
49 Correct 3 ms 1884 KB Output is correct
50 Correct 1 ms 1628 KB Output is correct
51 Correct 92 ms 8620 KB Output is correct
52 Correct 91 ms 8620 KB Output is correct
53 Correct 91 ms 8636 KB Output is correct
54 Correct 90 ms 8640 KB Output is correct
55 Correct 92 ms 8632 KB Output is correct
56 Correct 91 ms 8636 KB Output is correct
57 Correct 91 ms 8640 KB Output is correct
58 Correct 44 ms 8640 KB Output is correct
59 Correct 45 ms 8636 KB Output is correct
60 Correct 1 ms 1628 KB Output is correct
61 Correct 119 ms 14272 KB Output is correct
62 Correct 123 ms 14272 KB Output is correct
63 Correct 122 ms 14272 KB Output is correct
64 Correct 121 ms 14304 KB Output is correct
65 Correct 120 ms 14268 KB Output is correct
66 Correct 121 ms 14212 KB Output is correct
67 Correct 122 ms 14352 KB Output is correct
68 Correct 112 ms 14304 KB Output is correct
69 Correct 94 ms 10428 KB Output is correct
70 Correct 1 ms 1624 KB Output is correct