DES:给出一个数列。然后有q个询问,对给定的区间内是否有重复的数。如果有输出任意一个重复的。如果没有输出OK。

开始以为是线段树。后来发现。只是水的比较隐蔽。感觉这个方法还是很聪明的。把每个点的最近的有重复的数的区间记录下来。这样每次询问都可以直接表示结果了。

 #include<stdio.h>
#include<string.h>
#include<iostream>
#include<map>
#define inf 0x3f3f3f3f
using namespace std; map<int, int>mp;
int num[];
int id[]; int main()
{
int n, q;
while(cin >> n >> q)
{
if (n == && q == ) break;
for (int i=; i<n; ++i)
{
cin >> num[i];
} mp.clear();
id[n] = inf; for (int i=n-; i>=; --i)
{
if (mp[num[i]] == )
{
id[i] = id[i+];
mp[num[i]] = i;
continue;
}
else
{
id[i] = min(mp[num[i]], id[i+]);
mp[num[i]] = i;
}
} while(q--)
{
int x, y;
cin >> x >> y;
x--;
y--;
if (y < id[x]) cout << "OK\n";
else cout << num[id[x]] << endl;
}
cout << endl;
}
return ;
}

LOoK

UVALive 5881的更多相关文章

  1. UVALive 5881 Unique Encryption Keys (DP)

    Unique Encryption Keys 题目链接: http://acm.hust.edu.cn/vjudge/problem/26633 Description http://7xjob4.c ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  5. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  6. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  7. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  8. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  9. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

随机推荐

  1. Visual Leak Detector简明使用教程

    Visual Leak Detector是一款内存泄漏检测软件,主要的作用就是检测可能或者是存在内存泄露的地方,具体的功能的话,可以百度下,今天主要简单介绍下怎么使用 首先下载Visual Leak ...

  2. ubuntu下交叉编译ffmpeg

    环境:ubuntu16.04 交叉编译器版本:4.8.3 依赖x264,lame x264: 1.wget ftp://ftp.videolan.org/pub/x264/snapshots/last ...

  3. 基于bootstrap的后台管理系统

    ace metro'nic 基于bootstrap的后台admin system ace [eis], 扑克牌中的A 表示 非常棒, 杰出, 顶好的... gallery: 画廊, 走廊; 在网页中常 ...

  4. FieldOffset

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.G ...

  5. 记一次诡异的bug

    使用django做项目,在视图函数中需要查询,查询前构造一个查询参数的模型来过滤参数防止报错,然后调用模型的方法返回一个字典,包括了所有查询的字段和值,发现只要查询过一次之后,后续的访问查询结果会在之 ...

  6. .NET Core2.0应用IdentityServer4

    IdentityServer4能解决什么问题 假设我们开发了一套[微博程序],主要拥有两个功能:[登陆验证].[数据获取] 随后我们又开发了[简书程序].[知乎程序],它们的主要功能也是:[登陆验证] ...

  7. .NET反射的优化

    写在前面 1)本篇博客并非原创,而是我针对.NET反射相关知识的总结.本篇内容来源汇总于3篇博客.在后面的介绍中会在开头给出对应的链接,方便读者自行学习.2)本篇博客主要针对表达式树代码进行详细讲解. ...

  8. ubuntu16.04上安装tomcat7

    sudo apt-get update sudo apt-get install tomcat7 启动:sudo service tomcat7 start 访问http://127.0.0.1:80 ...

  9. [原][osg][osgEarth]关于在OE中使用物理引擎的调研

    关于物理引擎旋转的一些整理 参考文档 http://blog.wolfire.com/2010/03/Comparing-ODE-and-Bullet 介绍ODE和bullet的利弊 http://s ...

  10. Windows 2012 R2 创建AD域

    创建复数的域控制器,容错的同时(一台AD故障),且能提高用户的登录效率. 为了实现负载平衡,域配置前,两台Ad域的DNS应该按如下设置,同时,也为了避免在AD02上,选择“将域控制器添加到现有域”时出 ...