Codeforces Round #275 (Div. 2)

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

链接:http://codeforces.com/contest/483


A. Counterexample
time limit per test
1 second
memory limit per test
256 megabytes

Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.

Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.

You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r.

More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.

Input

The single line contains two positive space-separated integers l, r (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).

Output

Print three positive space-separated integers a, b, c — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.

If the counterexample does not exist, print the single number -1.

Sample test(s)
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
Note

In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.

In the second sample you cannot form a group of three distinct integers, so the answer is -1.

In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.


简单构造:第一个数和第二个数互素,第二个数和第三个数互素,第一个数和第三个数不互素,显然找偶奇偶序列


#include <cstdio>
#define ll long long
ll gcd(ll a, ll b) 
{
    return b ? gcd(b, a % b) : a;  
}
int main()
{
    ll a, b;
    ll ans[3] = {0};
    scanf("%I64d %I64d", &a, &b);
    if(b == a + 1)
    {
        printf("-1\n");
        return 0;
    }
    if(a % 2 == 1)
    {
        ans[0] = a + 1;
        ans[1] = a + 2;
    }
    else
    {
        ans[0] = a;
        ans[1] = a + 1;   
    }
    for(ll i = a + 2; i <= b; i++)
    {
        if(gcd(ans[1], i) == 1 && gcd(ans[0], i) != 1)
        {
            ans[2] = i;
            break;
        }
    }
    if(ans[2] == 0)
    {
        printf("-1\n");
        return 0;
    }
    printf("%I64d %I64d %I64d\n", ans[0], ans[1], ans[2]);
}




B. Friends and Presents
time limit per test
1 second
memory limit per test
256 megabytes

You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.

In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.

Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.

A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.

Input

The only line contains four positive integers cnt1, cnt2, x, y (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.

Output

Print a single integer — the answer to the problem.

Sample test(s)
Input
3 1 2 3
Output
5
Input
1 3 2 3
Output
4
Note

In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.

In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.


构造两个序列,第一个序列要有cnt1个数且其中不能有x的倍数,第二个序列要有cnt2个数且其中不能有y的倍数。要求求出这两个序列中的最大数的最小值。


如果答案是ans则ans+1也满足可以发现问题满足二分做法的条件,cnt1个数为num - num / x,及1到num中不包含x倍数的数的个数,同理

cnt2个数为num - num / y,还有一点要注意的是必须满足cnt1 + cnt2 <= num - num / (x * y)因为题目要求两个集合中的元素不同,又因为x,y必然互素,所以cnt1和cnt2的和必须小于1到num中不包含(x * y)倍数的数的个数,不然两个集合必然出现重复元素,然后二分num的值便可以得到最终答案。


#include <cstdio>
int cal(int a, int b)
{
    return a - a / b;
}
int main()
{
    int cnt1, cnt2, x, y;
    scanf("%d %d %d %d", &cnt1, &cnt2, &x, &y);
    int l = 1, r = 2e9;         
    while(l < r)
    {              
        int mid = l + (r - l) / 2;
        if(cnt1 <= cal(mid, x) && cnt2 <= cal(mid, y) && cnt1 + cnt2 <= cal(mid, x * y))
            r = mid;
        else
            l = mid + 1;
    }
    printf("%d\n", r);  
}



C. Diverse Permutation
time limit per test
1 second
memory limit per test
256 megabytes

Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,   p2,   ...,   pn.

Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.

Input

The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).

Output

Print n integers forming the permutation. If there are multiple answers, print any of them.

Sample test(s)
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note

By |x| we denote the absolute value of number x.



一个包含n个数的数列,要求相邻两元素差的绝对值的数的个数为k,要求构造这样的数列。

简单的构造题,k--并变号判断即可


#include <cstdio>
#include <cstring>
int const MAX = 1e5 + 5;
int a[MAX];
int hash[MAX];
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    memset(hash, 0, sizeof(hash));
    a[1] = 1;
    hash[a[1]] = 1;
    int cnt = 1;
    for(int i = 2; i <= n; i++)
    {
        cnt++;
        a[i] = a[i - 1] + k;
        hash[a[i]] = 1;
        if(k > 0)
            k--;
        else
            k++;
        k *= -1;
        if(k == 0)
            break;
    }
    for(int i = 1; i <= n; i++)
        if(!hash[i])
            a[++cnt] = i;
    for(int i = 1; i < n; i++)
        printf("%d ", a[i]);
    printf("%d\n", a[n]);

}




D. Interesting Array
time limit per test
1 second
memory limit per test
256 megabytes

We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value should be equal to qi.

Your task is to find any interesting array of n elements or state that such array doesn't exist.

Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal — as "and".

Input

The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits.

Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.

Output

If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them.

If the interesting array doesn't exist, print "NO" (without the quotes) in the single line.

Sample test(s)
Input
3 1
1 3 3
Output
YES
3 3 3
Input
3 2
1 3 3
1 3 2
Output
NO


题意如题,还是构造数列,线段树维护+判断


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int const MAX = 110000;
struct Node
{
    int l, r;
    int val;
};
Node tree[10 * MAX];
Node a[MAX];
vector<int> ans;

void build(int step, int l, int r)
{
    tree[step].l = l;
    tree[step].r = r;
    tree[step].val = 0;
    if(l == r)
        return;
    int mid = (l + r) >> 1;
    build(step << 1, l, mid);
    build(((step << 1) + 1), mid+1, r);
}
void update(int step, int l, int r, int val)
{
    if(tree[step].l == l && tree[step].r == r)
    {
        tree[step].val |= val;
        return;
    }
    int mid = (tree[step].l + tree[step].r) >> 1;
    if(r <= mid)
        update(step << 1, l, r, val);
    else if(l > mid)
        update((step << 1) + 1, l, r, val);
    else
    {
        update(step << 1, l, mid, val);
        update((step << 1) + 1, mid+1, r, val);
    }
}
int query(int step, int l, int r)
{
    if(tree[step].l == l && tree[step].r == r)
        return tree[step].val;
    int mid = (tree[step].l + tree[step].r) >> 1;
    if(r <= mid)
        return query(step << 1, l, r);
    if(l > mid)
        return query((step << 1) + 1, l, r);
    else
        return query(step << 1, l, mid) & query((step << 1) + 1, mid+1, r);
}
void solve(int step)
{
    if(step != 1)
        tree[step].val |= tree[step >> 1].val;
    if(tree[step].l == tree[step].r)
    {
        ans.push_back(tree[step].val);
        return ;
    }
    solve(step << 1);
    solve((step << 1) + 1);
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    build(1, 1, n);
    for(int i = 0; i < m; i++)
    {
        scanf("%d %d %d", &a[i].l, &a[i].r, &a[i].val);
        update(1, a[i].l, a[i].r, a[i].val);
    }
    bool flag = true;
    for(int i = 0; i < m; i++)
    {
        if(query(1, a[i].l, a[i].r) != a[i].val)
        {
            flag = false;
            break;
        }
    }
    solve(1);
    if(flag)
    {
        printf("YES\n");
        for(int i = 0; i < ans.size(); i++)
            printf("%d%c",ans[i], i == n ? '\n' : ' ');
        ans.clear();
        printf("\n");
    }
    else
        printf("NO\n");
}



Zemax实战:手把手教你设计一个40倍、NA0.65的显微物镜(附初始结构文件) 本文详细介绍了使用Zemax设计40倍、NA0.65显微物镜的完整流程,从初始结构搭建到优化验证,涵盖光学设计的关键技巧和实战经验。通过分阶段优化策略和公差分析,帮助工程师快速掌握高倍显微物镜的设计方法,提升光学系统性能。 阅读详情

相关推荐

百度API实现人流量数量检测(动态)

百度的这个API还挺好用的,对与不追求高精度的人来说非常适用,结合他官方给的文档,极易上手。 需要做的就是通过API Key和Secret Key获取的access_token。 然后稍微修改下代码就行,但是他给的代码并没有直接从摄像头获取视频,而是读取一个文件夹,那么就需要自己先对摄像头的输出视频进行处理。 识别结果如下,"person_num"是当前画面的人数,in是累计进入的人数,out是累计走出去的人数。 他这个有个缺点就是返回值里边并没有实时返回in和out的值,而是都是0,但是这个图片上有,图片

qq_42479987的博客 3345

2018/8/13

线段树,树状数组,lazy优化 好困不多bb了 一: C - Ultra-QuickSort  POJ - 2299  In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapp...

qq_40214483的博客 368

强化学习优化多目标冲突推理的决策过程设计

1. 背景介绍 强化学习(Reinforcement Learning,RL)作为机器学习的一个重要分支,近年来在计算机科学和人工智能领域取得了显著的进展。其核心思想是通过试错来学习最优策略,从而在复杂的环境中实现目标。然而,在多目标冲突推理(Multi-Objective Conflict Reasoning,MOCR)问题上,强化学习面临着诸多挑

AI天才研究院 1466

Codeforces Round #275 (Div. 1)B(线段树+位运算)

B. Interesting Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We'll call an array of n non-negative i

cq_phqg 1029

Codeforces 482B Interesting Array(位运算+差分+线段树)

巧妙的题目。

ZZY的博客 272

Codeforces Round #275 (Div. 2) D题 (线段树)

D. Interesting Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We'll call an array of n non-negative integers a

Tc的专栏 1318

CodeForces 482B. Interesting Array

We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) ...

weixin_30896763的博客 173

Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n。求一个序列其中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个。求序列、 思路:1~k+1。构造序列前段,之后直接输出剩下的数。前面的构造可以根据,两项差的绝对值为1~k构造。 AC代码: #include #include

n-1 1374

构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

题目传送门 1 /* 2 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放。因为是绝对差值,从n开始一下一上, 3 这样保证不会超出边界并且以防其余的数相邻绝对值差>k 4 */ 5 /************************************************ 6 Author ...

weixin_30894583的博客 76

codeforces Round #275(div2) D解题报告

题目大意: 假设有n个非负数,现在有m个限制,a[l] & a[l+1] & a[l+2] ... & a[r] = q。要求根据上述的限制,输出符合要求的1~n个数,如若不能则输出“NO”。 解法: 我们先挖掘题意,弄清楚题目给的已知条件和要我们输出什么。 a[l] & a[l+1] & a[l+2] ... & a[r] = q,这是每个限制的基本形式,由“&”我们可以得知,如若q中的某一个bit是1的话,则要求a[l]~a[r]中的那个bit位都为1。这个条件看似是限制

旅行者西瓜 1303

codeforces Round #275(div2) A解题报告

A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Your friend has recently learned about cop

旅行者西瓜 906

Codeforces Round #275 (Div. 2) c

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33919941的博客 91

codeforces Round #275(div2) B解题报告

B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have two friends. You want to pr

旅行者西瓜 1008

Codeforces Round #275 (Div. 2) D

D. Interesting Array

A Cube Master 480

Codeforces Round #275 (Div. 2) D.Interesting Array】线段树

链接: CodeForces-483D Interesting Array 题意 让你构造一个数列,满足m种限制条件,每种限制条件是l,r,x,要求构造的序列区间[l,r] 与运算的值结果为x。 做法 首先由一个拆位的做法,对于每次询问,拆成30位分别进行构造,对于每个为0的位,区间查询这一位下[l,r]的和是不是等于区间长度,也就是看区间[l,r]与的结果是否为0。对于每个为1的位,区间更新。但...

lajiyuan的博客 245

Codeforces Round #275 (Div. 2) b

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33817333的博客 92

Codeforces Round #275 (Div. 2) A

Codeforces Round #275 (Div. 2) A

Notdeep__acm的专栏 987

Codeforces Round #275 (Div. 2) B

B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have two friends. You want to pr

qq243887的专栏 337
上一篇: HDU 4081 Qin Shi Huang's National Road System (Prim, 次小生成树)
下一篇: 第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安站
_TCgogogo_
博客等级 码龄12年 615粉丝 1081原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值