#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <vector>
#include <string>
#include <queue>
using namespace std;
#define ll long long
#define N 100500
#define mod 1000000007
int n;
ll a[N];int idx[N];
ll dp[N],sum[N];
bool cmp(int left,int right)
{
return a[left]==a[right] ? left<right : a[left]<a[right];
}
int lowbit(int x)
{
return x&(-x);
}
void update(int x,ll val)
{
while(x<=n)
{
sum[x]+=val;
sum[x]%=mod;
x+=lowbit(x);
}
}
ll query(int x)
{
ll res=0;
while(x>0)
{
res+=sum[x];
res%=mod;
x-=lowbit(x);
}
return res;
}
int main ()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%I64d",&a[i]);
idx[i]=i;
}
sort(idx+1,idx+1+n,cmp);
ll ans=0,now;
for(int i=1;i<=n;++i)
{
if(a[idx[i-1]] != a[idx[i]])
{
now=a[idx[i]];
now+=query(idx[i]-1) * a[idx[i]];
}
else
{
now=(query(idx[i]-1)-query(idx[i-1]-1)) * a[idx[i]];
now%=mod;
}
// now can be <0
now=(now%mod+mod)%mod;
update(idx[i],now);
ans=(ans+now)%mod;
}
cout<<ans<<endl;
return 0;
}
CF314-C Sereja and Subsequences
最新推荐文章于 2019-01-08 08:33:39 发布