题目: 题目描述 给定一个长度为 � n 的序列 � a,有 � q 次询问,每次询问一段区间 [ � , � ] [l,r],判断能否选出三个不同的下标 ( � , � , � ) (i,j,k),满足以 ( � � , � � , � � ) (a i ,a j ,a k ) 为边长,可以构成三角形
输入格式 输入数据有 � + 2 q+2 行
第一行两个整数 � , � n,q
接下来一行 � n 个正整数,第 � i 个数为 � � a i
接下来 � q 行,每行两个正整数 � , � l,r 保证 1 ≤ � ≤ � ≤ � 1≤l≤r≤n,代表询问区间 [ � , � ] [l,r]
输出格式 � q 行,每行请判定,若判定成功则输出 Triangle
否则输出 Not triangle
输入输出样例 输入 #1复制
5 4
1 3 6 5 26
1 3
2 5
3 5
1 2
输出 #1复制 Not triangle
Triangle
Not triangle
Not triangle
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,m,a[maxn],l[maxn],r[maxn];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i]; T463178
}
for(int i=1;i<=m;i++){
cin>>l[i]>>r[i];
}
int k=0;
for(int i=1;i<=m;i++){
if(r[i]-l[i]+1<3){
cout<<"Not triangle"<<endl;
k=1;
continue;
}
for(int j=l[i];j<=r[i];j++){
if(a[i]+a[i+1]>a[i+2]){
if(a[i]+a[i+2]>a[i+1]){
if(a[i+1]+a[i+2]>a[i]){
cout<<"Triangle"<<endl;
break;
}
}
}
if(a[i+2]!=r[i]) break;
}
cout<<"Not triangle"<<e ndl;
}
return 0;
}