CodeForces 622C Not Equal on a Segment
预处理p[i],p[i]表示:【p[i],i】这段闭区间上所有数字都是a[i]
询问的时候,如果xi==a[ri]并且p[ri]<=li,一定无解
剩下的情况都是有解的,如果xi!=a[ri],那么输出ri,否则输出p[ri]-1。
另外,看到有大牛博客说可以用线段树,大致是这样的:
线段树保存区间最大值与最小值,
如果询问的区间上最小值==最大值,那么无解;
剩下的情况都是有解;如果xi不等于最小值,那么输出最小值位置;如果xi不等于最大值,那么输出最大值位置。
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std; const int maxn=+;
int a[maxn],p[maxn];
int n,m; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
p[]=;
for(int i=;i<=n;i++)
{
if(a[i]==a[i-]) p[i]=p[i-];
else p[i]=i;
} //p[i]表示,【p[i],i】这段闭区间上所有数字都是a[i] for(int i=;i<=m;i++)
{
int li,ri,xi;
scanf("%d%d%d",&li,&ri,&xi);
if(xi==a[ri]&&p[ri]<=li) printf("-1\n");
else
{
if(xi!=a[ri]) printf("%d\n",ri);
else printf("%d\n",p[ri]-);
}
} return ;
}
CodeForces 622C Not Equal on a Segment的更多相关文章
- Codeforces 622C Not Equal on a Segment 【线段树 Or DP】
题目链接: http://codeforces.com/problemset/problem/622/C 题意: 给定序列,若干查询,每个查询给定区间和t,输出区间内任意一个不等于t的元素的位置. 分 ...
- codeforces 622C C. Not Equal on a Segment
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 7 C. Not Equal on a Segment 并查集
C. Not Equal on a Segment 题目连接: http://www.codeforces.com/contest/622/problem/C Description You are ...
- C. Not Equal on a Segment(codeforces)
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...
- Codeforces gym101612 E.Equal Numbers(贪心)
传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的 ...
- CodeForces A. Many Equal Substrings
http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase La ...
- CF622C Not Equal on a Segment
题目链接: http://codeforces.com/problemset/problem/622/C 题目大意: 给定一个长度为n(n不超过200000)的序列,有m(m不超过200000)次询问 ...
- Codeforces 1188D Make Equal DP
题意:给你个序列,你可以给某个数加上2的幂次,问最少多少次可以让所有的数相等. 思路(官方题解):我们先给序列排序,假设bit(c)为c的二进制数中1的个数,假设所有的数最后都成为了x, 显然x &g ...
随机推荐
- C/C++ - 结构体实际申请的空间
C/C++ - 结构体实际申请的空间 如下的结构体,sizeof()大小,实际申请的空间以及理论上申请最佳空间 struct Spot { int x; int y; bool visible; in ...
- UVALive 3027 并查集
#include <cstdio> #include <queue> #include <cstring> #include <iostream> #i ...
- oracle常用高级sql---1
Oracle/Sql高级篇 1.TOP 子句 TOP 子句用于规定要返回的记录的数目. 对于拥有数千条记录的大型表来说,TOP 子句是非常有用的. SELECT TOP number|percen ...
- Zookeeper: configuring on centos7
thispassage is referenced, appreciated. ZooKeeper installation: Download from this site Install java ...
- mysql问题总结,远程登录
http://blog.sina.com.cn/s/blog_4550f3ca0101axzd.html 更改mysql数据库的数据库名 http://tech.sina.com.cn/s/s/200 ...
- UMeng崩溃日志如何进行symbiolicate
Application received signal SIGSEGV (null) ( 0 CoreFoundation 0x2f2dde9b + 154 1 libobjc.A.dylib 0x3 ...
- SQL Server 自定义快捷键
SQL Server程序员经常要在SSMS(SQL Server Management Studio)或查询分析器(2000以前)中编写T-SQL代码.以下几个技巧,可以提升工作效率. 以下说明以SS ...
- debug运行可以,release运行报错的原因及修改方法
通常我们开发的程序有2种模式:Debug模式和Release模式在Debug模式下,编译器会记录很多调试信息,也可以加入很多测试代码,方便我们程序员测试,以及出现bug时的分析解决Release模式下 ...
- 10317 Fans of Footbal Teams(并查集)
10317 Fans of Footbal Teams 时间限制:1000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: G++;GCC Description ...
- JS页面延迟执行一些方法(整理)
一般在JS页面延迟执行一些方法.可以使用以下的方法 jQuery.delay()方法简介 http://shawphy.com/2010/11/jquery-delay.html jQuery中que ...