# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
267040 | kimbj0709 | Mountains (NOI20_mountains) | C++14 | 182 ms | 14172 KiB |
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>
using namespace std;
#define int long long
#define maxn 300050
vector<int> fenwick(maxn,0);
void add(int b,int c){
int temp = b+1;
while(temp<=fenwick.size()){
fenwick[temp] += c;
temp += temp & (-temp);
}
}
int getsum(int a,int b){
int temp = b+1;
int total = 0;
while(temp!=0){
total += fenwick[temp];
temp -= temp & (-temp);
}
int idk = a;
while(idk!=0){
total -= fenwick[idk];
idk -= idk & (-idk);
}
return total;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int no_of_input;
int input;
vector<int> vect1;
vector<int> vect2;
cin >> no_of_input;
for(int i=0;i<no_of_input;i++){
cin >> input;
vect1.push_back(input);
vect2.push_back(input);
}
sort(vect2.begin(),vect2.end());
for(int i=0;i<no_of_input;i++){
int k = lower_bound(vect2.begin(),vect2.end(),vect1[i])-vect2.begin();
vect1[i] = k+1;
}
for(int i=0;i<vect1.size();i++){
vect2[i] = getsum(0,vect1[i]-1);
add(vect1[i],1);
}
for(int i=0;i<fenwick.size();i++){
fenwick[i] = 0;
}
int ans = 0;
for(int i=vect1.size()-1;i>=0;i--){
ans += vect2[i]*getsum(0,vect1[i]-1);
add(vect1[i],1);
}
cout << ans;
}
Compilation message (stderr)
# | 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... |