2072Count(foj)
来源:互联网 发布:dota2天梯淘宝买账号 编辑:程序博客网 时间:2024/05/01 18:19
Accept:110 Submit:295
Time Limit: 1000mSec MemoryLimit : 65536 KB
Time Limit: 1000mSec
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 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
- 2072Count(foj)
- Foj 1559 Count Zeros
- FOJ 1559 Count Zeros
- FZU/FOJ 2105 Problem 2105 Digits Count 成段更新
- [FOJ 2105][Vjudge 35179] Digits Count [线段树]
- FOJ月赛被虐
- FOJ 1036
- foj 1689
- FOJ 1615
- foj 1075
- Foj 1382
- foj 1627
- foj 1759
- foj 1607
- foj 1753
- foj 1411
- foj 1402
- foj 2027
- Dijkstra算法
- 二分图——匈牙利算法
- Luke'family
- 结构体排序
- linux磁盘管理二之磁盘配额
- 2072Count(foj)
- 1002 hdu (高精度)
- Common Subsequence(hdu 1159)
- 最长公共子序列
- Dijkstra算法(单源最短路径)
- hdu(Number Sequence 1711)kmp
- hdu1025(最长上升子序列)
- Monkey and Banana hdu(1069)
- 报错:Link of class 'Lcom/.../PersistentConnectionListener;' failed ...VFY: unable to resolve new-insta