UVALive 5881
DES:给出一个数列。然后有q个询问,对给定的区间内是否有重复的数。如果有输出任意一个重复的。如果没有输出OK。
开始以为是线段树。后来发现。只是水的比较隐蔽。感觉这个方法还是很聪明的。把每个点的最近的有重复的数的区间记录下来。这样每次询问都可以直接表示结果了。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<map>
#define inf 0x3f3f3f3f
using namespace std; map<int, int>mp;
int num[];
int id[]; int main()
{
int n, q;
while(cin >> n >> q)
{
if (n == && q == ) break;
for (int i=; i<n; ++i)
{
cin >> num[i];
} mp.clear();
id[n] = inf; for (int i=n-; i>=; --i)
{
if (mp[num[i]] == )
{
id[i] = id[i+];
mp[num[i]] = i;
continue;
}
else
{
id[i] = min(mp[num[i]], id[i+]);
mp[num[i]] = i;
}
} while(q--)
{
int x, y;
cin >> x >> y;
x--;
y--;
if (y < id[x]) cout << "OK\n";
else cout << num[id[x]] << endl;
}
cout << endl;
}
return ;
}
LOoK
UVALive 5881的更多相关文章
- UVALive 5881 Unique Encryption Keys (DP)
Unique Encryption Keys 题目链接: http://acm.hust.edu.cn/vjudge/problem/26633 Description http://7xjob4.c ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- 20145206邹京儒《网络对抗技术》 PC平台逆向破解
20145206邹京儒<网络对抗技术> PC平台逆向破解 注入shellcode并执行 一.准备一段shellcode 二.设置环境 具体在终端中输入如下: apt-cache searc ...
- 20145206邹京儒《网络对抗》逆向及Bof基础实践
20145206邹京儒<网络对抗>逆向及Bof基础实践 1 逆向及Bof基础实践说明 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:ma ...
- STM32.定时器
一.定时器分类 11个定时器: 定时器: 1.8 高级(7路PWM输出) 2.3.4.5 通用(4路) 6.7 基本 2个看门狗 1个sysTick 时钟分布: 二.这里我们主要对定时器中 定 ...
- git分支 远程协作
创建文件mkdir ### cd ### git init 初始化 git config global user.name “username” git config global user.emia ...
- Delphi XE5 for Android (三)
在VCL下,常用的询问对话框包括 procedure TfrmMainVCL.btnAppMessageboxClick(Sender: TObject); begin if Applicatio ...
- git的软件安装
1.Git for Winodws 1.*的版本 https://github.com/msysgit/msysgit/releases 2.*的版本 https://github.com/g ...
- 2017 ACM/ICPC 新疆赛区 I 题 A Possible Tree 带权并查集
传送门 题意:给定一棵带权树的形态, 但是并不知道每天条边的具体权重. 然后给m个信息, 信息格式为u v val, 表示在树上u 到 v 的路径上经过的边的权重的异或和为val, 问前面最多有多少个 ...
- BZOJ1398: Vijos1382寻找主人 Necklace 字符串最小表示法
Description 给定两个项链的表示,判断他们是否可能是一条项链. Input 输入文件只有两行,每行一个由0至9组成的字符串,描述一个项链的表示(保证项链的长度是相等的). Output 如果 ...
- 移动端Css初始化
@charset "utf-8"; /* 禁用iPhone中Safari的字号自动调整 */ html { -webkit-text-size-adjust: %; -ms-tex ...
- 解决Floodlight界面无法显示问题
参考: 解决Floodlight1.2+Mininet问题及使用安装 解决Floodlight界面无法显示问题 执行以下命令启动Floodlight时: java -jar target/floodl ...