URAL 1613. For Fans of Statistics(STL)

36 篇文章 5 订阅
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1613


1613. For Fans of Statistics

Time limit: 1.0 second
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 10 9 − 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  lr, and  x separated with a space; 1 ≤  l ≤  r ≤  n; 0 <  x < 10 9.

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

inputoutput
5
1234567 666666 3141593 666666 4343434
5
1 5 3141593
1 5 578202
2 4 666666
4 4 7135610
1 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;
}
/*
5
1234567 999999999 1000000000 666666 4343434
5
1 5 3141593
1 5 578202
2 4 666666
1 5 1000000000
1 1 1234567
*/


用代码解决这个问题The program committee of the school programming contests, which are often held at the Ural State University, is a big, joyful, and united team. In fact, they are so united that the time spent together at the university is not enough for them, so they often visit each other at their homes. In addition, they are quite athletic and like walking. Once the guardian of the traditions of the sports programming at the Ural State University decided that the members of the program committee spent too much time walking from home to home. They could have spent that time inventing and preparing new problems instead. To prove that, he wanted to calculate the average distance that the members of the program committee walked when they visited each other. The guardian took a map of Yekaterinburg, marked the houses of all the members of the program committee there, and wrote down their coordinates. However, there were so many coordinates that he wasn't able to solve that problem and asked for your help. The city of Yekaterinburg is a rectangle with the sides parallel to the coordinate axes. All the streets stretch from east to west or from north to south through the whole city, from one end to the other. The house of each member of the program committee is located strictly at the intersection of two orthogonal streets. It is known that all the members of the program committee walk only along the streets, because it is more pleasant to walk on sidewalks than on small courtyard paths. Of course, when walking from one house to another, they always choose the shortest way. All the members of the program committee visit each other equally often. Input The first line contains the number n of members of the program committee (2 ≤ n ≤ 105). The i-th of the following n lines contains space-separated coordinates xi, yi of the house of the i-th member of the program committee (1 ≤ xi, yi ≤ 106). All coordinates are integers. Output Output the average distance, rounded down to an integer, that a member of the program committee walks from his house to the house of his colleague.
最新发布
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值