标签:des blog io ar os sp for on div
第三个样例解释:{4}, {7,2,4}, {5,7,2,4,3}和{5,7,2,4,3,1,6}
N<=100000
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
int n,m,pos,now;
int a[1000010];
int f[2000010];
int g[2000010];
LL ans;
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
{
a[i]=read();
if (a[i]==m)pos=i;
}
now=1000000;
for (int i=pos;i<=n;i++)
{
if (a[i]<m)now--;
if (a[i]>m)now++;
f[now]++;
}
now=1000000;
for (int i=pos;i>=1;i--)
{
if(a[i]<m)now--;
if(a[i]>m)now++;
g[now]++;
}
for (int i=1;i<2000000;i++)
{
ans+=(LL)f[i]*g[2000000-i];
}
printf("%lld\n",ans);
}
标签:des blog io ar os sp for on div
原文地址:http://www.cnblogs.com/zhber/p/4116746.html