URAL 1613. For Fans of Statistics(STL 数学啊 )

题目链接: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 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 lr, 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

input output
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
*/
时间: 2024-10-13 06:25:01

URAL 1613. For Fans of Statistics(STL 数学啊 )的相关文章

Ural 1613 For Fans of Statistics(vector应用)

题目: For Fans of Statistics Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 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 th

URAL 1613 For Fans of Statistics

题意:就是给了你n个数字,他们的编号为1到n,然后接下来有q个询问,每次询问有 l,r,x, 就是问你 是否 在编号区间[l,r]内有数字X出现过,有就是1,无就是0,最后一起输出来 输入其实数字是有重复的,所以先用map离散化,然后再用map跟vector 的邻接表连接,讲编号放入邻接表里面,并升序排序,然后询问的时候直接二分查找编号,是否存在就可以了,手写的二分 一直WA,莫名其妙,改用Lower_bound就过了 int n; map<string ,int>mark,mp; vecto

timus 1613. For Fans of Statistics【该题超时的代码记录】

该题的意思:按编号递增给出n(0<n<70000)个点的值(点的编号从1~n),给出m(1<=m<70000)条查询数据 数据输入格式为a b c(从编号a到编号b之间是否有值是为c的,如果有则返回1,没有返回0 具体的意思可以进链接: http://acm.timus.ru/problem.aspx?space=1&num=1613 这里只给出超时的代码(可能这道题C++解决真的得用上STL): case 1: /* 树的子节点最多三个 左边的子节点(left)表示小于根

Ural 1613-For Fans of Statistics(vector)

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

STL--G - For Fans of Statistics(两个判断条件-二分)

G - For Fans of Statistics Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Have you ever thought about how many people are transported by trams every year in a city with a ten-million population

For Fans of Statistics

For Fans of Statistics Time limit: 1.0 secondMemory 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 th

URAL 1727. Znaika&#39;s Magic Numbers(数学 vector)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1727 1727. Znaika's Magic Numbers Time limit: 0.5 second Memory limit: 64 MB Znaika has many interests. For example, now he is investigating the properties of number sets. Znaika writes down some set

ural 2029 Towers of Hanoi Strike Back (数学找规律)

ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺塔问题,给定一串只有(A, B, C)的字符串(A代表在第一根柱子,B代表在第二根柱子,C代表在第三根柱子),从前往后代表盘子的大小,第 i 个字母代表di i 个盘子在某个柱子上.问移动给定字母状态的盘子最少需要多少步. 思路:首先,从后往前看(最大的盘子),如果不在当前柱子上,那么移动到目标柱子需要 2

ural 2032 Conspiracy Theory and Rebranding (数学水题)

ural 2032  Conspiracy Theory and Rebranding 链接:http://acm.timus.ru/problem.aspx?space=1&num=2032 题意:给定一个三角形的三条边 (a, b, c),问是否可放在二维坐标,使得3个顶点都是整数点.若可以,输出任意一组解,否则,输出 -1. 思路:暴力枚举:以 a 为半径做第一象限的 1/4 圆, 以 b 为半径做 一.四 象限的半圆,存储整数点的解,暴力枚举 a 整数点与 b 整数点是否构成长度为 c