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+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}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,,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+='';
else ans+='';
}
cout<<ans<<endl;
//system("pause");
return ;
}

ural1613 For Fans of Statistics的更多相关文章

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

    G - For Fans of Statistics Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & ...

  2. 1613. For Fans of Statistics(STL)

    1613 高端的东西 lower_bounder 函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置.如果所有元素都小于val,则返 ...

  3. ural 1613 For Fans of Statistics

    #include <cstdio> #include <cstring> #include <map> #include <vector> #inclu ...

  4. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

  5. AC题目简解-数据结构

    A - Japan  POJ 3067 要两条路有交叉,(x1,y1)(x2,y2)那么需要满足:(x1-x2)*(y1-y2)<0判断出这是求逆序的问题 树状数组求逆序,先通过自定义的比较器实 ...

  6. ABBA BABA statistics

    The ABBA BABA statistics are used to detect and quantify an excess of shared derived alleles, which ...

  7. SQL Server 的 Statistics 簡介

    當你要清空「資料表(table)」,或倒入大量「資料(data;record)」,或公司「資料庫(database)」改用新版本要資料大搬家…等情形,不只是要重建「索引(index)」,還應要重建或更 ...

  8. SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色 SP2-0611: 启用 STATISTICS 报告时出错

    援引: SP2-0618: 无法找到会话标识符.启用检查 PLUSTRACE 角色 SP2-0611: 启用 STATISTICS 报告时出错 问题描述及解决方法: SQL*Plus: Release ...

  9. Spark MLlib 之 Basic Statistics

    Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下: 1.Summary statistics 对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法 ...

随机推荐

  1. http response

    关键词:http response header 下载文件 案例1: 访问某个链接,然后下载文件,需要特定的http头: header("Content-Type:application/z ...

  2. Google Gson的使用方法

    用法1:从网络获取到json字符串之后,假如该字符串为data, Gson gson = new Gson(); HomeBean json = gson.fromJson(data, HomeBea ...

  3. 最大独立集 HDU 1068

    题目大意:有n个人,两个人之间有相互的关系,问最大的关系数目. 思路:n-(最大匹配数/2).因为这里给出的是n个人之间的两两关系 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心 ...

  4. perl的Getopt::Long和pod::usage ?

    来源: http://www.cnblogs.com/itech/archive/2012/08/07/2627267.html 代码: 需要显式地定义变量且初始化.例如optionX. 如果没有定义 ...

  5. C#窗口实现最小化到系统托盘

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. html 页面视图中的资源文件(css/js/image)的路径问题。

    说到html 页面视图中的资源文件的路径引用问题,这个问题以前一直没去弄明白.今天,我将公司新开发的一个项目完全移植到我本地搭建的php 环境中来,遇到了这个问题,想了一下,然后也不是很困难的就把它给 ...

  7. Vs2010 WPF 项目打包

    [转]图解WPF程序打包全过程 首先打开已经完成的工程,如图: 下面开始制作安装程序包. 第一步:[文件]——[新建]——[项目]——安装项目. 名称——可以自己根据要求修改. 位置——是指你要制作的 ...

  8. Listview和checkbox多选

    在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上看上去只是改变checkbox那么简单,然而实际开发中,实现起来并不是那么得心应手.尤其当 ...

  9. Linux学习 -- 系统管理

    1 进程管理 判断服务器健康状态 top [选项] 查看系统中所有进程 ps aux      BSD格式 ps -le        Linux格式 pstree [选项] -p   显示PID - ...

  10. html5中拨打电话代码

    <a href="tel:18600000000">给我打电话</a>   <a href="sms:18600000000"&g ...