Unique Encryption Keys
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的更多相关文章
- UVALive 5881 Unique Encryption Keys (DP)
Unique Encryption Keys 题目链接: http://acm.hust.edu.cn/vjudge/problem/26633 Description http://7xjob4.c ...
- Unique Encryption Keys (思维题 预处理)
题目 题意:给m个数字, q次询问, 询问b到e之间如果有重复数字就输出, 没有就输出OK 思路:用f[i]数组 记录从i开始向后最近的有重复数字的 位置, 如 1 3 2 2, 则f[1] = 4; ...
- ORA-02266: unique/primary keys in table referenced by enabled foreign keys
在数据库里面使用TRUNCATE命令截断一个表的数据时,遇到如下错误 SQL >TRUNCATE TABLE ESCMOWNER.SUBX_ITEM ORA-02266: unique/prim ...
- Android Unique Device ID
There are several occasions when the unique identifier of a device is required. For instance you nee ...
- SQL Server安全(8/11):数据加密(Data Encryption)
在保密你的服务器和数据,防备当前复杂的攻击,SQL Server有你需要的一切.但在你能有效使用这些安全功能前,你需要理解你面对的威胁和一些基本的安全概念.这篇文章提供了基础,因此你可以对SQL Se ...
- 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 ...
- 真正解决方案:phpMyAdmin #1089 - Incorrect prefix key; the storage engine doesn't support unique prefix key
先直接给解决方案: 点击A_I后,不要输入大小,直接点击执行!!! 分析 当你在使用phpMyAdmin 创建数据库表的时候,一般我们需要设置一个主键,然后让其自增长,但是有时候当你设置完成后,你可能 ...
- openswan-ipsec.conf配置说明
Name ipsec.conf - IPsec configuration and connections Description The optional ipsec.conf file speci ...
- A Study of WebRTC Security
转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...
随机推荐
- python——深刻理解Python中的元类(metaclass)
译注:这是一篇在Stack overflow上 很热的帖子.提问者自称已经掌握了有关Python OOP编程中的各种概念,但始终觉得元类(metaclass)难以理解.他知道这肯定和自省有关,但仍然觉 ...
- lodash _.size
返回collection(集合)的长度,如果集合是类数组或字符串,返回其 length :如果集合是对象,返回其可枚举属性的个数. _.size([1, 2, 3]); // => 3 _.si ...
- Date日期类型转化成中文字符串
例子: select to_char(sysdate,'yyyy"年"mm"月"dd"日"') as nowYear from dual 结 ...
- Centos6.8 下 Node.js 的安装
思路:采用编译好的文件进行安装 一 使用 wget 下载 到 Node.js 官网(https://nodejs.org/en/download/) 选择要下载的编译版本(Source Code) / ...
- mac下安装python pip、pyspider
如果mac下没有安装wget,还需要安装wget,见http://www.cnblogs.com/cocowool/archive/2012/06/24/2560574.html 使用 pip 安装 ...
- html&css基础框架
原文地址:http://www.w3cplus.com/framework/index.php
- JS防后退跳转
location.replace("http://www.baidu.com");
- 自己动手开发更好用的markdown编辑器-07(扩展语法)
这里文章都是从个人的github博客直接复制过来的,排版可能有点乱. 原始地址 http://benq.im/2015/05/19/hexomd-07/ 文章目录 1. 准备工作 2. 目录语法 ...
- Codeforces Round #297 (Div. 2) 525C Ilya and Sticks(脑洞)
C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Vim使用技巧(2) -- 插入模式技巧 【持续更新】
组合快捷键 Ctrl + h //删除前一个字母(同退格键) Ctrl + w //删除前一个单词 Ctrl + u //删除到行首 Esc //切换到普通模式 Ctrl + [ //切换到普通模式 ...