The security of many ciphers strongly depends on the fact that the keys are unique and never re-used. This may be vitally important, since a relatively strong cipher may be broken if the same key is used to encrypt several different messages. In this problem, we will try to detect repeating (duplicate) usage of keys. Given a sequence of keys used to encrypt messages, your task is to determine what keys have been used repeatedly in some specified period. Input The input contains several cipher descriptions. Each description starts with one line containing two integer numbers M and Q separated by a space. M (1 ≤ M ≤ 1000000) is the number of encrypted messages, Q is the number of queries (0 ≤ Q ≤ 1000000). Each of the following M lines contains one number Ki (0 ≤ Ki ≤ 2 30) specifying the identifier of a key used to encrypt the i-th message. The next Q lines then contain one query each. Each query is specified by two integer numbers Bj and Ej , 1 ≤ Bj ≤ Ej ≤ M, giving the interval of messages we want to check. There is one empty line after each description. The input is terminated by a line containing two zeros in place of the numbers M and Q. Output For each query, print one line of output. The line should contain the string “OK” if all keys used to encrypt messages between Bj and Ej (inclusive) are mutually different (that means, they have different identifiers). If some of the keys have been used repeatedly, print one identifier of any such key. Print one empty line after each cipher description.

Sample Input

10 5

3

2

3

4

9

7

3

8

4

1

1 3

2 6

4 10

3 7 2 6

5 2

1

2

3

1

2

2 4

1 5

0 0

Sample Output

3

OK

4

3

OK

OK

1

// 题意,m长的序列,要q次询问,然后m个数,再q对 l,r ,问当中有没有重复的,有就输出最靠左的

//f[i] 表示i位置右边最近发生重复的位置,就很简单了,主要是没想到啊!

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
using namespace std;
#define MX 1000005 int a[MX];
int f[MX]; //f[i] 表示i位置右边最近发生重复的位置 int main()
{
int n,q;
while (scanf("%d%d",&n,&q)&&(n+q))
{
map <int ,int> mp;
for (int i=;i<=n;i++)
scanf("%d",&a[i]);
f[n]=n+;
mp[a[n]]=n;
for (int i=n-;i>=;i--)
{
if (mp.count(a[i]))
f[i] = min(f[i+],mp[a[i]]);
else
f[i] = f[i+];
mp[a[i]]=i;
}
while (q--)
{
int l,r;
scanf("%d%d",&l,&r);
if (f[l]<=r)
printf("%d\n",a[f[l]]);
else
printf("OK\n");
}
printf("\n");
}
return ;
}

Unique Encryption Keys的更多相关文章

  1. UVALive 5881 Unique Encryption Keys (DP)

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

  2. Unique Encryption Keys (思维题 预处理)

    题目 题意:给m个数字, q次询问, 询问b到e之间如果有重复数字就输出, 没有就输出OK 思路:用f[i]数组 记录从i开始向后最近的有重复数字的 位置, 如 1 3 2 2, 则f[1] = 4; ...

  3. ORA-02266: unique/primary keys in table referenced by enabled foreign keys

    在数据库里面使用TRUNCATE命令截断一个表的数据时,遇到如下错误 SQL >TRUNCATE TABLE ESCMOWNER.SUBX_ITEM ORA-02266: unique/prim ...

  4. Android Unique Device ID

    There are several occasions when the unique identifier of a device is required. For instance you nee ...

  5. SQL Server安全(8/11):数据加密(Data Encryption)

    在保密你的服务器和数据,防备当前复杂的攻击,SQL Server有你需要的一切.但在你能有效使用这些安全功能前,你需要理解你面对的威胁和一些基本的安全概念.这篇文章提供了基础,因此你可以对SQL Se ...

  6. TDE: Transparent Data Encryption brief introduction

    1. What is TDE? Briefly speaking, TDE is used to encrypted data. 2. The benifits: Belows are come fr ...

  7. 真正解决方案:phpMyAdmin #1089 - Incorrect prefix key; the storage engine doesn't support unique prefix key

    先直接给解决方案: 点击A_I后,不要输入大小,直接点击执行!!! 分析 当你在使用phpMyAdmin 创建数据库表的时候,一般我们需要设置一个主键,然后让其自增长,但是有时候当你设置完成后,你可能 ...

  8. openswan-ipsec.conf配置说明

    Name ipsec.conf - IPsec configuration and connections Description The optional ipsec.conf file speci ...

  9. A Study of WebRTC Security

    转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...

随机推荐

  1. javascript中按位操作的应用,如何快速取整 判断字符串是否是包含某字符串

    最近在看最基础的<javascript高级程序设计>看的灰常慢,看到按位运算这里,突然反思,这种鬼操作到底有什么实际的应用呢? 按位运算符有6个 & 按位与:a & b | ...

  2. HDU 2819 Swap (行列匹配+输出解)

    题意:是否能使对角线上全是1 ,这个简单直接按行列匹配.难在路径的输出,我们知道X,Y左右匹配完了之后,不一定是1–1,2–2,3–3--这种匹配.可能是1–3,2–1,3–2,我们要把他们交换成前一 ...

  3. Linux学习笔记 (八)Shell概述

    一.什么是Shell? Shell是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来启动,挂起,停止甚至是编写一些程序.Shell还是一 ...

  4. 实现微信浏览器内打开App Store链接

    http://www.ildsea.com/1781.html 微信浏览器是不支持打开App Store 页面的,不知道微信为什么这么做.比如你页面写 <a href=”http://itune ...

  5. java自定义注解与反射

    java注解与反射一.Java中提供了四种元注解,专门负责注解其他的注解,分别如下 1.@Retention元注解,表示需要在什么级别保存该注释信息(生命周期).可选的RetentionPoicy参数 ...

  6. IE 页面不正常显示 错误脚本不报错 脚本调试相关

    在开发时,有时自己做的页面上的JS有错误,但是IE浏览器并不报错,这个时候有可能是因为脚本调试被禁止了. 在Internet选项的高级里面有 两个禁止脚本调试选项,把他们去掉就行.

  7. acm之路--母函数 by小宇

    母函数又叫生成函数,原是数学上的一个名词,是组合数学中的一个重要理论. 生成函数是说,构造这么一个多项式函数g(x).使得x的n次方系数为f(n). 对于母函数,看到最多的是这样两句话: 1.&quo ...

  8. 解决安装Ubuntu之后找不到无线网卡驱动的问题

    为了不浇灭大家尝试ubuntu的冲动,昨天我安装了ubuntu 14.04 LTS版本号,从安装到又一次开机都非常顺利.PS:不会安装的请找教程区把,网上非常多,CSDN论坛都有. 安装之后当你奇妙的 ...

  9. 《我是一只IT小小鸟》(胡江堂主编)读后感

    http://blog.csdn.net/wojiushiwo987/article/details/8685539<我是一只IT小小鸟>(胡江堂主编)读后感 2011年下半年研二的时候, ...

  10. 各种broker对比

    broker的主要职责是接受发布者发布的所有消息,并将其过滤后分发给不同的消息订阅者.如今有很多的broker,下面就是一张关于各种broker对比的图片: 在使用mosquitto时,如果想使用集群 ...