Uvalive 4329 Ping Pong

Source: Internet
Author: User

The title of the Great White

#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring># Include <iostream> #include <algorithm> #define LL long long#define PI 3.1415926535897932626using namespace Std;int gcd (int a, int b) {return a% b = = 0? b:gcd (b, a% b);} #define MAXN 100010#define maxd 20010int num[maxn];int val[maxd],lmin[maxd],rmin[maxd];int lowbit (int x) {return x & ( -X);}        int sum (int x) {int ret = 0;                while (x > 0) {ret + = num[x];        X-= Lowbit (x); } return ret;}                void Add (int x,int d) {while (x <= maxn) {num[x] + = D;        x + = Lowbit (x);        }}int Main () {int t,n;        scanf ("%d", &t); While (t--)                {scanf ("%d", &n);                memset (num,0,sizeof (num));                        for (int i = 1; I <= n; i++) {scanf ("%d", &val[i]);                        Add (val[i],1);                Lmin[i] = SUM (val[i]-1);                } memset (Num,0,sizeof (num));                        for (int i = n; I >= 1; i--) {Add (val[i],1);                Rmin[i] = SUM (val[i]-1);                } LL ans = 0;                for (int i = 1; I <= n; i++) ans + lmin[i] * (N-i-rmin[i]) + (I-lmin[i]-1) * rmin[i];        printf ("%lld\n", ans); } return 0;}


Uvalive 4329 Ping Pong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.