# fdu Problem 2072 Count

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 100009;

struct Arr {
int val, it;
};

Arr a[N];

int c, d, ans;

int cmp(Arr a, Arr b) {
if (a.val == b.val)
return a.it < b.it;
return a.val < b.val;
}

void bisearch(int l, int r, int x) {
if (l > r)
return;
int mid;
mid = (l + r)>>1;
if (a[mid].val > x)
bisearch(l, mid-1, x);
else if (a[mid].val < x)
bisearch(mid+1, r, x);
else {
if(a[mid].it > d)
bisearch(l, mid-1, x);
else if (a[mid].it < c)
bisearch(mid+1, r, x);
else {
if (a[mid].it >= c && a[mid].it <= d)
ans++;
bisearch(l, mid-1, x);
bisearch(mid+1, r, x);
}
}
}

int main()
{
int i, n, q, x;
while (scanf("%d %d", &n, &q) != EOF) {
for (i = 1; i <= n; ++i) {
scanf("%d", &a[i].val);
a[i].it = i;
}
sort(a+1, a + n + 1, cmp);
for (i = 0; i < q; ++i) {
scanf("%d %d %d", &c, &d, &x);
ans = 0;
bisearch(1, n, x);
printf("%d\n", ans);
}
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：fdu Problem 2072 Count 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)