陈老师的多校联合20140815 ||uvalive 5881 区间处理
2014-08-15 20:47
302 查看
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3892
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.
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
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.
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.
题目大意:给出一段区间判断是否在这一段区间上有重复数字出现
解题思路:用b数组存储a[i]后面与a[i]最近的重复数字的位置
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map<int,int>p;
const int maxn=1000000+10;
int a[maxn],v[maxn],b[maxn];
int n,m;
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n==0&&m==0)
break;
p.clear();
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
b[n+1]=n+1;
for(int i=n;i>0;i--)
{
b[i]=b[i+1];
if(p[a[i]])
b[i]=min(p[a[i]],b[i]);
p[a[i]]=i;
}
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
if(b[x]>y)
printf("OK\n");
else
printf("%d\n",a[b[x]]);
}
printf("\n");
}
}
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 (1M
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
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 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
题目大意:给出一段区间判断是否在这一段区间上有重复数字出现
解题思路:用b数组存储a[i]后面与a[i]最近的重复数字的位置
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map<int,int>p;
const int maxn=1000000+10;
int a[maxn],v[maxn],b[maxn];
int n,m;
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n==0&&m==0)
break;
p.clear();
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
b[n+1]=n+1;
for(int i=n;i>0;i--)
{
b[i]=b[i+1];
if(p[a[i]])
b[i]=min(p[a[i]],b[i]);
p[a[i]]=i;
}
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
if(b[x]>y)
printf("OK\n");
else
printf("%d\n",a[b[x]]);
}
printf("\n");
}
}
相关文章推荐
- 陈老师的多校联合 D题 字符串处理起来挺麻烦
- 陈老师的多校联合2010811c题||09年武汉站||hdu3232
- 陈老师的多校联合20180808 map映射字符串
- 陈老师的多校联合2009年武汉站D题 ||hdu 3033
- 陈老师的多校联合20140818||Uvalive 5683 模拟
- 陈老师的多校联合 20140809 C题
- 陈老师的多校联合20140811||HDU 3236 ||2009年武汉站G题 01背包问题
- 陈老师的多校联合20140816||SPOJ AMR11B 三角形的有向面积
- UVALive 5691 二分图匹配||陈老师的多校联合20140818 J题
- 陈老师的多校联合 20140808 E题
- HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
- hdu 5412 CRB and Queries 2015多校联合训练赛#10 分治 求区间第k大数
- 陈老师的多校联合20140816||spoj10237 bfs
- hdu 4632 Palindrome subsequence 区间dp 多校联合训练第四场
- HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)
- 陈老师的多校联合 I题 二分
- 陈老师的多校联合 20140809
- HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)
- 陈老师的多校联合20140816A题||spoj 10228 动态规划
- HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)