This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 300001;
const ll INF = 1e9;
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 35;
struct ura{
int i, v, idx;
} v[NMAX];
bool cmp(ura a, ura b){
return a.i < b.i;
}
bool cmpp(ura a, ura b){
return a.idx < b.idx;
}
int st[NMAX], n, dr[NMAX];
int aib[NMAX + 5];
void update(int x, int val){
for(int i = x; i <= n; i += i&(-i))
aib[i] += val;
}
int query(int x){
int val = 0;
for(int i = x; i > 0; i -= i&(-i))
val += aib[i];
return val;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int i;
cin >> n;
for(i = 1; i <= n; i++){
cin >> v[i].i;
v[i].idx = i;
}
int cnt = 1;
sort(v + 1, v + n + 1, cmp);
for(i = 1; i <= n; i++){
if(i > 1 && v[i].i != v[i - 1].i)
cnt++;
v[i].v = cnt;
}
sort(v + 1, v + n + 1, cmpp);
for(i = 1; i <= n; i++){
update(v[i].v, 1);
st[i] = query(v[i].v - 1);
}
ll sol = 0;
for(i = 1; i <= n; i++){
update(v[i].v, -1);
}
for(i = n; i >= 1; i--){
update(v[i].v, 1);
dr[i] = query(v[i].v - 1);
sol += 1LL * (1LL * st[i] * 1LL * dr[i]);
}
cout << sol;
return 0;
}
# | 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... |