C. Train and Queries
Along the railroad there are stations indexed from 11 to 109109. An express train always travels along a route consisting of nn stations with indices u1,u2,…,unu1,u2,…,un, where (1≤ui≤1091≤ui≤109). The train travels along the route from left to right. It starts at station u1u1, then stops at station u2u2, then at u3u3, and so on. Station unun — the terminus.
It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values u1,u2,…,unu1,u2,…,un.
You are given kk queries, each containing two different integers ajaj and bjbj (1≤aj,bj≤1091≤aj,bj≤109). For each query, determine whether it is possible to travel by train from the station with index ajaj to the station with index bjbj.
For example, let the train route consist of 66 of stations with indices [3,7,1,5,1,43,7,1,5,1,4] and give 33 of the following queries:
- a1=3a1=3, b1=5b1=5
It is possible to travel from station 33 to station 55 by taking a section of the route consisting of stations [3,7,1,53,7,1,5]. Answer: YES.
- a2=1a2=1, b2=7b2=7
You cannot travel from station 11 to station 77 because the train cannot travel in the opposite direction. Answer: NO.
- a3=3a3=3, b3=10b3=10
It is not possible to travel from station 33 to station 1010 because station 1010 is not part of the train's route. Answer: NO.
Input
The first line of the input contains an integer tt (1≤t≤1041≤t≤104) —the number of test cases in the test.
The descriptions of the test cases follow.
The first line of each test case is empty.
The second line of each test case contains two integers: nn and kk (1≤n≤2⋅105,1≤k≤2⋅1051≤n≤2⋅105,1≤k≤2⋅105) —the number of stations the train route consists of and the number of queries.
The third line of each test case contains exactly nn integers u1,u2,…,unu1,u2,…,un (1≤ui≤1091≤ui≤109). The values u1,u2,…,unu1,u2,…,un are not necessarily different.
The following kk lines contain two different integers ajaj and bjbj (1≤aj,bj≤1091≤aj,bj≤109) describing the query with index jj.
It is guaranteed that the sum of nn values over all test cases in the test does not exceed 2⋅1052⋅105. Similarly, it is guaranteed that the sum of kk values over all test cases in the test also does not exceed 2⋅1052⋅105
Output
For each test case, output on a separate line:
- YES, if you can travel by train from the station with index ajaj to the station with index bjbj
- NO otherwise.
You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
Example
input
36 3 3 7 1 5 1 4 3 5 1 7 3 103 3 1 2 1 2 1 1 2 4 57 5 2 1 1 1 2 4 4 1 3 1 4 2 1 4 1 1 2
output
YES NO NO YES YES NO NO YES YES NO YES
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<utility>
#include<stack>
#include<vector>
#include<math.h>
#include<map>
#include<queue>
using namespace std;
int t,n,k;
map<int, pair<int,int>>a;
int main() {ios::sync_with_stdio(false); cin >> t;while (t--){a.clear();cin >> n >> k;for (int i = 1; i <= n; i++){int x;cin >> x;if (a[x].first == 0) { //用map对每个数的最小索引,最大索引进行储存a[x].first = i;a[x].second = i;}else a[x].second = i;}for (int i = 0; i < k; i++){int ui, vi;cin >> ui >> vi; if (a[ui].first <= a[vi].second&&a[ui].first!=0&&a[vi].first!=0)cout << "YES" << endl;else cout << "NO" << endl; //用前一个的最小索引跟后一个的最大索引进行比较}}return 0;
}
C. Train and Queries相关推荐
- 【CF 比赛记录】Roye_ack的艰难上分日常(35)
目录 #792 Div1+Div2 AC A1. Digit Minimization #Edu 129 Div2 !A2. Game with Cards #795 Div2 AC A3. Be ...
- java里面queries怎么写,Java程序员在写SQL时常犯的10个错误
10 Common Mistakes Java Developers Make when Writing SQL Java developers mix object-oriented thinkin ...
- A. Vova and Train
滴答滴答---题目链接 time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- TFRecord tf.train.Feature
一.定义 事先将数据编码为二进制的TFRecord文件,配合TF自带的多线程API,读取效率最高,且跨平台,适合规范化存储复杂的数据.上图为TFRecord的pb格式定义,可发现每个TFRecord由 ...
- 二、如何保存MNIST数据集中train和test的图片?
如何保存MNIST数据集中train和test的图片? 介绍一种非诚神奇的图片保存方法,尤其是利用字典-format-结合来用,创建保存路径,这是一种史上很难用到的一种方法,哈哈哈哈,有点吹牛皮,不说 ...
- c4d教程-太空火车站场景创作视频教程Skillshare – Create A Space Train Scene With Cinema 4D Redshift Render
c4d教程-太空火车站场景创作视频教程Skillshare – Create A Space Train Scene With Cinema 4D & Redshift Render 教程大小 ...
- GDC2016 Epic Games【Bullet Train】 新风格的VR-FPS的制作方法
追求"舒适"和"快感"的VR游戏设计方法 http://game.watch.impress.co.jp/docs/news/20160318_749016.h ...
- Caffe中对cifar10执行train操作
参考Caffe source中examples/cifar10目录下内容. cifar10是一个用于普通物体识别的数据集,cifar10被分为10类,分别为airplane.automobile.bi ...
- Caffe中对MNIST执行train操作执行流程解析
之前在 http://blog.csdn.net/fengbingchun/article/details/49849225 中简单介绍过使用Caffe train MNIST的文章,当时只是仿照ca ...
最新文章
- 现宣布Windows Azure中SQL数据同步的增强功能
- linux系统下卷组管理,Linux LVM卷组管理
- python 如何放心干净的卸载模块
- (7) hibernate之级联cascade和关系维持inverse
- redhat linux yum仓库,关于RHEL6发行版yum仓库的配置
- 代码组织和部署 文件操作 node.js 1
- 我:一个女孩从软件测试工程师到主管的成长
- javascript对象的property和prototype是这样一种关系
- 为什么devc调试时循环一下就过去了_SEPCOIII英语研习社(第六十一讲)| 燃气轮机调试...
- mysql+sqlplus命令找不到_oracle sqlplus命令报command not found
- 分布式集群中网络分区问题
- 用最简单的方法解决:linux系统重启网络delaying initialization错误
- 基于对立非洲秃鹫优化算法求解单目标优化问题(OAVOA)含Matlab代码
- STM32固件库(Standard Peripheral Libraries )官网下载方法
- ovo以及ovr的直观理解
- 全球都在乘“云”而上,从十几亿暴涨至千亿规模的云计算究竟是什么来头?
- 计算机网络培训方案,计算机网络技术 专业培训方案
- 个人博客系统之框架搭建
- 深耕怀旧经济,这个淘宝商家如何卖出3个金皇冠店铺?
- 祝福考研的兄弟姐妹们!