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. ThinkPHP第九天(在Admin分组中配置__PUBLIC__,$POST异步传输,import使用方法,验证码点击刷新方法,Create方法作用)

    1.项目分组之后,后台模板的公用文件一般放置在Tpl/Admin/Public中,这样子在替换模板路径时候如果还用__PUBLIC__时为了不与前台冲突,应该在Admin/config.php中配置一 ...

  2. mysql存储过程详解[转]

    1.      存储过程简介   我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储 ...

  3. python笔记之列表与元组函数和方法使用举例

    在学习列表之前先了解了raw_input和input的区别:(仅适用于版本2,版本3中raw_input和input合并,没有raw_input) input的语法为:input("str& ...

  4. [LeetCode]题解(python):025-Reverse Nodes in k-Group

    题目来源: https://leetcode.com/problems/reverse-nodes-in-k-group/ 题意分析: 这道题目和上一题目类似,输入一个链表和一个整型k.每k个翻转一下 ...

  5. 谈谈我的iOS学习及分享

    iOS可以说是最近几年比较热门和高速发展一个系统,因此iOS开发也变得火热.越来越多的程序员都转向了iOS开发,每个人的学习方法都不同,分享下我的学习经历和见解吧.我之前学习过C++和Qt,Java也 ...

  6. 工程脚本插件方案 - c集成Python基础篇(VC++嵌入Python)

    序: 为什么要集成脚本,怎么在工程中集成Python脚本. 在做比较大型的工程时,一般都会分核心层和业务层.核心层要求实现高效和稳定的基础功能,并提供调用接口供业务层调用的一种标准的框架划分.在实际中 ...

  7. 基于visual Studio2013解决C语言竞赛题之0406数列求和

      题目 解决代码及点评 这个题目,还是考察for循环的使用 以及数列规律,该数列的特点是第n个分子 = 第n-1个分子 + 第n-2个分子,分母也是此规律 而另外一个规律是第n个分子和第n- ...

  8. UVA 1160 - X-Plosives 即LA3644 并查集判断是否存在环

    X-Plosives A secret service developed a new kind ofexplosive that attain its volatile property only ...

  9. 误mlogc.c:32:23: error: curl/curl.h: No such file or directory

    出现以下错误: mlogc.c:32:23: error: curl/curl.h: No such file or directory mlogc.c:1091: error: expected ' ...

  10. Android Studio入门到精通

    链接地址:http://blog.csdn.net/yanbober/article/details/45306483 目标:Android Studio新手–>下载安装配置–>零基础入门 ...