# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092789 | Sunbae | Mountains (NOI20_mountains) | C++17 | 175 ms | 15556 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>
typedef long long ll;
using namespace std;
const int N = 5e5 + 5;
ll a[N], cp[N], A[N], tot;
int bit[N], m;
void upd(int i){ for(; i<=m; i+=i&-i) ++bit[i];}
int qry(int i){ int r = 0; for(; i; i-=i&-i) r += bit[i]; return r;}
int pos(int x){ return upper_bound(cp, cp+m, x) - cp;}
signed main(){
int n; scanf("%d", &n);
for(int i = 1; i<=n; ++i) scanf("%lld", a+i), cp[m++] = a[i];
sort(cp, cp+m); m = unique(cp, cp+m) - cp;
for(int i = 1; i<=n; ++i) A[i] = qry(pos(a[i]) - 1), upd(pos(a[i]));
memset(bit, 0, sizeof(bit));
for(int i = n; i>=1; --i) A[i] *= qry(pos(a[i]) - 1), upd(pos(a[i]));
for(int i = 1; i<=n; ++i) tot += A[i];
printf("%lld", tot);
}
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... |