You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
560 B
C++
23 lines
560 B
C++
#include <cstdio>
|
|
const int maxn = 100010;
|
|
int n, k, p, a[maxn], l[maxn << 1], r[maxn << 1];
|
|
int main()
|
|
{
|
|
scanf("%d%d", &n, &k);
|
|
for (int i = 1, x; i <= n; i++)
|
|
{
|
|
scanf("%d", &x);
|
|
if (x < k) a[i] = -1;
|
|
if (x > k) a[i] = 1;
|
|
if (x == k) p = i;
|
|
}
|
|
for (int i = 1; i <= n; i++) a[i] += a[i - 1];
|
|
for (int i = 0; i < p; i++) l[a[i] + n]++;
|
|
for (int i = p; i <= n; i++) r[a[i] + n]++;
|
|
int ans = 0;
|
|
for (int i = n << 1; i >= 0; i--)
|
|
ans += l[i] * r[i];
|
|
printf("%d", ans);
|
|
return 0;
|
|
}
|