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 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

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

没发现和stl有什么关系。。。。。用二分过的,先以值得大小二分,假设值同样的话,加一组推断,以当前的id与给出的l和r进行二分,看最后能不能得出符合条件的值

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int id , k ;
} p[80000];
bool cmp(node a,node b)
{
return a.k<b.k || ( a.k==b.k && a.id < b.id );
}
void f(int l,int r,int x,int n)
{
int low = 0 , top = n-1 ;
while(low <= top)
{
int mid = (low+top)/2 ;
if( p[mid].k == x && p[mid].id >= l && p[mid].id <= r )
{
printf("1");
return ;
}
else if( p[mid].k < x || ( p[mid].k == x && p[mid].id < l ) )
low = mid+1 ;
else
top = mid - 1 ;
}
printf("0");
return ;
}
int main()
{
int i , n , m , l , r , x ;
while(scanf("%d", &n)!=EOF)
{
for(i = 0 ; i < n ; i++)
{
scanf("%d", &p[i].k);
p[i].id = i+1 ;
}
sort(p,p+n,cmp);
scanf("%d", &m);
while(m--)
{
scanf("%d %d %d", &l, &r, &x);
f(l,r,x,n);
}
printf("\n");
}
}

STL--G - For Fans of Statistics(两个推断条件-二分)的更多相关文章

  1. ural1613 For Fans of Statistics

    For Fans of Statistics Time limit: 1.0 secondMemory limit: 64 MB Have you ever thought about how man ...

  2. 1613. For Fans of Statistics(STL)

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

  3. 2018/7/31--zznu-oj-问题 G: 方差 普拉斯--【两重暴力循环求方差即可!】

    问题 G: 方差 普拉斯 时间限制: 1 Sec  内存限制: 128 MB提交: 94  解决: 17[提交] [状态] [讨论版] [命题人:admin] 题目描述 方差(样本方差)是每个样本值与 ...

  4. ural 1613 For Fans of Statistics

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

  5. 51Nod 1557 两个集合(二分)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1557 题意: 小X有n个互不相同的整数: p1,p2,...,pn .他 ...

  6. Wooden Stricks——两个递增条件的线性DP

    题目 一堆n根木棍.每个棒的长度和重量是预先已知的.这些木棒将由木工机械一一加工.机器需要准备一些时间(称为准备时间)来准备处理木棍.设置时间与清洁操作以及更换机器中的工具和形状有关.木工机械的准备时 ...

  7. FJWC2018

    晚上水到8:40,感觉药丸. 把电脑带回寝室,大半夜敲键盘…… bzoj5254红绿灯 泰迪每天都要通过一条路从家到学校,这条路的起点是泰迪家,终点则是学校. 这条路中间还有n个路口,从第i-1个路口 ...

  8. Android触摸事件(一)-TouchEventHelper

    文件夹 文件夹 概述 关于更新 2016-08-31 2016-06-20 关于单点触摸事件singleTouch 单击的两种方式 关于双击事件 双击事件的检測逻辑 双击事件触发的时机 关于多点触摸事 ...

  9. 仅仅有五行的Floyd最短路算法

    暑假,小哼准备去一些城市旅游.有些城市之间有公路,有些城市之间则没有,例如以下图.为了节省经费以及方便计划旅程,小哼希望在出发之前知道随意两个城市之前的最短路程. 上图中有4个城市8条公路,公路上的数 ...

随机推荐

  1. python之高阶函数编程

    在这篇文章中我指出两点: 第一:系统函数可以被覆盖 比如: a=abs(-10) print a 10 但是,如果把函数本身赋值给变量呢? f = abs f <built-in functio ...

  2. win7 64下安装mysql-python报错的解决办法

    最近要使用django进行项目开发,需要使用mysql-python模块. 在本地搭建环境安装的时候却出现报错,Unable to find vcvarsall.bat  在网上找了很多资料,发现是w ...

  3. QR Code 码

    一.QR Code码 由日本Denso公司于1994年9月研制的一种矩阵二维码符号,它除具有一维条码及其它二维条码所有的信息容量大.可靠性高.可表示汉字及图象多种文字信息.保密防伪性强等优点外,还具有 ...

  4. 定制一个winCE5.0操作系统

    定制一个winCE5.0操作系统 2009-04-01 09:01:14|  分类: winCE|字号 订阅     定制一个操作系统并模拟器上运行,需要以下几个步骤: STEP 1:用Platfor ...

  5. HTML::Entities 编码或解码 HTML 实体的字符串

    <pre name="code" class="html"><pre name="code" class="py ...

  6. jxl读写excel, poi读写excel,word, 读取Excel数据到MySQL

    这篇blog是介绍: 1. java中的poi技术读取Excel数据,然后保存到MySQL数据中. 2. jxl读写excel 你也可以在 : java的poi技术读取和导入Excel了解到写入Exc ...

  7. Android Touch事件传递机制具体解释 上

    尊重原创:http://blog.csdn.net/yuanzeyao/article/details/37961997 近期总是遇到关于Android Touch事件的问题,如:滑动冲突的问题,曾经 ...

  8. 卸载了PL/SQL Developer,说一下与Toad for Oracle的对照

    曾经一直用PL/SQL Developer来管理Oracle.发现真的使用起来非常不方便.打开非常卡,并且界面左上角总是多出那个框,怎么都无法设置默认隐藏掉. 唯一让人认为非常值得的就是有一个美化工具 ...

  9. 【Eclipse】修改java代码不强制重启

    找到tomcat的server.xml文件,修改以下代码,重新发布重启.然后修改java代码就可以不用重启了. 将reloadable=“true”改成reloadable="false&q ...

  10. ListActivity的注意点

    有的时候我们需要集成ListActivity,注意点1,这个时候我们的xml中的<ListView>标签中的id属性不能够随便自己命名,而是要固定为android:id="@id ...