首页 技术 正文
技术 2022年11月6日
0 收藏 873 点赞 696 浏览 1870 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,027
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857