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. iOS显示PDF

    使用UIWebView来显示 //locale file NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUT ...

  2. HLS 协议

    HTML 5 视频直播一站式扫盲   本文来自于腾讯bugly开发者社区,原文地址:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=1 ...

  3. 55. 略谈Lotus Notes的与众不同及系列文章至此的总结

    在二十多年的悠久历史里,Lotus Notes发展出一整套独特的概念.技术和思维.由于它早期惊人的领先时代和后续发展中同样惊人的忠于传统,这位软件领域的寿星在如今发展更新速度远超往日和技术愈趋公开互通 ...

  4. 禁用 Windows Azure 网站中的 ARR 实例关联

    编辑人员注释: 本博客文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 在 Windows Azure 网站中设置网站的多个实例是横向扩展网站的绝佳方式,Azur ...

  5. hdu 4679 (树形DP)

    题意:给一棵树,边的权值都是1,摧毁每条边是有代价的,选择摧毁一条边,把一棵树分成两部分,求出两部分中距离最大的两点的距离,求出距离*代价最小的边,多条的话输出序号最小的. 刚开始理解错题意了,wro ...

  6. Hadoop Security Authentication Terminology --Kerberos

    Hadoop Security Authentication Terminology --Kerberos What is kinit? Kinit -  obtain and cache Kerbe ...

  7. H264解码的一个測试程序

    网上看到的一个H264视频格式的解码測试程序,能够用来參考其逻辑流程. 代码例如以下: Test_Display_H264(){      in_fd = open(H264_INPUT_FILE, ...

  8. c#关于委托和事件

    using System; using System.Collections.Generic; using System.Text; namespace Delegate {     // 热水器   ...

  9. Win10玩魔兽争霸不能全屏显示的设置教程

    Win10玩魔兽争霸不能全屏显示的设置教程: 1.右击桌面左下角的windows图标,显示图片内容,然后点击运行: 2.点击运行,有个输入框,输入regedit,点击确认: 3.显示win10注册表, ...

  10. c++,public/protected/private权限修饰符

    1.public的变量可以在类中以及外部访问到: 2. private只可以在类/友元中访问到. #include <iostream> using namespace std; //-- ...