Problem You are given an array of N integers and Q queries. Each query is a closed interval [l, r]. You should find the minimum absolute difference between all pairs in that interval.

Input  First line contains an integer T (T ≤ 10). T sets follow. Each set begins with an integer N (N ≤ 200000). In the next line there are N integers ai (1 ≤ ai ≤ 104 ), the number in the i-th cell of the array. Next line will contain Q (Q ≤ 104 ). Q lines follow, each containing two integers li , ri (1 ≤ li , ri ≤ N, li < ri) describing the beginning and ending of of i-th range. Total number of queries will be less than 15000.

Output For the i-th query of each test output the minimum |ajak| for li ≤ j, k ≤ ri (j ̸= k) a single line.

Sample Input    1   10     1  2  4  7  11  10  8   5  1  10000            4     1  10     1   2      3  5         8  10

Sample Output    0     1     3       4

题解:因为给的N个数的范围很小,如果查询的区间的长度大于10000,那么区间一定有重复的数字,所以结果返回0,如果不是,把这个区间的所有出现的数记录在数组中,跑一遍[L,R]区间,求得相邻的出现的差值最小就是最后的答案。(根本不是线段树QTQ)

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 200005;
  4. const int Max = 10004;
  5. const int inf = 0x3f3f3f3f;
  6. int a[maxn];
  7. int b[Max];
  8. int main()
  9. {
  10. int t,n,m,i,l,r,ans,last;
  11. scanf("%d",&t);
  12. while(t--)
  13. {
  14. scanf("%d",&n);
  15. for(i = 1; i <= n; i ++)scanf("%d",&a[i]);
  16. scanf("%d",&m);
  17. while(m--)
  18. {
  19. scanf("%d%d",&l,&r);
  20. if(r - l + 1 >= 10000)
  21. {
  22. printf("0\n");
  23. continue;
  24. }
  25. else
  26. {
  27. memset(b,0,sizeof(b));
  28. for(i = l; i <= r; i ++)
  29. {
  30. b[a[i]]++;
  31. if(b[a[i]] > 1)
  32. {
  33. printf("0\n");
  34. break;
  35. }
  36. }
  37. if(i <= r)continue;
  38. ans = inf;
  39. last = -inf;
  40. for(i = 1; i <= 10000; i ++)
  41. {
  42. if(b[i]==1)
  43. {
  44. ans = min(ans,i - last);
  45. last = i;
  46. }
  47. }
  48. printf("%d\n",ans);
  49. }
  50. }
  51. }
  52. return 0;
  53. }

Killer Problem (UVA 11898 )的更多相关文章

  1. 木块问题(The Blocks Problem,Uva 101)

    不定长数组:vector vector就是一个不定长数组.不仅如此,它把一些常用操作“封装”在了vector类型内部. 例如,若a是一个vector,可以用a.size( )读取它的大小,a.resi ...

  2. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  3. P1832 A+B Problem(再升级)

    P1832 A+B Problem(再升级) 题目提供者 usqwedf 传送门 标签 动态规划 数论(数学相关) 洛谷原创 难度 普及/提高- 通过/提交 107/202 题目背景 ·题目名称是吸引 ...

  4. 题解 P1601 【A+B Problem(高精)】

    P1601 A+B Problem(高精) 题目描述 高精度加法,x相当于a+b problem,b不用考虑负数. 输入输出格式 输入格式: 分两行输入a,b<=10^500 输出格式: 输出只 ...

  5. A+B Problem(再升级)

    洛谷P1832 A+B Problem(再升级) ·给定一个正整数n,求将其分解成若干个素数之和的方案总数. 先说我的垃圾思路,根本没有验证它的正确性就xjb写的,过了垃圾样例,还水了20分,笑哭.. ...

  6. 【洛谷p1601】A+B Problem(高精)

    高精度加法的思路还是很简单容易理解的 A+B Problem(高精)[传送门] 洛谷算法标签: 附上代码(最近懒得一批) #include<iostream> #include<cs ...

  7. uva10401Injured Queen Problem(递推)

    题目:uva10401Injured Queen Problem(递推) 题目大意:依然是在棋盘上放皇后的问题,这些皇后是受伤的皇后,攻击范围缩小了.攻击范围在图中用阴影表示(题目).然后给出棋盘的现 ...

  8. 洛谷1601 A+B Problem(高精) 解题报告

    洛谷1601 A+B Problem(高精) 本题地址:http://www.luogu.org/problem/show?pid=1601 题目背景 无 题目描述 高精度加法,x相当于a+b pro ...

  9. 洛谷——P1832 A+B Problem(再升级)

    P1832 A+B Problem(再升级) 题目背景 ·题目名称是吸引你点进来的 ·实际上该题还是很水的 题目描述 ·1+1=? 显然是2 ·a+b=? 1001回看不谢 ·哥德巴赫猜想 似乎已呈泛 ...

随机推荐

  1. 2019牛客暑期多校训练营(第二场) - B - Eddy Walker 2 - BM算法

    参考于: https://www.luogu.org/problemnew/solution/P4723 shadowice1984 (太难) https://www.cnblogs.com/zhgy ...

  2. zabbix-自定义告警(二)

    实现自定义监控 文章引用:https://www.cnblogs.com/clsn/p/7885990.html#auto_id_28 一.实现自定义监控 说明zabbix自带模板Template O ...

  3. Cannot call sendRedirect() after the response has been committed的解决办法

    做一个Login Demo的时候,写了如下代码: protected void doPost(HttpServletRequest request, HttpServletResponse respo ...

  4. python之paramiko 远程执行命令

    有时会需要在远程的机器上执行一个命令,并获得其返回结果.对于这种情况,python 可以很容易的实现. 1 .工具 Python paramiko 1) Paramiko模块安装 在Linux的Ter ...

  5. HttpWorkerRequest应用简介

    1. Using HttpWorkerRequest for getting headers1.使用HttpWorkerRequest获取headers信息 First, the HttpWorker ...

  6. 如何为 esp32 编译和配置及烧写 MicroPython 固件。

    MicroPython 在 esp-idf (esp32) 上编译固件 esp32 编译 micropython 的固件相关的资料应该很多吧,我也会出一篇,但会额外讲一些 linux 的东西的. 资料 ...

  7. [leetcode] 题解记录 11-20

    博客园markdown太烂, 题解详情https://github.com/TangliziGit/leetcode/blob/master/solution/11-20.md Leetcode So ...

  8. cube打包后css顺序错误

    先说下解决办法: 把import {...} from cube-ui放在 import App from './App.vue'的前面 不然会产生如下错误 正确的顺序

  9. H5移动端弹幕动画实现

    思路 把单个内容编辑好,计算自身宽度,确定初始位置 移动的距离是屏幕宽度 js动态的添加css动画函数,将高度.动画移动时间.动画延迟时间都用随机数控制 代码: html骨架结构 (以三个为例,如果觉 ...

  10. 1.移动端自动化测试-知识笔记(面试必备,测试点,adb命令)

    移动端测试: 移动应用,特性(功能) 满足 需求(产品文档,隐性需求) 一.App功能测试: 死活背下来1.业务逻辑正确性测试: 产品文档,隐性需求- 写成测试用例 2.兼容性测试:   1.系统版本 ...