http://acm.hznu.edu.cn/OJ/problem.php?cid=1263&pid=1

http://acm.hznu.edu.cn/OJ/problem.php?id=2580

题意:问区间里有没有三个数能组成三角形的边长

题解:

判定一个区间能否组成的方法是排序后判断相邻的三个数字是否能组成,直接暴力会超时。

然而,如果一直满足a[i]+a[i+1]=a[i+2],就变成了斐波那契数列,而斐波那契数列的增长速度不用多少项就会超过数字大小的上限,打个表实际上是第56项。

于是当区间长度大于60直接输出YES,否则暴力判定即可,注意要使用long long

珍爱头发、远离endl;

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp,sum;
ll a[N];
ll b[N];
char str;
struct node{};
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //scanf("%d",&t);
    //while(t--){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    int l,r;
    while(m--){
        scanf("%d%d",&l,&r);
        if(r-l+1<3){
            cout<<"NO"<<"\n";
            continue;
        }
        if(r-l+1>60){
            cout<<"YES"<<"\n";
            continue;
        }
        bool flag=1;
        for(int i=l;i<=r;i++){
            b[i]=a[i];
        }
        sort(b+l,b+r+1);
        for(int i=l;i<r-1;i++){
            if(b[i]+b[i+1]-b[i+2]>0){
                cout<<"YES"<<"\n";
                flag=0;
                break;
            }
        }
        if(flag){
            cout<<"NO"<<"\n";
        }
    }
    //}

#ifdef DEBUG
	printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Hello world!" << endl;
    return 0;
}