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. Windows Services 学习(转载)

    转载:http://blog.csdn.net/fakine/article/details/42107571 一.学习点滴 1.本机服务查看:services.msc /s2.服务手动安装(使用sc ...

  2. Python3基础 os mkdir 创建一层文件夹 在有父目录的情况下创建子目录

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. Hexo 搭建 Blog 精简笔记

    安装Hexo npm install -g hexo-cli Mac 用户 您在编译时可能会遇到问题,请先到 App Store 安装 Xcode,Xcode 完成后,启动并进入 Preference ...

  4. 记录openwrt下补丁apply的过程中出错,但是可以单独打上该补丁

    背景: 在openwrt的编译框架下无法正确打上补丁,而单独使用git却可以成功 这个补丁到底与其它补丁有何不同? 该补丁的生成的过程解析: 旧文件:vi 打开旧文件会提示no newline at ...

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

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

  6. Kylin介绍

    转:http://blog.csdn.net/yu616568/article/details/48103415 Kylin是ebay开发的一套OLAP系统,与Mondrian不同的是,它是一个MOL ...

  7. $.cookie()取值设置

    本文为博主原创,未经允许不得转载: 使用jquery.cookie.js中的cookie做了一个折叠式菜单栏,用cookie保存会话的值,其中的值为点击菜单栏时,即在cookie中 保存对应的值,保证 ...

  8. ajax中的contentType使用

    本文为博主原创,未经允许不得转载: 最近在修改部分项目功能的时候,遇到一个问题.局部刷新某页面的功能是由ajax实现的,但当我进行局部刷新的时候,页面并没有刷新和响应, 在后台的代码中打了断点也并没有 ...

  9. hdu 5652 India and China Origins 并查集+二分

    India and China Origins Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  10. go语言 变量类型

    package main import "fmt" func main() { //这是我们使用range去求一个slice的和.使用数组跟这个很类似.创建数组 nums := [ ...