URAL 1613. For Fans of Statistics(STL 数学啊 )
来源:互联网 发布:苹果windows系统截屏 编辑:程序博客网 时间:2024/05/16 23:54
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1613
input output
1613. For Fans of Statistics
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Have you ever thought about how many people are transported by trams every year in a city with a ten-million population where one in three citizens uses tram twice a day?
Assume that there are n cities with trams on the planet Earth. Statisticians counted for each of them the number of people transported by trams during last year. They compiled a table, in which cities were sorted alphabetically. Since city names were inessential for statistics, they were later replaced by numbers from 1 to n. A search engine that works with these data must be able to answer quickly a query of the following type: is there among the cities with numbers from l to r such that the trams of this city transported exactly x people during last year. You must implement this module of the system.
Input
The first line contains the integer n, 0 < n < 70000. The second line contains statistic data in the form of a list of integers separated with a space. In this list, the ith number is the number of people transported by trams of the ith city during last year. All numbers in the list are positive and do not exceed 109 − 1. In the third line, the number of queries q is given, 0 < q < 70000. The next q lines contain the queries. Each of them is a triple of integers l, r, and x separated with a space; 1 ≤ l ≤ r ≤ n ; 0 < x < 109.
Output
Output a string of length q in which the ith symbol is “1” if the answer to the ith query is affirmative, and “0” otherwise.
Sample
51234567 666666 3141593 666666 434343451 5 31415931 5 5782022 4 6666664 4 71356101 1 1234567
10101
题意:
给出l, r, num,查找l到r中是否有数字 num;
代码如下:
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <vector>#include <set>#include <map>#include <iostream>#include <algorithm>using namespace std;map <int, vector<int> > mm;int main(){ int n; while(~scanf("%d",&n)) { int tt; for(int i = 1; i <= n; i++) { scanf("%d",&tt); mm[tt].push_back(i); } int m; scanf("%d",&m); int l, r; int ans[70017]; vector<int> ::iterator iter; for(int i = 0; i < m; i++) { scanf("%d%d%d",&l,&r,&tt); int len = mm[tt].size(); if(len == 0) { ans[i] = 0; continue; } iter = lower_bound(mm[tt].begin(), mm[tt].end(),l); if(iter == mm[tt].end() || *iter > r) { ans[i] = 0; } else { ans[i] = 1; } } for(int i = 0; i < m; i++) { printf("%d",ans[i]); } printf("\n"); } return 0;}/*51234567 999999999 1000000000 666666 434343451 5 31415931 5 5782022 4 6666661 5 10000000001 1 1234567*/
1 0
- URAL 1613. For Fans of Statistics(STL 数学啊 )
- URAL 1613. For Fans of Statistics 二分+stl
- ural 1613. For Fans of Statistics
- Ural 1613. For Fans of Statistics
- ural 1613. For Fans of Statistics
- For Fans of Statistics(STL)
- Ural 1613 For Fans of Statistics(vector应用)
- Ural 1613 For Fans of Statistics
- Ural 1613-For Fans of Statistics(vector)
- URAL 1613 For Fans of Statistics
- 1613. For Fans of Statistics
- STL--G - For Fans of Statistics(两个判断条件-二分)
- For Fans of Statistics——vector
- timus 1613. For Fans of Statistics【该题超时的代码记录】
- URAL 2005. Taxi for Programmers (最短路 数学啊)
- URAL 1120. Sum of Sequential Numbers (数学)
- URAL 1515. Cashmaster (数学啊 )
- URAL 1885. Passenger Comfort(数学啊 )
- ThinkPHP笔记------重定向
- 八连阳后将迎来暴风雨
- HDU-2519 新生晚会 组合数
- POJ Agri-Net
- SQLCODE=-968,SQLSTATE=57011
- URAL 1613. For Fans of Statistics(STL 数学啊 )
- 全排列算法-Java
- 消除VC 中的 Browser Info 警告
- 电信141班作业,9*9乘法表
- 浮点数在内存中的存储规则
- spark:配置Idea开发环境--14
- python在win7 下的安装已经环境变量的设置
- Get与Post提交与中文乱码解决
- 进程总结