Sort distinct integers in the range [0..N-1]

本文展示了一个通过位类标记整数的程序,用于输入任意范围内的整数并按顺序输出,实现了一种高效的排序算法。

下面的程序通过位类标记一个整数是否被输入,然后将所有输入的整数按顺序输出。

 

在论坛看到的

http://topic.youkuaiyun.com/u/20100106/22/956c60f1-8b1b-474d-b19b-29082a8c33f2.html

   B. Even Modulo Pair time limit per test1 second memory limit per test256 megabytes    You are given a strictly increasing sequence of positive integers a1<a2<…<an . Find two distinct elements x and y from the sequence such that x<y and ymodx is even, or determine that no such pair exists. pmodq denotes the remainder from dividing p by q . DeepL 翻译    给你一个**严格递增的正整数序列 a1<a2<…<an 。从序列中找出两个不同的元素 x 和 y ,使得 x<y 和 ymodx 是偶数,或者确定不存在这样的一对元素。 pmodq 表示 p 除以 q 所得的余数。    Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤2⋅104 ). The description of the test cases follows. The first line of each test case contains one integer n (2≤n≤105 ) — the length of the sequence. The second line of each test case contains n integers a1,a2,…,an (1≤a1<…<an≤109 ) — the given sequence. It is guaranteed that the sum of n over all test cases does not exceed 105 . DeepL 翻译    输入 每个测试包含多个测试用例。第一行包含测试用例的数量 t ( 1≤t≤2⋅104 )。测试用例说明如下。 每个测试用例的第一行包含一个整数 n ( 2≤n≤105 ) - 序列的长度。 每个测试用例的第二行包含 n 个整数 a1,a2,…,an ( 1≤a1<…<an≤109 )。( 1≤a1<…<an≤109 ) - 给定序列。 保证所有测试用例中 n 的总和不超过 105 。    Output For each test case: If no such pair exists, output -1. Otherwise, output two integers x and y — the elements that satisfy the condition. If there are multiple valid pairs, you may output any of them. DeepL 翻译    输出 对于每个测试用例: 如果不存在这样的一对,则输出 -1。 否则,输出两个整数 x 和 y - 满足条件的元素。 如果存在多个有效的元素对,可以输出其中任意一个。 Example InputCopy 4 5 1 3 4 5 6 6 2 3 5 7 11 13 4 2 3 13 37 3 17 117 1117 OutputCopy 3 5 3 11 -1 17 1117    Note Visualizer link In the first test case, choosing x=3 and y=5 yields ymodx=5mod3=2 , which is even. In the third test case, it is clear that no valid pair exists. GNU G++17 7.3.0     1你有啥好的想法
最新发布
11-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值