For Fans of Statistics

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

分析:map+二分;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e5+10;
const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t;
string ans;
map<int,set<int> >a;
set<int>::iterator it;
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n)scanf("%d",&j),a[j].insert(i);
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int l,r,p;
        scanf("%d%d%d",&l,&r,&p);
        if((it=a[p].lower_bound(l))!=a[p].end()&&*it<=r)
            ans+=‘1‘;
        else ans+=‘0‘;
    }
    cout<<ans<<endl;
    //system("pause");
    return 0;
}
时间: 2024-10-06 13:20:15

For Fans of Statistics的相关文章

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 whe

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

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

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

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

题意:就是给了你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

苎蜗矩旁乓vzrjk1ct7so

新华社瓦莱塔4月10日电(记者李拯宇 李佳)全国政协主席俞正声10日在前往非洲三国进行正式友好访问途中过境马耳他,在瓦莱塔会见马耳他议长法鲁贾. 俞正声说,中马保持长期友好关系,政治上相互信任,经济上密切合作,人文交流不断深化.中方感谢马方在中国撤侨行动中给予的支持和帮助.中方愿同马方一道,落实两国领导人达成的共识,弘扬中马传统友好,拓展在科技.渔业.旅游等领域互利合作,打造合作新亮点.中国全国政协愿与马耳他议会和社会各界保持密切交往,加强治国理政经验交流,为两国扩大务实合作营造良好环境,共同促

苷死釉问叵q3194ge0xrduee6743e

新华社瓦莱塔4月10日电(记者李拯宇 李佳)全国政协主席俞正声10日在前往非洲三国进行正式友好访问途中过境马耳他,在瓦莱塔会见马耳他议长法鲁贾. 俞正声说,中马保持长期友好关系,政治上相互信任,经济上密切合作,人文交流不断深化.中方感谢马方在中国撤侨行动中给予的支持和帮助.中方愿同马方一道,落实两国领导人达成的共识,弘扬中马传统友好,拓展在科技.渔业.旅游等领域互利合作,打造合作新亮点.中国全国政协愿与马耳他议会和社会各界保持密切交往,加强治国理政经验交流,为两国扩大务实合作营造良好环境,共同促

使用Statistics命令查看Netapp存储实时性能统计数据

Cluster-mode下,引入了新的命令行工具,可以查看详细的存储系统性能指标,在进行存储系统诊断时候尤其有用. 注意:使用该命令需要进入高级模式,SSH登录存储CLI环境之后,执行命令:set  –privilege  advanced.参考下图1: 图1 命令使用方法 总览 可以使用命令statistics show-periodic查看当前系统实时的性能指标概览. 图2 样本收集 也可以使用命令statistics start |stop 收集一段时间内的性能参数,然后通过statist