# 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;
}


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

## Google中国2015校园招聘笔试Round D APAC Test Problem B. GBus count

Problem There exists a straight line along which cities are built. Each city is given a number s...

## 2017年上海金马五校程序设计竞赛 Problem C : Count the Number

2017年上海金马五校程序设计竞赛 Problem C : Count the NumberProblem C : Count the NumberTime Limit: 3 sDescription...

## phpweb 2072

• 2013-05-10 14:21
• 2.64MB
• 下载

## RFFC2072 datasheet

• 2011-06-10 10:13
• 2.03MB
• 下载

## cbm2072量产工具V1.rar

• 2010-07-11 12:23
• 573KB
• 下载

## HDU-2072(单词数)都是坑啊

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)