Advertisement
Saleh127

CF GYM 104168 D2

Mar 22nd, 2023
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. /***
  2.  created: 2023-03-02-02.24.59
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define all(we) we.begin(),we.end()
  13. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  14. #define nl '\n'
  15.  
  16. int main()
  17. {
  18.     ios_base::sync_with_stdio(0);
  19.     cin.tie(0);
  20.     cout.tie(0);
  21.  
  22.  
  23.  
  24.     test
  25.     {
  26.         ll n,m,i,j,k,l,mod=1e9+7;
  27.  
  28.  
  29.         cin>>n;
  30.  
  31.         ll p[n+4]={0},s[n+4]={0};
  32.         ll a[n+4];
  33.         for(i=1;i<=n;i++)
  34.         {
  35.             cin>>a[i];
  36.             p[i]=p[i-1]+a[i];
  37.             p[i]%=mod;
  38.         }
  39.  
  40.         for(i=n-1;i>0;i--)
  41.         {
  42.             m=(a[i]*(p[n]-p[i]+mod)%mod)%mod;
  43.             s[i]=s[i+1]+m;
  44.             s[i]%=mod;
  45.         }
  46.         l=0;
  47.  
  48.         for(i=1;i<n-1;i++)
  49.         {
  50.             l+=(a[i]*s[i+1])%mod;
  51.             l%=mod;
  52.         }
  53.  
  54.         cout<<l<<nl;
  55.  
  56.  
  57.     }
  58.  
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement