标签:等于 序列 pac turn getc font 元素 printf root
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。
第三个样例解释:{4}, {7,2,4}, {5,7,2,4,3}和{5,7,2,4,3,1,6}
N<=100000
//It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 100011;
int n,k,a[MAXN],tot,root;
int mp1[MAXN*2],mp2[MAXN*2];
LL ans;
inline int getint(){
int w=0,q=0; char c=getchar(); while((c<‘0‘||c>‘9‘) && c!=‘-‘) c=getchar();
if(c==‘-‘) q=1,c=getchar(); while (c>=‘0‘&&c<=‘9‘) w=w*10+c-‘0‘,c=getchar(); return q?-w:w;
}
inline void work(){
n=getint(); k=getint(); for(int i=1;i<=n;i++) a[i]=getint();
for(int i=1;i<=n;i++) if(a[i]>k) a[i]=1; else if(a[i]<k) a[i]=-1; else a[i]=0,root=i/*!!!*/;
int ZERO=100000; mp2[ZERO]=1; tot=0;
for(int i=1;i<=n;i++) {
tot+=a[i];
if(i&1) {
if(i>=root) ans+=mp2[ZERO+tot]/*!!!*/;
else mp1[ZERO+tot]++;
}
else {
if(i>=root) ans+=mp1[ZERO+tot]/*!!!*/;
else mp2[ZERO+tot]++;
}
}
printf("%lld",ans);
}
int main()
{
work();
return 0;
}
标签:等于 序列 pac turn getc font 元素 printf root
原文地址:http://www.cnblogs.com/ljh2000-jump/p/6238756.html