zoukankan      html  css  js  c++  java
  • Codeforces 1270B 灵感题

    B. Interesting Subarray
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    For an array aa of integers let's denote its maximal element as max(a)max(a), and minimal as min(a)min(a). We will call an array aa of kk integers interesting if max(a)min(a)kmax(a)−min(a)≥k. For example, array [1,3,4,3][1,3,4,3] isn't interesting as max(a)min(a)=41=3<4max(a)−min(a)=4−1=3<4 while array [7,3,0,4,3][7,3,0,4,3] is as max(a)min(a)=70=75max(a)−min(a)=7−0=7≥5.

    You are given an array aa of nn integers. Find some interesting nonempty subarray of aa, or tell that it doesn't exist.

    An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

    Input

    The first line contains integer number tt (1t100001≤t≤10000). Then tt test cases follow.

    The first line of each test case contains a single integer nn (2n21052≤n≤2⋅105) — the length of the array.

    The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (0ai1090≤ai≤109) — the elements of the array.

    It is guaranteed that the sum of nn over all test cases does not exceed 21052⋅105.

    Output

    For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in aa.

    Otherwise, output "YES" in a separate line. In the next line, output two integers ll and rr (1lrn1≤l≤r≤n) — bounds of the chosen subarray. If there are multiple answers, print any.

    You can print each letter in any case (upper or lower).

    Example
    input
    3
    5
    1 2 3 4 5
    4
    2 0 1 9
    2
    2019 2020
    
    output
    NO
    YES
    1 4
    NO
    
    Note

    In the second test case of the example, one of the interesting subarrays is a=[2,0,1,9]a=[2,0,1,9]: max(a)min(a)=90=94max(a)−min(a)=9−0=9≥4.

    /*
        只要存在合法字串,那么一定存在长度为2的合法子串
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #define maxn 200010
    using namespace std;
    int a[maxn],n;
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
            scanf("%d",&n);
            for(int i=1;i<=n;i++)scanf("%d",&a[i]);
            if(n==1){
                puts("NO");
                continue;
            }
            bool flag=0;
            for(int i=2;i<=n;i++){
                if(abs(a[i]-a[i-1])>=2){
                    flag=1;
                    puts("YES");
                    printf("%d %d
    ",i-1,i);
                    break;
                }
            }
            if(!flag)puts("NO");
        }
        return 0;
    } 
  • 相关阅读:
    为Internal页面添加一个Unit Test的运行入口
    使用 AWSTATS 来查看IIS/iisnode 日志
    用issnode+IIS来托管NodeJs Server之四:支持Debug
    Restify实践
    Mocha实践
    Graphite实战
    StatsD与Graphite联合作战
    单元测试
    NHibernate配置
    NHibernate概念
  • 原文地址:https://www.cnblogs.com/thmyl/p/12298065.html
Copyright © 2011-2022 走看看