G-for fans of statistics
Time limit:1000 ms
Memory limit:65536kb
64bit Io format:% I64d & % i64usubmit status
Description
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
NCities 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
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
LTo
RSuch that the trams of this city transported exactly
XPeople 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,
ITh number is the number of people transported by trams of
ITh City during last year. All numbers in the list are positive and do not exceed 10 9? 1. In the third line, the number of queries
QIs given, 0 <
Q<1, 70000. The next
QLines contain the queries. Each of them is a triple of Integers
L,
R, And
XSeparated with a space; 1 ≤
L≤
R≤
N ; 0 <
X<10 9.
Output
Output a string of Length
QIn which
ITh symbol is "1" if the answer to
ITh query is affirmative, and "0" otherwise.
Sample Input
| Input |
Output |
51234567 666666 3141593 666666 434343451 5 31415931 5 5782022 4 6666664 4 71356101 1 1234567 |
10101 |
No relationship with STL found ..... If the value is the same, add a group to judge and use the current ID and the given L and R, check whether the matching value can be obtained.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct node{ int id , k ;} p[80000];bool cmp(node a,node b){ return a.k<b.k || ( a.k==b.k && a.id < b.id );}void f(int l,int r,int x,int n){ int low = 0 , top = n-1 ; while(low <= top) { int mid = (low+top)/2 ; if( p[mid].k == x && p[mid].id >= l && p[mid].id <= r ) { printf("1"); return ; } else if( p[mid].k < x || ( p[mid].k == x && p[mid].id < l ) ) low = mid+1 ; else top = mid - 1 ; } printf("0"); return ;}int main(){ int i , n , m , l , r , x ; while(scanf("%d", &n)!=EOF) { for(i = 0 ; i < n ; i++) { scanf("%d", &p[i].k); p[i].id = i+1 ; } sort(p,p+n,cmp); scanf("%d", &m); while(m--) { scanf("%d %d %d", &l, &r, &x); f(l,r,x,n); } printf("\n"); }}