23333,在扒了一天题解之后发现我竟然还能秒题,虽然这是个pj的sb题。。。

(排个序,然后upper_bound和lower_bound一用就行了(是不是有O(1)的查询方法啊??貌似要离散啊,一样蛋疼。。))

 #include <bits/stdc++.h>
#define LL long long
#define inf 1e60
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
} const int maxn=; int a[maxn],n,m;
int main()
{
n=ra(); m=ra(); for (int i=; i<=n; i++) a[i]=ra();
sort(a+,a+n+);
while (m--)
{
int x=ra(),y=ra();
y=upper_bound(a+,a+n+,y)-a;
x=lower_bound(a+,a+n+,x)-a;
printf("%d\n",y-x);
}
return ;
}

bzoj 4747: [Usaco2016 Dec]Counting Haybales的更多相关文章

  1. [Usaco2016 Dec]Counting Haybales

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4747 先将原数组排序,然后二分查找即可.时间复杂度\(O((N+Q)logN)\). #i ...

  2. BZOJ 4742: [Usaco2016 Dec]Team Building

    4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 16[Su ...

  3. [Usaco2015 DEC] Counting Haybales

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4392 [算法] 线段树 时间复杂度 : O(MlogN) [代码] #include ...

  4. BZOJ 4576: [Usaco2016 Open]262144

    Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco ...

  5. Counting Haybales

    Counting Haybales 题目描述 Farmer John is trying to hire contractors to help rearrange his farm, but so ...

  6. Counting Haybales (线段树)

    Counting Haybales 时间限制: 50 Sec  内存限制: 256 MB提交: 52  解决: 18[提交][状态][讨论版] 题目描述 Farmer John is trying t ...

  7. 洛谷 P3184 [USACO16DEC]Counting Haybales数草垛

    P3184 [USACO16DEC]Counting Haybales数草垛 题目描述 Farmer John has just arranged his NN haybales (1 \leq N ...

  8. bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和

    4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec  Memory Limit: 128 MB Description Farmer John ...

  9. BZOJ 3389: [Usaco2004 Dec]Cleaning Shifts安排值班

    题目 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec  Memory Limit: 128 MB Description      ...

随机推荐

  1. git warning: CRLF will be replaced by LF in resources/views/sessions/create.blade.php

    git config core.autocrlf false

  2. html和css的重难点知识

    目录 html总难点总结: 1. 块级标签与内联标签的区别 1.1 块级标签: 1.2 内联标签: 2. 选择器 2.1 定义 2.2 选择器的分类 2.1 选择器的分类 3. css中margin, ...

  3. 连接数据库的url

    mysql: jdbc:mysql://localhost:3306:test这句里面分如下解析:jdbc:mysql:// 是指JDBC连接方式:localhost: 是指你的本机地址:3306 S ...

  4. ArrayList,LinkedList,vector的区别

    1,Vector.ArrayList都是以类似数组的形式存储在内存中,LinkedList则以链表的形式进行存储. 2.List中的元素有序.允许有重复的元素,Set中的元素无序.不允许有重复元素. ...

  5. 进程,内存,管理 ps,pstree,top,free,vmstat,iftop,lsof,查看网速

    一些基础 不同进程之间,进行数据访问 同一主机:pipe 管道 socket   套接字文件 signal   信号 shm   shared memory semaphore 信号量,一种计数器 不 ...

  6. 实时监听 mysql 操作,Linux 版

    效果 场景:某数据库新增了某条记录,服务器可以监听到变化的数据与操作,如 增加一条记录: id = 1009,name=''test,number = 11 服务器监听结果: 实现过程 测试过程:数据 ...

  7. linux下postgres创建hive数据库

    操作步骤 #登录 [root@xxx01 ~]# su postgres bash-4.2$ psql -U postgres could not change directory to " ...

  8. Mac 下 vim 常用命令

    vim 三种模式:命令模式.插入模式.底线命令模式. 切换模式: 命令模式: 启动 vim 进入命令模式: i 切换到插入模式,以输入字符. x   删除当前光标所在处的字符. :   切换到底线命令 ...

  9. centos7使用docker制作tomcat本地镜像

    1.安装Docker 安装docker前请确认当前linux的内核版必须是3.10及以上 命令: uname  -r 1).yum install -y yum-utils device-mapper ...

  10. Invalid or unexpected token:数据格式错误

    一个查询页面突然出现如下这个错误: Uncaught SyntaxError: Invalid or unexpected token, 翻译成中文是: 捕获的查询无效或意外的标记. 既然代码逻辑没问 ...