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 <stdio.h>
#include <algorithm>
#define max_a 100100
const long long mod = 1000000007;
int N; long long a[max_a],b[max_a],c[max_a],d;
void add(long long &a, long long p)
{
a += p;
if (a >= mod) a -= mod;
}
void in(long long *t, int x, long long p)
{
for (;x<max_a;x+=x&(-x)) add(t[x],p);
}
long long out(long long *t, int x)
{
long long r = 0;
for (;x;x-=x&(-x)) add(r,t[x]);
return r;
}
int main()
{
int i;
scanf ("%d",&N);
for (i=0;i<N;i++) scanf ("%lld",&a[i]);
std::sort(a,a+N);
for (i=0;i<N;i++){
in(b,a[i],a[i]);
in(c,a[i],a[i]*out(b,a[i]-1)%mod);
add(d,a[i]*out(c,a[i]-1)%mod);
}
printf ("%lld",d);
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... |