标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1614 Accepted Submission(s): 566
#include <stdio.h> #include <math.h> #include <iostream> #include <algorithm> #include <string.h> #include <vector> using namespace std; const int N = 40005; int a[N]; int cnt[2*N]; int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF){ int id = -1; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(a[i]==m){ id = i; } } memset(cnt,0,sizeof(cnt)); int ans = 0; int num = 0,j=0; for(int i=id-1;i>=1;i--){ ///往左计数 j++; if(a[i]<m) num++; else num--; if(num==0) ans++; cnt[N+num]++; } num = 0,j=0; for(int i=id+1;i<=n;i++){ j++; if(a[i]<m) num++; else num--; if(num==0) ans++; ans+=cnt[N-num]; } printf("%d\n",ans+1); } }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5628136.html