For Fans of Statistics——vector

来源:互联网 发布:农业银行软件官方下载 编辑:程序博客网 时间:2024/06/05 01:55
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 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 Input

inputoutput
51234567 666666 3141593 666666 434343451 5 31415931 5 5782022 4 6666664 4 71356101 1 1234567
10101

题意:有5各城市,每个城市的人口用表格表现出来,接下来有5组测试数据,1,5表示用1城市到5城市的人数有没有后面出现的。有可能两个不同的城市人数是相同的。
解析:利用哈希的思想,对每个城市的人口哈希,有相同的借助链表往后接。具体解析看代码:
#include <iostream>#include <algorithm>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#define MAX 100007using namespace std;int a[700100];struct node{    int id;//表示城市的代号    int zhi;//表示城市的人口数};vector<node> v[100007];//声明一个node型的容器int main(){    int n,m,i,j,k,x,y,z,mid;    struct node c;    scanf("%d",&n);    for(i = 1;i <= n;i++)    {        scanf("%d",&a[i]);        c.id = i;        c.zhi = a[i];        v[a[i]%MAX].push_back(c);//将人口哈希,借助v.push_back在最后加入数据    }    scanf("%d",&m);    for(i = 1;i <= m;i++)    {        scanf("%d%d%d",&x,&y,&z);        if(a[x] == z || a[y] == z)        {            printf("1");            continue;        }        int l = v[z%MAX].size();//判断相同人口的城市的数目,并一一遍历,查找符合条件的城市        int bj = 0;        for(j = 0;j < l;j++)        {            if(v[z%MAX][j].zhi == z && v[z%MAX][j].id > x && v[z%MAX][j].id < y)            {                bj = 1;                break;            }        }        if(bj == 1)            printf("1");        else            printf("0");    }    printf("\n");    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在店面住隔壁商铺一直放音乐怎么办 淘宝卖家把买家评论删了怎么办 淘宝店铺上当顾客说再看看怎么办 车辆摇号申请说手机号注册怎么办 如果在微商手上买到假东西怎么办? 登陆微信显示版本过低该怎么办 苹果手机登陆微信版本过低怎么办 微信版本过低无法登怎么办录 登入微信显示版本过低登不上怎么办 微信版本过低无法使用小程序怎么办 小米4s微信反应很慢怎么办 手机网页缓存的视频播放不了怎么办 ios微信占用内存太大了怎么办 爱奇艺离线视频显示暂无缓存怎么办 酷狗音乐不小心删了歌怎么办 苹果手机里系统占的空间太大怎么办 酷狗音乐歌单里有不同步的歌怎么办 一插耳机手机自带音乐就响怎么办 清理空间时不小心把图片删了怎么办 手机中清理误把照片删了怎么办 清理手机文件把照片给删了怎么办 清理手机不小心把照片删了怎么办 金牛不回微信我也不理他他会怎么办 华为手机微信文件自动删除怎么办 微信清理数据后不能登录了怎么办 k歌占内存又不想删除歌曲怎么办 把所有商品放在一起做链接怎么办 微信解冻短信验证总显示失败怎么办 淘金币能抵钱商家拿了淘金币怎么办 真实订单被系统判定虚假交易怎么办 淘宝买家号疑似虚假交易违规怎么办 货品交易一方收了定金违约了怎么办 饿了么店铺收到差评怎么办 淘宝顾客退款没成功给差评怎么办 身份证绑定了淘宝注册支付宝怎么办 把钱转错到支付宝账号被扣了怎么办 网上买东西收到信息被删掉了怎么办 表格在手机上显示不出来怎么办? 电子表格中复制后没有虚线框怎么办 word中页眉页脚横线短了怎么办 亿图图示画的图不显示怎么办