2072Count(foj)

来源:互联网 发布:dota2天梯淘宝买账号 编辑:程序博客网 时间:2024/05/01 18:19
2072 <wbr>Count <wbr>(foj) Problem2072 Count

Accept:110    Submit:295
Time Limit: 1000mSec    MemoryLimit : 65536 KB

2072 <wbr>Count <wbr>(foj) 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.

2072 <wbr>Count <wbr>(foj) 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).

2072 <wbr>Count <wbr>(foj) Output

For each queryoutput one line, the number of occurrences of x.

2072 <wbr>Count <wbr>(foj) SampleInput

3 2 
1 2 1 
1 2 1 
1 3 1

2072 <wbr>Count <wbr>(foj) SampleOutput

1 2

2072 <wbr>Count <wbr>(foj) Source

FOJ有奖月赛-2012年3月


 

#include<stdio.h>#include <math.h>#include <algorithm>#include <iostream>#include <string.h>#define MAXN 100005using 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);        }    }}


0 0
原创粉丝点击