![2072 <wbr>Count <wbr>(foj) 2072 <wbr>Count <wbr>(foj)](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
Accept:110 Submit:295
Time Limit: 1000mSec MemoryLimit : 65536 KB
ProblemDescription
Given an arrayof positive integers and m queries.Each query contains i, j, x,output the number of occurrences of x into the subarrayAi,Ai+1...,Aj.
Input
There are several cases. The first line of each case containstow integers n, q(1<=n,q<=100000),indicating the array length and the number of queries.The secondline contains n positive integers ai(1 <= ai<= 100000).Next q lines contain three positiveintegersi,j,x(1<=i<=j<=n).
Output
For each queryoutput one line, the number of occurrences of x.
SampleInput
3 2
1 2 1
1 2 1
1 3 1
SampleOutput
1 2
Source
FOJ有奖月赛-2012年3月
#include<stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#define MAXN 100005
using namespace std ;
int hashnum[MAXN][100],idx[MAXN];
int main() {
int n,query;
while(~scanf("%d%d",&n,&query)){
memset(idx,0,sizeof(idx));
int tmp,fr,to,cont = 0;;
for(int i = 0;i<n;i++) {
scanf("%d",&tmp);
hashnum[tmp][idx[tmp] ++] = i + 1;
//cout<<tmp<<""<<hashnum[tmp][idx[tmp]-1]<<endl;
}
for(int i = 0;i<query;i++) {
scanf("%d%d%d",&fr,&to,&tmp);
cont = 0;
for(int j = 0;j<idx[tmp];j++) {
//cout<<tmp<<""<<hashnum[tmp][j]<<endl;
if(hashnum[tmp][j] >= fr&& hashnum[tmp][j]<= to) {
cont ++;
}
else if(hashnum[tmp][j] > to){
break;
}
}
printf("%d\n",cont);
}
}
}