博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Central Europe Regional Contest 2011
阅读量:7093 次
发布时间:2019-06-28

本文共 3038 字,大约阅读时间需要 10 分钟。

 

Unique Encryption Keys
Time Limit: 30000ms, Special Time Limit:75000ms, Memory Limit:65536KB
Total submit users: 19, Accepted users: 15
Problem 12484 : Special judge
Problem description
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≤i≤230) 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 anysuch key.

 

Print one empty line after each cipher description.

Sample Input
10 532349738411 32 64 103 72 65 2123122 41 50 0
Sample Output
3OK43OKOK1
Problem Source
Central Europe 2011

 

 

题意:告诉你从1-n的区间内,依次对应一个整数,询问给定一个区间,是否存在两个相同的整数。

 

 

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 8 int n,m; 9 vector
value;10 11 int main()12 {13 for(;;) 14 {15 scanf("%d %d\n", &n, &m);16 if (!n) return 0;17 value.resize(n);18 for (int i = 0; i < n; i++) 19 {20 scanf("%d", &value[i]);21 }22 23 map
last_occ; //用于记录当前的最小匹配区间24 vector
first_match(n); //用于记录从i位置之后最先匹配的区间的右侧25 for (int i = n-1; i >= 0; i--) 26 {27 first_match[i] = n;28 if (i < n-1)29 first_match[i] = first_match[i+1];30 if (last_occ.count(value[i]))31 first_match[i] = min(first_match[i], last_occ[value[i]]); //更新区间32 last_occ[value[i]] = i; 33 }34 35 for (int i = 0; i < m; i++)36 {37 int x, y;38 scanf("%d %d",&x, &y);39 x--;40 y--;41 if (first_match[x] <= y)42 {43 printf("%d\n",value[first_match[x]]);44 } 45 else46 {47 printf("OK\n");48 }49 }50 printf("\n");51 }52 }53 /*54 12 1055 256 657 1258 559 660 461 762 663 764 1465 266 1467 3 768 */

题目链接:

 

 

 

 

 

注意一下vector和map的用法

1、vector<int>value(n);                         value大小为n             等同于      vector<int>value;          value.resize(n);

2、map<int,int>cnt;               等同于建立一个映射((int)x->(int)y)

转载地址:http://mziql.baihongyu.com/

你可能感兴趣的文章
使用Depth Texture
查看>>
第 9 章 PBX
查看>>
ylbtech-LanguageSamples-Porperties(属性)
查看>>
第 4 章 Music score
查看>>
架构设计目录
查看>>
Wind7外接显示器选择拓展模式后,鼠标只能往右移动才能切换到外接显示器上,不能修改切换方向...
查看>>
学习笔记: CSS3 鼠标悬停动画
查看>>
ylbtech-cnblogs(博客园)-数据库设计-7,News(新闻)
查看>>
WCF 基础简介
查看>>
用Soap消息调用Web Services(续)
查看>>
php数据库操作封装类
查看>>
atitit.导出excel的设计----查询结果 导出为excel的实现java .net php 总结
查看>>
[LeetCode] Partition List 划分链表
查看>>
以Ajax方式显示Lotus Notes视图的javasript类库----NotesView2
查看>>
ylbtech-memorandum(备忘录)-数据库设计
查看>>
spm中头动绘图的理解,自带数据集
查看>>
PostgreSQL的 initdb 源代码分析之二十五
查看>>
I.MX6 su.c 测试
查看>>
Restful风格API接口开发springMVC篇
查看>>
车辆管理系统之继续自己的任务(五)
查看>>