http://acm.hdu.edu.cn/showproblem.php?pid=5701
给出一个序列,取其中的任何一个连续的序列,该序列的数从小到大排列,待更新,,,
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int MAXN = 8005; 6 int num[MAXN]; 7 int arr[MAXN]; 8 int sum[MAXN*2]; 9 int cnt[MAXN]; 10 int main() 11 { 12 int n; 13 while(~scanf("%d",&n)) 14 { 15 for(int i = 1;i<=n;i++) 16 scanf("%d",&num[i]); 17 for(int i = 1;i<=n;i++) 18 { 19 int temp = num[i]; 20 memset(arr,0,sizeof(arr)); 21 memset(sum,0,sizeof(sum)); 22 int res = 0; 23 for(int j = i-1;j>=1;j--) 24 { 25 arr[j] = arr[j+1]+((num[j]>temp)?-1:1); 26 sum[arr[j]+n]++; 27 if(arr[j]==0) 28 res++; 29 } 30 for(int j = i+1;j<=n;j++) 31 { 32 arr[j] = arr[j-1]+((num[j]>temp)?1:-1); 33 if(sum[arr[j]+n]>0) 34 res=res+sum[arr[j]+n]; 35 if(arr[j]==0) 36 res++; 37 } 38 cnt[i] = res+1; 39 } 40 printf("%d",cnt[1]); 41 for(int i = 2;i<=n;i++) 42 printf(" %d",cnt[i]); 43 printf(" "); 44 } 45 return 0; 46 }