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. Selenium webdriver Java 操作IE浏览器

    V1.0版本:直接新建WebDriver使用 import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetE ...

  2. opencv提取surf特征点出现的错误

    opencv实现surf特征的提取.本来是一个非常easy的代码,结果我执行时却出现了各种错误,以下来谈谈我出现的错误及问题的解决过程. 首先,我把提取surf特征的过程整合成了一个函数,我单独建立一 ...

  3. 查看tomcat启动文件都干点啥---catalina.bat

    在上一次查看tomcat启动文件都干点啥一文中,我们总结出,startup.bat文件的作用就是找到catalina.bat文件,然后把参数传递给它,在startup.bat中,调用catalina. ...

  4. win10 为了对电脑进行保护,已经阻止此应用 解决方法

        win10 为了对电脑进行保护,已经阻止此应用 解决方法 正确方法: ."win+x"进入控制面板,选择安全性与维护,在左侧更改windows smartscreen筛选器 ...

  5. linux之getopt 函数(转)

    命令行参数解析函数 —— getopt() getopt()函数声明如下: #include <unistd.h> int getopt(int argc, char * const ar ...

  6. jquery绑定事件的区别

    query中绑定事件有三种方法:以click事件为例 (1)target.click(function(){}); (2)target.bind("click",function( ...

  7. 每日一个机器学习算法——k近邻分类

    K近邻很简单. 简而言之,对于未知类的样本,按照某种计算距离找出它在训练集中的k个最近邻,如果k个近邻中多数样本属于哪个类别,就将它判决为那一个类别. 由于采用k投票机制,所以能够减小噪声的影响. 由 ...

  8. jquery淡入淡出无延迟代码

    <!DOCTYPE html> <html> <head> <script src="jquery.js"></script& ...

  9. Openlayer4 - 最好最强大的开源地图引擎

    Openlayer4 - 最好最强大的开源地图引擎 # githubhttps://github.com/openlayers/openlayers # 官网http://openlayers.org ...

  10. delphi中检测局域网ip能够ping通模块

    // 函数PingHost用于ping目标IP是否连通 // uses winsock    在uses中加入  winsock // 用法:  if PingHost(edit2.Text) the ...