Submission #1311007

#TimeUsernameProblemLanguageResultExecution timeMemory
1311007discontinuousMountains (NOI20_mountains)C++20
22 / 100
381 ms31904 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define pb push_back
#define int long long

const int MOD = 1e9 + 7;
const int INF = 1e15;
const int N = 1e6;

int n, m, k, a, b, c, d, h, l, r, q, u, v, x, y;
vector<int> arr(N);

void solve() {
	cin >> n;

	for(int i = 0; i<n; i++) {
		cin >> arr[i];
	}

	ordered_set all;
	l = 0;
	all.insert({arr[0], l++});

	vector<int> smaller(n);
	vector<int> bigger(n);

	for(int i = 1; i<n; i++) {
		smaller[i] = all.order_of_key({arr[i], 0});
		all.insert({arr[i], l++});
	}

	all.clear();
	l = 0;
	all.insert({arr[n-1], l++});
	for(int i = n-2; i>=0; i--) {
		bigger[i] = all.order_of_key({arr[i], 0});
		all.insert({arr[i], l++});
	}

	c = 0;
	for(int i = 1; i<n-1; i++) c += smaller[i]*bigger[i];
	cout << c;
}

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

	int tc = 1;
	// cin >> tc;

	while(tc--) {
		solve();
		cout << "\n";
	}

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...