UPC Contest 1748 Little Sub and Triples

题目描述

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
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.

 

 

输入

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 231-1.

 

输出

For each query, print YES if it exists any legal triple or NO otherwise.

 

样例输入

复制样例数据

4 2
1 2 3 4
1 3
2 4

样例输出

NO
YES

思路:

           因为斐波那契数在达到第47个时就超出了1e9了。斐波那契数(1,2,3,5,8,13....)实际上就是满足不能构成三角形的一个连续边序列。所以在判断[l,r]的长度大于47就保证可以构成三角形。如果小于47的话,排序遍历一遍即可。

AC代码

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a[240000],b[240000];
int main()
{
    int n,q,r,l;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=q;i++)
    {
        int j,flag=0,k=0;
        scanf("%d%d",&l,&r);
        if(r-l+1>47)
            printf("YES\n");
        else
        {
            for(j=l;j<=r;j++)
                b[k++]=a[j];
            sort(b,b+k);
            for(j=2;j<k;j++)
            {
                if(b[j]<b[j-1]+b[j-2])
                {
                    printf("YES\n");
                    break;
                }
            }
            if(j==k)
                printf("NO\n");
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值