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. Android 实践项目开发一

    这次做的项目是—手机地图系统 本次实验的功能是,为用户提供需要的目标定位系统定位处理,即用户设置一个目标后, 可以在后台启动一个Service,能够定时读取GPS数据已获得用户当前所在的位置信息, 并 ...

  2. JS引擎深入分析

    转载自阮一峰:http://javascript.ruanyifeng.com/bom/engine.html 目录 JavaScript代码嵌入网页的方法 script标签:代码嵌入网页 scrip ...

  3. P3939 数颜色

    目录 题目 思路1(待修莫队) 思路2(vector+二分) 代码1 代码2 题目 P3939 数颜色 思路1(待修莫队) 哇,这不是莫队模板题吗 3e5,TLE45分 不行 我有信仰啊 pow(n, ...

  4. 骗访问量的机房人物列传by xMinh

    作者:$xMinh$ 人物列传·Refun(Aufun,虚凡,人赢) 机房最人赢的人赢,上过表白墙的男人 在宿舍公然开设情感讲座和人赢培训班,教学成果显著,他的徒弟要么gay了要么凉了 认识的人极其广 ...

  5. Spring的面向切面

    Spring的面向切面 在应用开发中,有很多类似日志.安全和事务管理的功能.这些功能都有一个共同点,那就是很多个对象都需要这些功能.复用这些通用的功能的最简单的方法就是继承或者委托.但是当应用规模达到 ...

  6. spring boot 使用@ConfigurationProperties

    有时候有这样子的情景,我们想把配置文件的信息,读取并自动封装成实体类,这样子,我们在代码里面使用就轻松方便多了,这时候,我们就可以使用@ConfigurationProperties,它可以把同类的配 ...

  7. Java之Elasticsearch 增删改查

    <!--ELK --> <dependency> <groupId>org.elasticsearch.client</groupId> <art ...

  8. HDU 5961 传递

    http://acm.hdu.edu.cn/showproblem.php?pid=5961 题意: 思路: 话不多说,直接暴力. #include<iostream> #include& ...

  9. Github客户端操作

    Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.作为一个程序员,我们需要掌握其用法. 作为开源代码库以及版本控制系统,Github目前拥有140 ...

  10. Map<K, V> 中k,v如果为null就转换

    Set<String> set = map.keySet(); if(set != null && !set.isEmpty()) { for(String key : s ...