zoukankan      html  css  js  c++  java
  • CodeForces 622C

    题意:
    给你一个数组,m个询问,l,r,x;让你输出在区间[ l , r ]上哪个位置不等于x。
    思路:
    额。。我这个思路还是剽来的。。。不过真心赞啊。
    开个p数组,直接记录数组每个元素的位置,并且实现是最右。
    然后对于每个查询,直接询问下限位置的a[ i ]是否等于x,不等于直接输出,等于的话调用p数组,就可以知道,最右啊,然后判断一下最右+1是否<=上限。然后就好啦。这种效率超级提高啊。长见识,长见识。

    code…

    //#include <bits/stdc++.h>
    #include<cstdio>
    #include<iostream>
    #include<math.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    const double eps=1e-6;
    const double pi=acos(-1.0);
    const int mod=998244353;
    const int INF=0x3f3f3f3f;
    
    const int N=1e5+10;
    
    int a[N*2];
    int p[N*2];
    
    int main()
    {
        int s,t,x,n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        p[n]=n;
        for(int i=n-1;i>=1;i--)
        {
            if(a[i]==a[i+1])
                p[i]=p[i+1];
            else
                p[i]=i;
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&s,&t,&x);
            if(a[s]!=x){
                printf("%d
    ",s);
            }
            else{
                if(p[s]+1<=t)
                    printf("%d
    ",p[s]+1);
                else
                    printf("-1
    ");
            }
        }
    }
    
    
    
  • 相关阅读:
    康师傅JVM:运行时数据区概述及线程(三)
    康师傅JVM:程序计数器(四)
    Git常用命令
    Arthas概述
    康师傅JVM:JVM与Java体系结构(一)
    LabVIEW 连接MySQL数据库
    LabVIEW dll 崩溃
    LabVIEW 关于定时的研究
    NI 配置管理软件MAX的一些功能使用介绍
    LabVIEW 串口通信
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934453.html
Copyright © 2011-2022 走看看