标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2985 | Accepted: 1104 |
Description
Input
Output
Sample Input
1 3 1 2 3
Sample Output
1
Source
写这题顺便练了一下重载运算符
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdlib> 5 #include <queue> 6 #include <stack> 7 #include <vector> 8 #include <iostream> 9 #include "algorithm" 10 using namespace std; 11 typedef long long LL; 12 const int MAX=100005; 13 int T; 14 int n; 15 int c[MAX]; 16 struct Peo{ 17 int name; 18 int sco; 19 bool operator <(const Peo &zt) const { 20 if (sco!=zt.sco) 21 return sco<zt.sco; 22 return name<zt.name; 23 } 24 }stu[MAX]; 25 void add(int x,int y){ 26 for (;x<=n;c[x]+=y,x+=(x&-x)); 27 } 28 LL search(int x){ 29 LL an(0); 30 for (;x>0;an+=c[x],x-=(x&-x)); 31 return an; 32 } 33 int main(){ 34 freopen ("tennis.in","r",stdin); 35 freopen ("tennis.out","w",stdout); 36 int i,j; 37 scanf("%d",&T); 38 while (T--){ 39 scanf("%d",&n); 40 for (i=1;i<=n;i++) 41 {scanf("%d",&stu[i].sco); 42 stu[i].name=i; 43 } 44 sort(stu+1,stu+n+1); 45 memset(c,0,sizeof(c)); 46 LL x1,x2,x3,x4,ans(0); 47 add(stu[1].name,1); 48 for (i=2;i<=n;i++) 49 {x1=search(stu[i].name-1); 50 x2=stu[i].name-1-x1; 51 x3=search(n)-search(stu[i].name); 52 x4=n-stu[i].name-x3; 53 ans=ans+x1*x4+x2*x3; 54 add(stu[i].name,1); 55 } 56 printf("%lld\n",ans); 57 } 58 return 0; 59 }
标签:
原文地址:http://www.cnblogs.com/Michaelzzn/p/5764438.html