Not Equal on a Segment CodeForces - 622C
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.
Example
6 4 1 2 1 1 3 5 1 4 1 2 6 2 3 4 1 3 4 2
2 6 -1 4
题意就是 在一串数字中给出前后区间 和x 找出区间内与x不等的元素下标
这道题可以用一个特殊的结构pos数组 记录与此元素相同连续串的首元素位置
如果这个元素与 前面一个元素的值是相同的 就记录下pos[i]=pos[i-1] 这种情况就会导致 如果出现 1 1 1连续的1 那么他们的pos 就会变成 x x x 只要是连续相同 那么后面的值得元素的pos就会与第一个值得元素相同 连续相同元素的线段 指向最初的那个 而最初的元素一定是他自身的位置 也就是判断 如果这个pos[r]<=l && r处值为x 也就说 他是一只连续到r的 一定是-1 如果这个最右端的元素不是x直接输出即可 如果最右端的是x且pos[r]>l也就说 中间间断过 否则这个值一定会<=l 那么输出pos[r]即为与他相同元素的第一个 由于大于l那么-1 必然与他不相等 而且这个位置必然>=l 也就是构造一个 连续元素的链结构 把相同元素都指到第一个元素的位置 然后如果 不等 就把它指向自身 表示这个值元素的起始位置 那么他前一个元素必然与他不相等
当时想了好久用来快排二分啥的都没过 。。。 ORZ
code:
#include<bits/stdc++.h>
using namespace std;
int a[200010],pos[200010];
int main()
{int n,m;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]==a[i-1])pos[i]=pos[i-1];else pos[i]=i; }while(m--){int s,e,x;scanf("%d%d%d",&s,&e,&x);if(a[e]!=x)printf("%d\n",e);else if(a[e]==x&&pos[e]<=s)puts("-1");else if(a[e]==x&&pos[e]>s)printf("%d\n",pos[e]-1);}return 0;
}
Not Equal on a Segment CodeForces - 622C相关推荐
- CodeForces - 622C Not Equal on a Segment(思维+水题)
题目链接:点击查看 题目大意:先给出一个长度为n的数列,然后给出m次询问,每次询问的格式是l,r,x,其中[l,r]代表的是数列的下标范围,要求我们输出任意一个在区间[l,r]内值不等于x的下标 题目 ...
- Not Equal on a Segment(CF-622C)
Problem Description You are given array a with n integers and m queries. The i-th query is given wit ...
- Longest k-Good Segment CodeForces - 616D(尺取法)
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in ...
- 2016区域赛前冲刺训练
UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...
- 基础算法 —— 模拟思维
[概述] 模拟,是根据实际问题建立模型,模拟实际按程序走一遍,最终求出答案. 思维,则是与逻辑思维有关,其需要针对题意.数据范围等抽丝剥茧抽离出有用的信息,从而得出一个结果. 对于一般的模拟,直接根据 ...
- 技术派-汇编语言指令集(intel X86系列)
针对汇编语言指令集(intel X86系列8086/80186/80286/80386/80486) AAA - Ascii Adjust for Addition AAD - Asci ...
- cf #825 Div.2(A~C2)
Cf #825 Div.2 文章目录 Cf #825 Div.2 [A. Make A Equal to B](https://codeforces.com/contest/1736/problem/ ...
- CodeForces - 616D Longest k-Good Segment
CodeForces - 616D Longest k-Good Segment 题意: 有包含n个数的序列a,求能找到最长的区间包含不超过k个不同的元素. 题解: 尺取法,先固定L,然后移动R,R每 ...
- codeforces EDU segment tree
本文以codeforces EDU segment tree为资料 content introdcution problems & solutions A. Sign alternation ...
最新文章
- Python命名空间和作用域
- HDU - 3530 Subsequence(单调队列+思维)
- 我的2021年度总结
- 看奥运之一:实力是最重要的
- python制作安装包(setup.py)
- 后来朋友选了伪原创工具下载这个词
- php7 验证url格式,url的组成格式为
- 1701. Ostap and Partners(并查集-关系)
- 获取页面元素的滚动位置,兼容各浏览器
- 21天Jmeter打卡Day18 前置处理器_熟悉常用组件
- 设置电脑的保护色(绿豆沙色)
- 聚类分析在SPSS上的实现与结果分析——基于SPSS实验报告
- 百融大数据自助查询_【百融云创科技股份有限公司现在大数据公司被查,百融受影响了吗】-看准网...
- 电脑分区后,电脑提醒没有权限在此位置保存文件怎么办?
- You are what you read 笔记
- F1DC2706双模数据透传蓝牙模块AT指令使用介绍
- 2021-08-16
- 2021Java校招笔试题答案及评分标准
- Golang#Typora-Golang笔记
- json进阶---jackson底层之JsonParser理解使用(springboot多结构参数的映射方法的实现思路)
热门文章
- springboot 整合 kafka demo 顺便看一下源码
- sharding-sphere按月动态分表
- 改造一下jeecg中的部门树
- Android 集成微信支付详解
- IP协议包中的TTL(Time-To-Live)
- 支付宝生成RSA密钥,上传应用公钥的完整流程
- ELK套件FileBeat部署
- 鼠标问题:鼠标拖拽不灵敏,准备复制拖动的半截就断了
- 自定义安装mysql linux_linux下 安装mysql 问题
- ad证书服务器在ADgroup,ACS 5.x :根据AD组成员配置示例和Authorization命令的TACACS+认证...