UVALive 5881 Unique Encryption Keys
来源:互联网 发布:基于oracle的sql优化 编辑:程序博客网 时间:2024/06/06 02:18
[Submit] [Go Back] [Status]
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(1M1000000) is the number of encrypted messages, Q is the number of queries (0Q1000000).
Each of the following M lines contains one number Ki(0Ki230) 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, 1BjEjM, 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 532349738411 32 64 103 72 65 2123122 41 50 0
Sample Output
3OK43OKOK1
#include <cstdlib>#include <cctype>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <iostream>#include <sstream>#include <map>#include <set>#include <queue>#include <stack>#include <fstream>#include <numeric>#include <iomanip>#include <bitset>#include <list>#include <stdexcept>#include <functional>#include <utility>#include <ctime>using namespace std;#define PB push_back#define MP make_pair#define CLR(vis) memset(vis,0,sizeof(vis))#define MST(vis,pos) memset(vis,pos,sizeof(vis))#define MAX3(a,b,c) max(a,max(b,c))#define MAX4(a,b,c,d) max(max(a,b),max(c,d))#define MIN3(a,b,c) min(a,min(b,c))#define MIN4(a,b,c,d) min(min(a,b),min(c,d))#define PI acos(-1.0)#define INF 0x7FFFFFFF#define LINF 1000000000000000000LL#define eps 1e-8typedef long long ll;typedef unsigned long long ull;const int maxn=1e6+100;int n,m;int a[maxn];int b[maxn];int main(){ while(scanf("%d%d",&n,&m)!=EOF) { if(!n && !m) break; for(int i=0;i<n;i++) scanf("%d",&a[i]); map<int ,int > p; p.clear(); CLR(b); for(int i=n-1;i>=0;i--) { b[i]=INF; if(i<n-1) b[i]=b[i+1]; if(p.find(a[i])!=p.end()) b[i]=min(b[i],p[a[i]]); p[a[i]]=i; } int l,r; for(int i=0;i<m;i++) { scanf("%d%d",&l,&r); l--,r--; if(b[l]<=r) printf("%d\n",a[b[l]]); else printf("OK\n"); } cout<<endl; } return 0;}
- UVALive 5881 Unique Encryption Keys
- UVALive 5881 Unique Encryption Keys
- UVALive 5881 Unique Encryption Keys【线段树】
- Unique Encryption Keys
- Unique Encryption Keys 暴力学习map,vector 函数
- Partitioning Keys, Primary Keys, and Unique Keys
- Lest We Remember: Cold Boot Attacks on Encryption Keys
- 19.6.1 Partitioning Keys, Primary Keys, and Unique Keys 分区键,主键,和唯一健
- Encryption
- UVALive 6044 Unique Path 解题报告
- Ticket Servers: Distributed Unique Primary Keys on the Cheap
- Ticket Servers: Distributed Unique Primary Keys on the Cheap
- ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found
- ORA-02449: unique/primary keys in table referenced by foreign keys
- ORA-02266: unique/primary keys in table referenced by enabled foreign keys
- truncate table 错误 ORA-02266: unique/primary keys in table referenced by enabled foreign keys
- ORA-02266: unique/primary keys in table referenced by enabled foreign keys
- Keys
- UVA - 11111 Generalized Matrioshkas
- hdu 2522(整数相除 判断循环节)
- Ubuntu 下安装Mongodb
- mysql中文乱码问题
- 微信开发HTML5轻游戏中的几个坑
- UVALive 5881 Unique Encryption Keys
- Touch of Venom +SPOJ+推公式题
- 线性表的链式表示与实现(单链表)
- Ubuntu网络功能总结
- 用C开发PHP扩展初探
- iOS 错误 missing required architecture i386 in file
- 数据库路由器 ICX
- 一张纸上打印多页报表
- 关于ethernet的调试验证总结