Submission #1265834

#TimeUsernameProblemLanguageResultExecution timeMemory
1265834minggaMountains (NOI20_mountains)C++20
24 / 100
77 ms6392 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 3e5 + 7;
int a[N], n, lef[N];

struct BIT {
	vector<int> bit;
	int n;
	BIT(int n) : n(n) {
		bit.resize(n + 1, 0);
	}
	void update(int u, int x) {
		for(; u <= n; u += (u & -u)) bit[u] += x;
	}
	int get(int u) {
		int ans = 0;
		for(; u > 0; u -= (u & -u)) ans += bit[u];
		return ans;
	}
};

vector<int> val;

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i], val.pb(a[i]);
	sort(all(val));
	val.erase(unique(all(val)), val.end());
	BIT bit(n);
	for(int i = 1; i <= n; i++) {
		a[i] = upper_bound(all(val), a[i]) - val.begin();
		lef[i] = bit.get(a[i] - 1);
		bit.update(a[i], 1);
	}
	ll ans = 0;
	bit = BIT(n);
	for(int i = n; i > 0; i--) {
		int rig = bit.get(a[i] - 1);
		bit.update(a[i], 1);
		ans += 1ll * lef[i] * rig;
	}
	cout << ans << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

Mountains.cpp: In function 'int main()':
Mountains.cpp:40:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:41:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...