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

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

  1. #include <bits/stdc++.h>
  2. #define LL long long
  3. #define inf 1e60
  4. using namespace std;
  5. inline int ra()
  6. {
  7. int x=,f=; char ch=getchar();
  8. while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
  9. while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
  10. return x*f;
  11. }
  12.  
  13. const int maxn=;
  14.  
  15. int a[maxn],n,m;
  16. int main()
  17. {
  18. n=ra(); m=ra(); for (int i=; i<=n; i++) a[i]=ra();
  19. sort(a+,a+n+);
  20. while (m--)
  21. {
  22. int x=ra(),y=ra();
  23. y=upper_bound(a+,a+n+,y)-a;
  24. x=lower_bound(a+,a+n+,x)-a;
  25. printf("%d\n",y-x);
  26. }
  27. return ;
  28. }

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. js中的跨域

    因为javascript的同源策略,导致它普通情况下不能跨域,直到现在,我还是不能完全理解js跨域的几种方法,没办法,只能慢慢学习,慢慢积累,这不,几天又在园里看到一篇博文,有所收获,贴上来看看; 原 ...

  2. ES6:字面量的增强写法

    以前对象字面量的写法: 属性的增强写法: ES6中可以写成: 方法的增强写法 ES6中可以写成: ~~~~~ END ~~~~~

  3. python中的type和object详解

    关于这篇博客 这篇博客主要描述Python的新风格对象(new-style objects),如下: <type 'type'>和<type 'object'>分别是什么? 用 ...

  4. Attributes for Slot

    关于AP Config中的一些参数的意义: Radio Type................................... RADIO_TYPE_80211ac-5 Radio Subba ...

  5. Nexus-vPC基础实验

    一.实验拓扑: 由于条件有限,使用两个N5K做基本的vPC实验,Peer Keepalive Link使用的是两个Nexus 5K的Mgm0接口. 二.配置步骤:1.先构建vPC domain,并在d ...

  6. 【SSM 验证码】登录验证码

    LoginController /** * 登陆方法 */ @ResponseBody @RequestMapping("login2") public Map<String ...

  7. java之中文乱码处理

    有些时候,比如文件操作的时候,特别是文件中有中文,会规定用GBK格式,这时读写文件,可能会出现中文乱码 资源文件乱码 文件内容乱码 资源文件乱码: 解决: PropertiesUtil proper ...

  8. 科幻电影免费百度云分享(Scince-fiction cloud share)

    Marvel episode Link  Passcode:6h9k Star War full episode Link Passcode:7abk Men In Black Episode Col ...

  9. lnmp1.5安装fileinfo扩展

    cd /usr/local/src cd lnmp1.-full/src tar xvf php-.tar.bz2 cd php-/ext/fileinfo phpize ./configure -- ...

  10. python-定时任务-apschelduer

    python-定时任务-apschelduer 1.      apscheduler 1.1.    install pip install apscheduler 1.2.    basic co ...