#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=(int)b;i++)
#define FORD(i,a,b) for(int i=a;i>=(int)b;i--)
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define BIT(mask,i) ((mask>>(i))&1)
#define MASK(a) (1LL<((a)))
#define uni(v) sort(all(v)); v.resize(unique(all(v)) - v.begin())
#define pii pair <int, int>
#define vi vector <int>
#define vl vector <ll>
template <class A,class B>
bool maximize(A &a, const B b)
{
if(a < b){ a = b; return 1;} return 0;
}
template <class A,class B>
bool minimize(A &a, const B b)
{
if(a > b){ a = b; return 1;} return 0;
}
const int maxn = 3e5 + 5;
int n;
ll a[maxn];
struct Fenwick
{
int bit[maxn];
void up(int u, int val){for(int i = u; i <= n; i+= i&-i) bit[i]+= val;}
int get(int u){int res = 0; for(int i = u; i; i-=i&-i) res+= bit[i]; return res;}
int get(int l, int r) {return get(r) - get(l - 1);}
} fwt;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define kieuoanh "caonashdadj"
if(fopen(kieuoanh".inp","r"))
{
freopen(kieuoanh".inp","r",stdin);
freopen(kieuoanh".out","w",stdout);
}
cin >> n;
FOR(i, 1, n) cin >> a[i];
vl values;
FOR(i, 1, n) values.pb(a[i]);
uni(values);
FOR(i, 1, n) a[i] = upper_bound(all(values), a[i]) - values.begin();
vi L(n + 2, 0);
vi R(n + 2, 0);
FOR(i, 1, n)
{
L[i] = fwt.get(a[i] - 1);
fwt.up(a[i], 1);
}
FOR(i, 1, n) fwt.up(a[i], - 1);
FORD(i, n, 1)
{
R[i] = fwt.get(a[i] - 1);
fwt.up(a[i], 1);
}
ll ans = 0;
FOR(i, 1, n) ans+= 1LL * L[i] * R[i];
cout << ans;
return 0;
}
Compilation message (stderr)
Mountains.cpp: In function 'int main()':
Mountains.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(kieuoanh".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen(kieuoanh".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |