2019年杭州师范大学第十二届程序设计竞赛 B:Little Sub and Triples(思维+枚举)

Little Sub and Triples

【题解】

\frac{e^{a}e^{b}}{e^{c}}>1 即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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值