poj3928 Ping Pong tree-like array

Source: Internet
Author: User

http://poj.org/problem?id=3928

Ping Pong
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2087 Accepted: 798

Description

N (3<=n<=20000) Ping pong players live along a West-east street (consider the street as a line segment). Each player has a unique skill rank. To improve their skill rank, they often compete with each other. If-Players want to compete, they must choose a referee among other ping pong players and hold the game in the referee ' S house. For some reason, the contestants can ' t choose a referee whose skill rank is higher or lower than both of theirs. The contestants has to walk to the referee's house, and because they is lazy, they want to make their total walking dist Ance no more than the distance between their houses. Of course all players live in different houses and the position of their houses is all different. If the referee or any of the contestants are different, we call both games different. Now are the problem:how many different games can being held in this ping Pong street?

Input

The first line of the input contains a integer T (1<=t<=20), indicating the number of test cases, followed by T line s each of the which describes a test case.
Every test case consists of N + 1 integers. The first integer is N, the number of players. Then N distinct integers a1, A2 ... an follow, indicating the skill rank of all player, in the order of West to east. (1 <= AI <= 100000, i = 1 ... N).

Output

For each test case, output a single line contains an integer with the total number of different games.

Sample Input

1 3 1) 2 3

Sample Output

1

Source

Beijing 2008
Test instructions: Each person has a competency value, 22 can match must have a referee, the referee ability value must be in between two person position also must be between two person, ask different race arrangement how many kinds. Simple problem: There is a sentence inside, now is the problem, blurt out the excavator technology which strong 233 .... Think of the enumeration of referees can be, ask each person as the referee's plan how many kinds, is to ask how many in front of the larger than it (small), behind how many larger than it (small) can. And the same as the number of reverse order of the tree-like array to engage in any way .... Code:
/** * @author neko01 *///#pragma comment (linker, "/stack:102400000,102400000") #include <cstdio> #include < cstring> #include <string.h> #include <iostream> #include <algorithm> #include <queue># Include <vector> #include <cmath> #include <set> #include <map>using namespace Std;typedef long Long LL; #define MIN3 (a,b,c) min (a,min (b,c)) #define MAX3 (A,B,C) max (A,max (b,c)) #define PB Push_back#define MP (A, b) make_ Pair (A, B) #define CLR (a) memset (a,0,sizeof a) #define CLR1 (a) memset (a,-1,sizeof a) #define DBG (a) printf ("%d\n", a) typedef pair<int,int> PP;CONST Double Eps=1e-9;const double Pi=acos ( -1.0); const int Inf=0x3f3f3f3f;const LL inf= (( (LL) 1) <<61) +5;const int n=20005;const int m=100005;int bit[m];int f[n];int a[n];    ll sum (int i) {ll s=0;        while (i>0) {s+=bit[i];    i-=i&-i; } return s;}        void Add (int i,int x) {while (i<=m) {bit[i]+=x;    i+=i&-i;    }}int Main () {int t; ScanF ("%d", &t);        while (t--) {int n;        CLR (bit);        scanf ("%d", &n);            for (int i=0;i<n;i++) {scanf ("%d", &a[i]);            F[i]=sum (A[i]);        Add (a[i],1);        } CLR (bit);        LL ans=0;            for (int i=n-1;i>=0;i--) {int x=sum (a[i]);            int y=n-i-1-x;            ans+= (LL) (f[i]*y);            ans+= (LL) ((I-f[i]) *x);        Add (a[i],1);    } printf ("%lld\n", ans); } return 0;}


poj3928 Ping Pong tree-like array

Related Article

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.