Problem 2072 Count
来源:互联网 发布:淘宝联盟 百度百科 编辑:程序博客网 时间:2024/06/05 23:52
Problem 2072 Count
Accept: 167 Submit: 514
Time Limit: 1000 mSec Memory Limit : 65536 KB
Problem Description
Given an array of positive integers and m queries.Each query contains i, j, x, output the number of occurrences of x into the subarray Ai,Ai+1...,Aj.
Input
There are several cases. The first line of each case contains tow integers n, q(1<=n,q<=100000), indicating the array length and the number of queries.The second line contains n positive integers ai(1 <= ai <= 100000).Next q lines contain three positive integers i,j,x(1<=i<=j<=n).
Output
For each query output one line, the number of occurrences of x.
Sample Input
3 21 2 11 2 11 3 1
Sample Output
1
2
代码如下:
#include <cstdio>#include <algorithm>#include <vector>#define Max 100000+5using namespace std;int a[Max];vector< int > c[Max];void solve(int i, int j, int x){ if(c[x].size()==0){ printf("0\n"); return; } int d = upper_bound(c[x].begin(),c[x].end(),j)-lower_bound(c[x].begin(),c[x].end(),i);// upper_bound返回地址,区间为[0,j]-[0,i) printf("%d\n",d); return;}int main(){ int n, q, sum; int i, j, k, x; while( ~scanf("%d%d",&n,&q) ){ for(i=0; i<n; i++) scanf("%d",&a[i]); for(i=0; i<n; i++) c[a[i]].clear(); for(i=0; i<n; i++) c[a[i]].push_back(i); for(k=0; k<q; k++){ scanf("%d%d%d",&i, &j, &x); solve(i-1, j-1, x); } }}
0 0
- fdu Problem 2072 Count
- Problem 2072 Count
- Problem - 3777 Page Count
- Pop Count Problem
- HDU 2575 Count Problem (水题)
- A+B Problem (Case Count)
- A+B Problem (Case Count)
- A+B problem(case count)
- hdu 2575 Count Problem (水)
- WOJ:Problem 1157 - Easy to Count
- Pop Count Problem (二进制数中1的个数)
- FZU/FOJ 2105 Problem 2105 Digits Count 成段更新
- 2072Count(foj)
- Count
- COUNT
- count
- Count
- count
- fatal error LNK1168: cannot open Debug/opreat.exe for writing
- Bitmap Allocation与重用
- 浏览器web播放rtsp视频流解决方案(chrome/IE/firefox/360等)
- 在vs10中处理多线程MFC遇到的问题
- solr查询语法
- Problem 2072 Count
- Linux下的查找命令使用指导
- Baidu Map开发示例
- 【手势交互】6. 微动VID
- HDU 3336 Count the string(KMP)
- HDU 3046 Pleasant sheep and big big wolf(最小割)
- Hibernate ehcache配置二级缓存
- iOS int long NSInteger 入门与兼容问题讲解,让你秒懂
- 配置文件工具类