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>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n;
vl arr;
vector<ll> tree[12 * 100000];
void build(int node, int l, int r){
if(l == r)
tree[node].pb(arr[l]);
else{
int mid = (l + r) / 2;
build(node * 2, l, mid);
build(node * 2 + 1, mid + 1, r);
merge(tree[node * 2].begin(), tree[node * 2].end(), tree[node * 2 + 1].begin(), tree[node * 2 + 1].end(), back_inserter(tree[node]));
}
}
int query(int node, int l, int r, int L, int R, int k){
if(r < L || l > R) return 0;
if(L <= l && r <= R){
return lower_bound(tree[node].begin(), tree[node].end(), k) -tree[node].begin();
}
int mid = (l + r) / 2;
int left = query(node * 2, l, mid, L, R, k), right = query(node * 2 + 1, mid + 1, r, L, R, k);
return left + right;
}
int main(){
cin>>n;
for(int i = 0; i < n; i++){
ll a;
cin>>a;
arr.pb(a);
}
build(1, 0, n - 1);
ll rez = 0;
for(int i =1; i < n - 1; i++){
ll left = query(1, 0, n - 1, 0, i, arr[i]);
ll right = query(1, 0, n - 1, i, n - 1, arr[i]);
if(left > 0 && right > 0)
rez += (left * right);
}
cout<<rez<<endl;
}
# | 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... |