Problem Description

You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.

For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.

The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.

Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.

Output

Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value - 1 if there is no such number.

Sample Input

6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2

Sample Output

2
6
-1
4

题意:给出 n 个数 m 组询问,每组询问 l、r、x,任意输出区间 [l,r] 上不等于 x 的一个位置,若在区间内全等于 x,则输出 -1

思路:有些类似并查集路径压缩的思想,开一个数组 res[],令 res[i] 记录第 i  个数前面第一个和他不等的数的下标就行了,如果相等就令 res[i]=res[i-1],然后每次对 [l,r] 查询时,从最右端开始与 x 对比即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-6
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define N 1001
#define LL long long
using namespace std;
int a[N];
int res[N];
int main()
{int n,m;scanf("%d%d",&n,&m);for(int i=1;i<=n;++i)scanf("%d",&a[i]);res[n]=n;for(int i=n-1;i>=1;i--){if(a[i]==a[i+1])res[i]=res[i+1];elseres[i]=i;}while(m--){int l,r,x;scanf("%d%d%d",&l,&r,&x);if(a[l]!=x)printf("%d\n",l);else if(res[l]+1<=r)printf("%d\n",res[l]+1);elseprintf("-1\n");}return 0;
}

Not Equal on a Segment(CF-622C)相关推荐

  1. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  2. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  3. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  4. D. Make a Power of Two(cf#739DIV3)

    D. Make a Power of Two 链接: link. 题意: 找出将数字转换为 2 的任意幂的最小移动次数. 题解: 先将2的xxx次幂的结果以字符串形式保存,输入字符串nnn后,因为存在 ...

  5. Web of Lies(CF 1548A)

    这是今天在打个人赛时碰见的一道题,是一道半图论半思维的题. Web of Lies 题目大意不难理解,在这里只需要注意一些细节.在加边时,只有当cnt[min]的值为1时答案才应该减1,而不是当cnt ...

  6. 【解题报告】博弈专场 (CF 2000~2200)前五题

    [解题报告]博弈专场 (CF 2000+)前五题 A:Fox and Card Game | CF388C 题意 思路 代码 B:Berzerk | CF786A 题意 思路 代码 C:Ithea P ...

  7. Java集合篇:ConcurrentHashMap详解(JDK1.8)

    (本文使用的源码都是基于JDK1.8的) (基于JDK1.6的版本可以参考这篇文章:https://blog.csdn.net/a745233700/article/details/83120464) ...

  8. 软件设计师提纲+复习资料整理(上午题)

    文章目录 软件设计师考试大纲 上午题(选择题) 一.计算机组成原理 考点:CPU结构组成 考点:原码.反码.补码定点整数范围 考点:浮点数表示 考点:RISC和CISC计算机的区别 考点:奇校验与偶校 ...

  9. 深入理解数据库磁盘存储(Disk Storage)

    数据库管理系统将数据存储在磁盘.磁带以及其他的裸设备上,虽然这些设备的访问速度相比内存慢很多,但其非易失性和大容量的特点使他们成为数据存储的不二之选. 本文主要讨论大型数据库产品的磁盘存储内部结构,这 ...

最新文章

  1. webstorm常用快捷键
  2. 【Demo】改变SO项目状态并取消拒绝原因实现
  3. CiberCut_5.6 标牌制作
  4. 微信小程序复制到剪切板及换行问题
  5. 原创 通过PEB获得进程路径 (附完整工程)
  6. LeetCode4. 寻找两个有序数组的中位数
  7. 两数据库Dblink数据抽取blob
  8. 机器学习知识点查漏补缺(朴素贝叶斯分类)
  9. 简易的文件上传 tp5
  10. Shiro框架的搭建与使用
  11. 10 分钟了解 Flutter 跨平台方案
  12. 学生计算机可以打游戏吗,关于在校学生玩电脑游戏的调查报告
  13. spotlight ios_如何禁用iOS 10的Spotlight搜索历史记录
  14. 使用windows命令行 启动WeGame
  15. vue 身份证校验、识别性别/生日/年龄
  16. CUDA_NVCC_FLAGS set
  17. MySQL中的字符集是啥?如何更改?
  18. 因果推断1--基本方法介绍(个人笔记)
  19. LLDB命令简单介绍
  20. C#人脸识别入门篇(Step by step 人脸识别)

热门文章

  1. 崩溃!新浪程序员加班错失 77 万年会大奖
  2. 不懂 ZooKeeper?没关系,这一篇给你讲的明明白白
  3. 从17 个方面对比 Kafka、RabbitMQ、RocketMQ、ActiveMQ 等分布式消息队列
  4. 微信小程序时代,哪些人能赚到第一桶金
  5. jsp自定义标签(taglib)编写的原理和实现
  6. 读书笔记—《发现你的行为模式(钻石版)》-开篇
  7. 数据交互智能终端设想
  8. Eclipse导入类库【Java】
  9. 在MAC Xcode下安装OpenCV
  10. TCP/IP入门(3) --传输层