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)

#include <bits/stdc++.h>

using namespace std;
const int maxn = 200005;
const int Max = 10004;
const int inf = 0x3f3f3f3f; int a[maxn];
int b[Max];
int main()
{
int t,n,m,i,l,r,ans,last;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i = 1; i <= n; i ++)scanf("%d",&a[i]);
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&l,&r);
if(r - l + 1 >= 10000)
{
printf("0\n");
continue;
}
else
{
memset(b,0,sizeof(b));
for(i = l; i <= r; i ++)
{
b[a[i]]++;
if(b[a[i]] > 1)
{
printf("0\n");
break;
}
}
if(i <= r)continue;
ans = inf;
last = -inf;
for(i = 1; i <= 10000; i ++)
{
if(b[i]==1)
{
ans = min(ans,i - last);
last = i;
}
}
printf("%d\n",ans);
}
}
}
return 0;
}

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. yum更新出错-解决

    Total download size: 14 MIs this ok [y/d/N]: 命令里已经yum install -y了,但是还是需要选择Y,N没有自动执行,请问这个要怎么破. PS:我是在 ...

  2. 《深入实践C++模板编程》之三——模板参数类型详解

    非类型模板参数 和 模板型模板参数 整数以及枚举类型:指向对象或者函数的指针:对对象或函数的引用:指向对象成员的指针.统称为非类型模板参数. 模板型模板参数,是指模板参数还可以是一个模板.   1.整 ...

  3. ES6新特性总结

    一.let const var有缺陷:有块级作用域.能重复定义.无法限制修改.所以出来了let和const. 有块级作用域,不能重复定义 const不能修改,必须定义的时候赋值 二.解构赋值 1.左右 ...

  4. python版本

    一般在Linux下,默认会安装一个python2.*的版本,但是我们自己开发有时候需要python3.*的版本 1. 安装python3 .安装依赖包 )首先安装gcc编译器,gcc有些系统版本已经默 ...

  5. HTML5之fileReader异步读取文件及文件切片读取

    fileReader的方法与事件 fileReade实现图片预加载 fileReade实现文件读取进度条 fileReade的与file.s实现文件切片读取 一.fileReader的方法与事件 1. ...

  6. vue事件处理机制

    <button @click="handleAdd1()">add1</button> <button @click="handleAdd2 ...

  7. Dreamweaver CS6 破解安装

    安装 双击Dreamweaver.dmg文件,然后Command+N,新建一个Finder,接着将Adobe Dreamweaver CS6拖到新建Finder的应用程序中.   在Finder中应用 ...

  8. 在已有lnmp环境的基础上安装PHP7

    Centos7.6系统 已经安装lnmp一键环境 想装个apache跑php7, apache安装在这 https://www.cnblogs.com/lz0925/p/11227063.html 要 ...

  9. IoT 设备通信安全讨论

    IoT 设备通信安全讨论 作者:360CERT 0x00 序言 IoT 设备日益增多的今天,以及智能家居这一话题愈发火热,智能家居市场正在飞速的壮大和发展,无数 IoT 设备正在从影片中不断的走向用户 ...

  10. VM 下增加磁盘空间

    随着Linux虚拟机的不断使用,在VMware中经常遇到 预先装好的 linux 虚拟机的硬盘空间过小 的问题,造成很多软件不能安装, 而重新装一个,又挺麻烦.于是,上网搜了下关于 vmware 硬盘 ...