7_6_S题 Not Equal on a Segment题解 [codeforces 622C] (贪心)
来源:互联网 发布:洗相片软件 编辑:程序博客网 时间:2024/06/05 01:57
题目链接
简单题意
给出一个序列和多次询问,每次询问会给出一个范围l~r和一个数k,要求在l到r的区间里找出任意一个与k不同的数;
思路
只要给出的序列中存在两个以上的数,就肯定可以找到一个和k不同的数,只要记录一下同样的数最左的坐标,然后分情况判断输出就可以了。
代码
#include <cstdio>using namespace std;const int maxn = 2e5+10;int num[maxn];int loc[maxn];int main(){ int n,m; scanf("%d %d",&n,&m); for(int i = 1 ; i <= n ; i++) scanf("%d",num+i); num[0] = -1; for(int i = 1 ; i <= n ; i ++){ if(num[i] == num[i-1]) loc[i] = loc[i-1]; else loc[i] = i; } for(int i = 0 ; i < m ; i ++){ int l,r,x; scanf("%d %d %d",&l,&r,&x); if(x != num[r]) printf("%d\n",r); else if(loc[l] == loc[r]) puts("-1"); else printf("%d\n",loc[r]-1); }}
0 0
- 7_6_S题 Not Equal on a Segment题解 [codeforces 622C] (贪心)
- Codeforces 622 C. Not Equal on a Segment
- CodeForces 622 C. Not Equal on a Segment(水~)
- CodeForces 622C Not Equal on a Segment
- CodeForces 622C Not Equal on a Segment
- Codeforces 622C Not Equal on a Segment
- CodeForces 622C F - Not Equal on a Segment
- Educational Codeforces Round 7--C. Not Equal on a Segment
- Educational Codeforces Round 7 C. Not Equal on a Segment
- Educational Codeforces Round 7-C. Not Equal on a Segment
- Not Equal on a Segment CodeForces
- Not Equal on a Segment CodeForces
- Not Equal on a Segment CodeForces
- Not Equal on a Segment CodeForces
- Educational Codeforces Round 7 CF622C Not Equal on a Segment
- Codeforces 622C Not Equal on a Segment 【线段树 or dp】
- Codeforces 622C Not Equal on a Segment(线段树)
- CodeForces 622C Not Equal on a Segment(并查集)
- nginx环境中配置网站目录权限设置
- 几个 Context 上下文的区别
- 输油管道 (Standard IO)
- CnCrypt代码 之 SYSTEMTIME转字符串,字符串转SYSTEMTIME
- 运营老司机分享:APP运营推广那些事
- 7_6_S题 Not Equal on a Segment题解 [codeforces 622C] (贪心)
- 线程池
- 最近公共祖先(2)
- setpwent()
- csdn如何转载别人的文章
- 查询数组中的学生信息
- SQL Server游标的使用
- Spring 表达式语言之 SpEL 语法
- iOS开发Navigation 导航栏渐变