title Link: http://acm.timus.ru/problem.aspx?space=1&num=1613
1613. For Fans of Statisticstime limit:1.0 second
Memory limit:64 MB
Ever thought about how many people is transported by trams every year in a city with a ten-million population wh Ere one in three citizens uses tram twice a day? Assume that there is
NCities with trams on the planet Earth. Statisticians counted for each of them, the number of people transported by trams during. 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 is able to answer quickly a query of the following type:is there among th E Cities with numbers from
LTo
RSuch the trams of this city transported exactly
xPeople during last year. You must implement this module of the system. Inputthe 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. All numbers in the list is positive and do not exceed 109? 1. The third line, the number of queries
Qis given, 0 <
Q < 70000. The next
Qlines contain the queries. Each of the them is a triple of integers
L,
R, and
xseparated with a space; 1≤
l ≤
r ≤
n ; 0 <
x< 109. Outputoutput a string of length
Qin which the
ITh symbol is ' 1 ' if the answer to the
ITh query is affirmative, and "0" otherwise. Sample
input |
Output |
51234567 666666 3141593 666666 434343451 5 31415931 5 5782022 4 6666664 4 71356101 1 1234567 |
10101 |
Test instructions
Given L, R, Num, find out if there is a number num in L to R;
The code is as follows:
#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*/
URAL 1613. For Fans of Statistics (STL math AH)