大水题WA了两发T T
记录一下a[i]的前缀和,a[i]*a[j]就是sigma(a[j]*sumi[j-1])
记录一下a[i]*a[j]的前缀和,a[i]*a[j]*a[k]就是sigma(a[k]*sumij[k-1])
因为要求ai<aj<ak,所以前缀和必须用权值树状数组来统计
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<algorithm> #define MOD(x) ((x)>=mod?(x)-mod:(x)) using namespace std; const int maxn=500010,mod=19260817; int n,N,ans; int a[maxn],b[maxn],lisan[maxn],tree[2][maxn]; char buf[80000010],*ptr=buf-1; inline int read() { char c=*++ptr;int s=0,t=1; while(c<48||c>57)c=*++ptr; while(c>=48&&c<=57){s=s*10+c-'0';c=*++ptr;} return s*t; } inline int lowbit(int x){return x&-x;} inline void add(int x,int delta,int ty){for(;x<=N;x+=lowbit(x))tree[ty][x]=MOD(tree[ty][x]+delta);} inline int query(int x,int ty){int sum=0;for(;x;x-=lowbit(x))sum=MOD(sum+tree[ty][x]);return sum;} int main() { fread(buf,1,sizeof(buf),stdin);n=read(); for(int i=1;i<=n;i++)a[i]=read(),a[i]%=mod,b[i]=a[i];N=n; sort(b+1,b+1+N);N=unique(b+1,b+1+N)-b-1; for(int i=1;i<=n;i++)lisan[i]=lower_bound(b+1,b+1+N,a[i])-b; for(int i=1;i<=n;i++) { ans=(ans+1ll*a[i]*query(lisan[i]-1,1))%mod; int x=1ll*a[i]*query(lisan[i]-1,0)%mod; add(lisan[i],a[i],0);add(lisan[i],x,1); } printf("%d ",ans); }