标签:
注意细节啊。。。。典型的乱搞。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define maxn 100500 using namespace std; long long n,a[maxn],mx[maxn],mi[maxn],cnta[maxn][3],cntb[maxn][3],regis[4],b,rec; long long num[maxn],kk=0,ans=0; long long vv(long long x) { if (x<0) return -x; return x; } int main() { scanf("%lld%lld",&n,&b); for (long long i=1;i<=n;i++) { scanf("%lld",&a[i]); if (a[i]>b) {mx[i]=mx[i-1]+1;mi[i]=mi[i-1];} else if (a[i]<b) {mx[i]=mx[i-1];mi[i]=mi[i-1]+1;} else {rec=i;mx[i]=mx[i-1];mi[i]=mi[i-1];} } for (long long i=1;i<=n;i++) { if (i<=rec-1) { num[i]=(mx[rec-1]-mx[i-1])-(mi[rec]-mi[i-1]); if (vv(num[i])>kk) kk=vv(num[i]); } else if (i>=rec+1) { num[i]=(mx[i]-mx[rec])-(mi[i]-mi[rec]); if (vv(num[i])>kk) kk=vv(num[i]); } } for (long long i=1;i<=rec-1;i++) { if (num[i]<0) cntb[-num[i]][1]++; else if (num[i]>0) cnta[num[i]][1]++; else regis[1]++; } for (long long i=rec+1;i<=n;i++) { if (num[i]<0) cntb[-num[i]][2]++; else if (num[i]>0) cnta[num[i]][2]++; else regis[2]++; } for (long long i=1;i<=kk;i++) { ans+=cnta[i][1]*cntb[i][2]; ans+=cntb[i][1]*cnta[i][2]; } ans=ans+regis[1]*regis[2]+regis[1]+regis[2]+1; printf("%lld\n",ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/ziliuziliu/p/5350628.html