2072Count(foj)

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值