【题解】
即a+b>c,又a<=b<=c,所以题意是问在给定区间内是否存在三条边能组成三角形。
int范围内(0x7fffffff),即使是最坏情况一直满足a[i]+a[i+1]=a[i+2],就变成了斐波那契数列,而斐波那契数列的增长速度不用多少项就会超过数字大小的上限,打个表实际上是第47项。
当区间大小超过47时输出YES,否则暴力枚举。
【代码】
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
int n,q; scanf("%d%d",&n,&q);
ll a[200005];
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
vector <ll> vec;
while(q--){
int f=0;
int l,r; scanf("%d%d",&l,&r);
if(r-l+1>47) f=1;
else{
vec.clear();
for(int i=l;i<=r;i++) vec.push_back(a[i]);
sort(vec.begin(),vec.end());
for(int i=2;i<vec.size();i++){
if(vec[i]<vec[i-1]+vec[i-2]){
f=1;
}
}
}
if(f) puts("YES");
else puts("NO");
}
return 0;
}
【题目】
Little Sub and Triples
Time Limit: 1 s Memory Limit: 256 MB
Submission:964 AC:120 Score:100.00
Description
Little Sub has learned a new word ’Triple’, which usually means a group with three elements in it. Now he comes up with an interesting problem for you.
Define F(a,b,c) = e^a∗e^b / e^c
Given an positive integer sequence A and some queries. In each query, you have to tell if there exists a triple T = (x, y, z) such that:
1.x, y, z are unique integers.
2.l ≤ x, y, z ≤ r.
3.Ax ≤ Ay ≤ Az.
4.F(Ax,Ay,Az) > 1.
Input
The first line contains two positive integers n, q(1 ≤ n, q ≤ 200000).
The second line contains n positive integers, indicating the integer sequence. The next q lines describe each query by giving two integer l, r(1 ≤ l ≤ r ≤ n). All given integers will not exceed 2^31 − 1.
Due to some reasons, when l>r, please consider it as an empty interval. Sorry for it.
Output
For each query, print YES if it exists any legal triple or NO otherwise.
Samples
input:
4 2
1 2 3 4
1 3
2 4
output:
NO
YES