Killer Problem (UVA 11898 )
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 )的更多相关文章
- 木块问题(The Blocks Problem,Uva 101)
不定长数组:vector vector就是一个不定长数组.不仅如此,它把一些常用操作“封装”在了vector类型内部. 例如,若a是一个vector,可以用a.size( )读取它的大小,a.resi ...
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- P1832 A+B Problem(再升级)
P1832 A+B Problem(再升级) 题目提供者 usqwedf 传送门 标签 动态规划 数论(数学相关) 洛谷原创 难度 普及/提高- 通过/提交 107/202 题目背景 ·题目名称是吸引 ...
- 题解 P1601 【A+B Problem(高精)】
P1601 A+B Problem(高精) 题目描述 高精度加法,x相当于a+b problem,b不用考虑负数. 输入输出格式 输入格式: 分两行输入a,b<=10^500 输出格式: 输出只 ...
- A+B Problem(再升级)
洛谷P1832 A+B Problem(再升级) ·给定一个正整数n,求将其分解成若干个素数之和的方案总数. 先说我的垃圾思路,根本没有验证它的正确性就xjb写的,过了垃圾样例,还水了20分,笑哭.. ...
- 【洛谷p1601】A+B Problem(高精)
高精度加法的思路还是很简单容易理解的 A+B Problem(高精)[传送门] 洛谷算法标签: 附上代码(最近懒得一批) #include<iostream> #include<cs ...
- uva10401Injured Queen Problem(递推)
题目:uva10401Injured Queen Problem(递推) 题目大意:依然是在棋盘上放皇后的问题,这些皇后是受伤的皇后,攻击范围缩小了.攻击范围在图中用阴影表示(题目).然后给出棋盘的现 ...
- 洛谷1601 A+B Problem(高精) 解题报告
洛谷1601 A+B Problem(高精) 本题地址:http://www.luogu.org/problem/show?pid=1601 题目背景 无 题目描述 高精度加法,x相当于a+b pro ...
- 洛谷——P1832 A+B Problem(再升级)
P1832 A+B Problem(再升级) 题目背景 ·题目名称是吸引你点进来的 ·实际上该题还是很水的 题目描述 ·1+1=? 显然是2 ·a+b=? 1001回看不谢 ·哥德巴赫猜想 似乎已呈泛 ...
随机推荐
- Excel导入异常Cannot get a text value from a numeric cell解决
POI操作Excel时偶尔会出现Cannot get a text value from a numeric cell的异常错误. 异常原因:Excel数据Cell有不同的类型,当我们试图从一个数字类 ...
- python基础知识0-4
collection 他是对字典 元组 集合 进行加工的 是计数器 无论 深 ,浅 ,赋值 拷贝 内存地址都不变 赋值也是拷贝的一种 拷贝分两类数字 字符串 另一类: 列表 字典 元组 这一类还分两 ...
- 使用JWT的ASP.NET CORE令牌身份验证和授权(无Cookie)——第1部分
原文:使用JWT的ASP.NET CORE令牌身份验证和授权(无Cookie)--第1部分 原文链接:https://www.codeproject.com/Articles/5160941/ASP- ...
- centos7---ansible批量部署
CentOS7系统 ansible自动化部署多台服务器部署 Ansible工作机制 从图中可以看出ansible分为以下几个部份: 1> Control Node:控制机器2> In ...
- Windows命令行命令总结
转载地址:https://www.cnblogs.com/accumulater/p/7110811.html 1. gpedit.msc-----组策略 2. sndrec32-------录音 ...
- 对MySQL索引、锁及事务的简单分析
一.索引的数据结构 1.二叉搜索树实现的索引 二叉搜索树如下图,它查找元素的时间复杂度为O(logn) 但如果经常出现增删操作,最后导致二叉搜索树变成线性的二叉树,这样它查找元素的时间复杂度就会变成O ...
- 正确理解这四个重要且容易混乱的知识点:异步,同步,阻塞,非阻塞,5种IO模型
本文讨论的背景是Linux环境下的network IO,同步IO和异步IO,阻塞IO和非阻塞IO分别是什么 概念说明 在进行解释之前,首先要说明几个概念: - 用户空间和内核空间 - 进程切换 - 进 ...
- mongodb启用auth,使用密码登录
更新操作: db.users.update({'currentVersion':3},{$set:{'currentVersion':5}}) 首先安装下载(略过) mongod 启动服务,有多重启动 ...
- odoo 常用模型的简写
<act_window>是窗口操作模型ir.actions.act_window <menuitem>是菜单项模型ir.ui.menu <report>是报表操作模 ...
- 《python解释器源码剖析》第9章--python虚拟机框架
9.0 序 下面我们就来剖析python运行字节码的原理,我们知道python虚拟机是python的核心,在源代码被编译成字节码序列之后,就将有python的虚拟机接手整个工作.python虚拟机会从 ...