标签:
代码:
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <queue> 7 #include <map> 8 #include <set> 9 #include <vector> 10 #include <iostream> 11 using namespace std; 12 13 const double pi=acos(-1.0); 14 double eps=0.000001; 15 16 int aa[8008]; 17 int les[8008]; 18 int big[8008]; 19 int has[8008+8000]; 20 int main() 21 { 22 23 24 int n; 25 while(scanf("%d",&n)!=EOF) 26 { 27 int i,j; 28 for (i=1; i<=n; i++) 29 { 30 scanf("%d",&aa[i]); 31 } 32 for (i=1; i<=n; i++) 33 { 34 long long ans=0; 35 memset(has,0,sizeof has); 36 les[i]=0; 37 big[i]=0; 38 for (j=i-1; j>=1; j--) 39 { 40 if (aa[j]<aa[i]) les[j]=les[j+1]+1; 41 else les[j]=les[j+1]; 42 if (aa[j]>aa[i]) big[j]=big[j+1]+1; 43 else big[j]=big[j+1]; 44 } 45 for (j=i+1; j<=n; j++) 46 { 47 if (aa[j]<aa[i]) les[j]=les[j-1]+1; 48 else les[j]=les[j-1]; 49 if (aa[j]>aa[i]) big[j]=big[j-1]+1; 50 else big[j]=big[j-1]; 51 } 52 for (j=i+1; j<=n; j++) 53 { 54 int need_big=les[j]-big[j]; 55 has[need_big+8000]++; 56 } 57 has[0+8000]++; 58 for (j=1; j<i; j++) 59 { 60 ans+=has[big[j]-les[j]+8000]; 61 } 62 ans+=has[0+8000]; 63 if (i>1)printf(" "); 64 printf("%I64d",ans); 65 } 66 67 printf("\n"); 68 69 70 } 71 72 return 0; 73 74 }
标签:
原文地址:http://www.cnblogs.com/wangmengmeng/p/5517530.html