• 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
    ");
            }
        }
    }
    
    
    
  • 相关阅读:
    HTML5 h1多层次样式问题
    spellcheck
    Favicon
    设计模式
    CSS 宽高的计算
    行高计算
    White-space 属性
    简约插件Plug-in for simple
    js类型及其判断
    前端路由
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934453.html
Copyright © 2020-2023  润新知