Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //In the Name of Allah Most Gracious, Most Merciful//
- /*If you want something you've never had, you have to do something you never did.*/
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define ll long long
- #define pii pair<ll,ll>
- #define pll pair<ll,ll>
- #define MaxN 201007
- #define INF 1e9
- #define INFL 1e18
- #define PI acos(-1)
- #define mp make_pair
- //const ll fx[]= {+1,-1,+0,+0};
- //const ll fy[]= {+0,+0,+1,-1};
- //const ll fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
- //const ll fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
- //const ll fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
- //const ll fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
- ll gcd(ll a, ll b)
- {
- return b ? gcd(b, a%b) : a;
- }
- ll bigmod(ll b,ll p,ll m)
- {
- ll res=1LL%m;
- ll x=b%m;
- while(p)
- {
- if( p & 1LL )res=(res*x) % m;
- x=(x*x)%m;
- p >>=1LL;
- }
- return res;
- }
- ll BIT[MaxN*10];
- ll arr[MaxN];
- ll n;
- ll lmt;
- void update(ll pos,ll val)
- {
- for( ;pos<=(lmt);pos+= pos & -pos)
- {
- BIT[pos]+=val;
- }
- }
- ll query(ll pos)
- {
- ll sum=0;
- for(;pos>0;pos-= pos&-pos)
- {
- sum+=BIT[pos];
- }
- return sum;
- }
- void blurryface()
- {
- scanf("%lld",&n);
- ll mx=0;
- ll ans=0;
- for(ll i=1;i<=n;i++)
- {
- scanf("%lld",&arr[i]);
- mx=max(mx,arr[i]);
- }
- lmt=mx+10;
- for(int i=1;i<=n;i++)
- {
- ans+=query(arr[i]-1);
- update(arr[i],arr[i]);
- }
- printf("%lld\n",ans);
- int val=log2(mx)+1;
- int lmt=(1<<val);
- // cout<<lmt<<endl;
- for(int i=0;i<=min(lmt,1000000);i++)
- {
- BIT[i]=0;
- }
- }
- int main()
- {
- // #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- // #endif
- // ios_base::sync_with_stdio(false);
- // cin.tie(NULL);
- ll t;
- cin>>t;
- while(t--)
- {
- blurryface();
- }
- //#ifdef LOCAL_DEFINE
- // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- // #endif
- ///Before submit=>
- /// *check for lleger overflow,array bounds
- /// *check for n=1
- }
Advertisement
Add Comment
Please, Sign In to add comment