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 ...
随机推荐
- HTML+CSS Day05 基本CSS选择器、复合CSS选择器与CSS继承性
1.基本CSS选择器 (1)标记选择器 <style> h1{ color:red; font-size:25px;} &l ...
- C --> OC with RunTime
前言 本来打算写一篇关于runtime的学习总结,无奈长篇大论不是我的风格,就像写申论一样痛苦,加之网上关于tuntime的文章多如牛毛,应该也够童子们学习的了,今天就随便聊聊我的理解吧. runti ...
- android:editable is deprecated: Use an <EditText> to make it editable
问题:android:editable is deprecated: Use an to make it editable 意思:Android的:编辑是反对:使用<</span> ...
- Lint Code——最多共线的点的个数
题目链接:http://www.lintcode.com/zh-cn/problem/max-points-on-a-line/# 条件:给一个点数组 目标:求出共线的点的最多个数 实现:时间复杂度- ...
- win10系统安装oracle11g时遇到INS-13001环境不满足最低要求
升级win10系统之后,需要重新安装Oracle,因为在安装Oralce11g时,使用64位的会出现各种不兼容问题,我每次安装都是使用32位的数据库. 在安装时点击setup.exe之后,出现了:[I ...
- hdu_5145_NPY and girls(莫队算法+组合)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5145 题意:给你n,m,共有n个女孩,标号为1—n,n个数xi表示第ith个女孩在第xi个教室,然后下 ...
- 修改maven本地仓库路径
修改maven配置文件conf/settings.xml 在setting标签中添加 <localRepository>E:/bhuwifi_java/repo</localRepo ...
- centos minimal Bind 主从服务器部署
实验环境 两台虚拟机BindM和BindS,装的系统都是centos6.3 minimal IP地址 主机名hostname 主DNS服务器 192.168.137.102 bindm.cas.c ...
- AngularJS Front-End App with Cloud Storage Tutorial Part 1: Building a Minimal App in Seven Steps
原文 : http://www.codeproject.com/Articles/1027709/AngularJS-Front-End-App-with-Cloud-Storage-Tutoria ...
- opcode修改
Smali: if-eqz opcode 38 if-nez opcode 39 SO: CMP R0,#0 00 28 CMP R0,#1 01 28