Skip to content
Snippets Groups Projects
Commit 50389063 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Add BALE11

parent 85adab67
No related branches found
No related tags found
No related merge requests found
#include <bits/stdc++.h>
#define MAX 101010
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define sz size()
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int v[MAX];
int tree[MAX];
int query(int idx) {
int sum = 0;
for (; idx > 0; idx -= (idx & -idx))
sum += tree[idx];
return sum;
}
void update(int idx, int val) {
for (; idx <= MAX; idx += (idx & -idx))
tree[idx] += val;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> v[i];
int ans = 0;
for (int i = 0; i < n; ++i) {
ans += query(n - v[i] + 1);
update(n - v[i] + 1, 1);
}
cout << ans << '\n';
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment