Submission #830145

# Submission time Handle Problem Language Result Execution time Memory
830145 2023-08-18T20:01:08 Z NK_ Mountains (NOI20_mountains) C++17
100 / 100
147 ms 9732 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;
 
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = long double;

const int INF = 1e9 + 10;


struct BIT {
	int N; vl A; void init(int n) { N = n; A = vl(N, 0); }
	void upd(int p, int x) { for(++p;p<=N;p+=p&-p) A[p-1] += x; }
	ll sum(int l, int r) { return sum(r + 1) - sum(l); }
	ll sum(int r) { ll s = 0; for(;r;r-=r&-r) s += A[r-1]; return s; }
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;
	vl A(N); for(auto& x : A) cin >> x;

	vl X = A; sort(begin(X), end(X));
	// X.erase(unique(begin(X), end(X)), end(X));

	for(auto& x : A) x = lower_bound(begin(X), end(X), x) - begin(X);

	int M = sz(X);
	BIT up, dwn; up.init(M); dwn.init(M);
	ll ans = 0;
	for(auto& x : A) {
		ans += dwn.sum(x + 1, M - 1);
		ll DWN = up.sum(0, x - 1);
		dwn.upd(x, DWN);
		up.upd(x, 1);
	}
	cout << ans << nl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 86 ms 9616 KB Output is correct
3 Correct 86 ms 9588 KB Output is correct
4 Correct 87 ms 9648 KB Output is correct
5 Correct 86 ms 9580 KB Output is correct
6 Correct 86 ms 9700 KB Output is correct
7 Correct 86 ms 9712 KB Output is correct
8 Correct 85 ms 9708 KB Output is correct
9 Correct 86 ms 9584 KB Output is correct
10 Correct 92 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 9636 KB Output is correct
2 Correct 76 ms 9720 KB Output is correct
3 Correct 74 ms 9704 KB Output is correct
4 Correct 73 ms 9684 KB Output is correct
5 Correct 67 ms 9632 KB Output is correct
6 Correct 69 ms 9700 KB Output is correct
7 Correct 81 ms 9704 KB Output is correct
8 Correct 68 ms 9684 KB Output is correct
9 Correct 72 ms 9636 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 9636 KB Output is correct
2 Correct 76 ms 9720 KB Output is correct
3 Correct 74 ms 9704 KB Output is correct
4 Correct 73 ms 9684 KB Output is correct
5 Correct 67 ms 9632 KB Output is correct
6 Correct 69 ms 9700 KB Output is correct
7 Correct 81 ms 9704 KB Output is correct
8 Correct 68 ms 9684 KB Output is correct
9 Correct 72 ms 9636 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 82 ms 9628 KB Output is correct
12 Correct 87 ms 9676 KB Output is correct
13 Correct 87 ms 9704 KB Output is correct
14 Correct 85 ms 9628 KB Output is correct
15 Correct 86 ms 9616 KB Output is correct
16 Correct 84 ms 9676 KB Output is correct
17 Correct 87 ms 9588 KB Output is correct
18 Correct 55 ms 9700 KB Output is correct
19 Correct 55 ms 9684 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 9636 KB Output is correct
2 Correct 76 ms 9720 KB Output is correct
3 Correct 74 ms 9704 KB Output is correct
4 Correct 73 ms 9684 KB Output is correct
5 Correct 67 ms 9632 KB Output is correct
6 Correct 69 ms 9700 KB Output is correct
7 Correct 81 ms 9704 KB Output is correct
8 Correct 68 ms 9684 KB Output is correct
9 Correct 72 ms 9636 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 82 ms 9628 KB Output is correct
12 Correct 87 ms 9676 KB Output is correct
13 Correct 87 ms 9704 KB Output is correct
14 Correct 85 ms 9628 KB Output is correct
15 Correct 86 ms 9616 KB Output is correct
16 Correct 84 ms 9676 KB Output is correct
17 Correct 87 ms 9588 KB Output is correct
18 Correct 55 ms 9700 KB Output is correct
19 Correct 55 ms 9684 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 112 ms 9700 KB Output is correct
22 Correct 110 ms 9580 KB Output is correct
23 Correct 113 ms 9620 KB Output is correct
24 Correct 108 ms 9624 KB Output is correct
25 Correct 112 ms 9708 KB Output is correct
26 Correct 112 ms 9616 KB Output is correct
27 Correct 112 ms 9616 KB Output is correct
28 Correct 67 ms 9704 KB Output is correct
29 Correct 68 ms 9588 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 86 ms 9616 KB Output is correct
3 Correct 86 ms 9588 KB Output is correct
4 Correct 87 ms 9648 KB Output is correct
5 Correct 86 ms 9580 KB Output is correct
6 Correct 86 ms 9700 KB Output is correct
7 Correct 86 ms 9712 KB Output is correct
8 Correct 85 ms 9708 KB Output is correct
9 Correct 86 ms 9584 KB Output is correct
10 Correct 92 ms 9676 KB Output is correct
11 Correct 66 ms 9636 KB Output is correct
12 Correct 76 ms 9720 KB Output is correct
13 Correct 74 ms 9704 KB Output is correct
14 Correct 73 ms 9684 KB Output is correct
15 Correct 67 ms 9632 KB Output is correct
16 Correct 69 ms 9700 KB Output is correct
17 Correct 81 ms 9704 KB Output is correct
18 Correct 68 ms 9684 KB Output is correct
19 Correct 72 ms 9636 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 82 ms 9628 KB Output is correct
22 Correct 87 ms 9676 KB Output is correct
23 Correct 87 ms 9704 KB Output is correct
24 Correct 85 ms 9628 KB Output is correct
25 Correct 86 ms 9616 KB Output is correct
26 Correct 84 ms 9676 KB Output is correct
27 Correct 87 ms 9588 KB Output is correct
28 Correct 55 ms 9700 KB Output is correct
29 Correct 55 ms 9684 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 3 ms 596 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 3 ms 596 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 2 ms 596 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 112 ms 9700 KB Output is correct
52 Correct 110 ms 9580 KB Output is correct
53 Correct 113 ms 9620 KB Output is correct
54 Correct 108 ms 9624 KB Output is correct
55 Correct 112 ms 9708 KB Output is correct
56 Correct 112 ms 9616 KB Output is correct
57 Correct 112 ms 9616 KB Output is correct
58 Correct 67 ms 9704 KB Output is correct
59 Correct 68 ms 9588 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 147 ms 9676 KB Output is correct
62 Correct 129 ms 9708 KB Output is correct
63 Correct 131 ms 9708 KB Output is correct
64 Correct 135 ms 9616 KB Output is correct
65 Correct 138 ms 9588 KB Output is correct
66 Correct 128 ms 9676 KB Output is correct
67 Correct 128 ms 9628 KB Output is correct
68 Correct 128 ms 9620 KB Output is correct
69 Correct 113 ms 9732 KB Output is correct
70 Correct 0 ms 212 KB Output is correct