题意:求$$\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^n a_i*a_j*a_k[i<j<k][a_i<a_j<a_k]$$
Practice: might as well do twice the order right, take two Fenwick tree $ (t_1, t_2) $ Maintenance
$ $ T_l solution then $ a_i <a_j $ (order of actually), a_i $ $ inserted in position i
$ $ T_2 solution $ a_j <a_k $ (actually on the order), is inserted in the position j of a_j $ * \ sum_ {i = 1} ^ {j-1} [ai <aj] $
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 inline ll read() { 5 ll x=0,f=1; char ch=getchar(); 6 for(;ch<'0'||ch>'9';ch=getchar()) 7 if(ch=='-')f=-f; 8 for(;ch>='0'&&ch<='9';ch=getchar()) 9 x=x*10+ch-'0'; 10 return x*f; 11 } 12 inline void chkmin( int &a,int b ) { if(a>b) a=b; } 13 inline void chkmax( int &a,int b ) { if(a<b) a=b; } 14 #define _ read() 15 #define ln endl 16 const ll mod=19260817; 17 const int N=300005; 18 int n,a[N]; 19 ll ans,b[N],m; 20 struct Bit { 21 ll t[N]; 22 inline int lowbit( int x ) { return x&-x; } 23 inline void add( int x,int v ) { 24 for(;x<=m;x+=lowbit(x)) 25 t[x]=(t[x]+v)%mod; 26 } 27 inline ll query( int x ) { 28 ll ans=0; 29 for(;x;x-=lowbit(x)) 30 ans=(ans+t[x])%mod; 31 return ans; 32 } 33 }t1,t2; 34 int main() { 35 n=_; 36 for( int i=1;i<=n;i++ ) 37 b[i]=a[i]=_%mod; 38 sort(b+1,b+n+1); m=unique(b+1,b+n+1)-b-1; 39 for( int i=1;i<=n;i++ ) 40 a[i]=lower_bound(b+1,b+m+1,a[i])-b; 41 for( int i=1;i<=n;i++ ) { 42 t1.add(a[i],b[a[i]]); 43 t2.add(a[i],1ll*t1.query(a[i]-1)*b[a[i]]%mod); 44 ans=(ans+1ll*b[a[i]]*t2.query(a[i]-1)%mod)%mod; 45 } 46 cout<<ans<<ln; 47 } 48 / * 49 two 'bit 50 of a value of ai in the i memory 51 of the second tree in memory ai * AJ i values (ai> AJ) 52 is * /