2022-10-09
B. Mathematical Circus

A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — nn and kk, where nn is even. Next, he takes all the integers from 11 to nn, and splits them all into pairs (a,b) (each integer must be in exactly one pair) so that for each pair the integer (a+k)⋅b is divisible by 4 (note that the order of the numbers in the pair matters), or reports that, unfortunately for viewers, such a split is impossible.
Burenka really likes such performances, so she asked her friend Tonya to be a magician, and also gave him the numbers nn and kk.
Tonya is a wolf, and as you know, wolves do not perform in the circus, even in a mathematical one. Therefore, he asks you to help him. Let him know if a suitable splitting into pairs is possible, and if possible, then tell it.
Input
The first line contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. The following is a description of the input data sets.
The single line of each test case contains two integers nn and k (2≤n≤2⋅105 , 0≤k≤109≤k≤109
n is even) — the number of integers and the number being added kk.
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, first output the string “YES” if there is a split into pairs, and “NO” if there is none.
If there is a split, then in the following n2 lines output pairs of the split, in each line print 2 numbers — first the integer a, then the integer b.
Example
input
Copy
4
4 1
2 0
12 10
14 11
output
Copy
YES
1 2
3 4
NO
YES
3 4
7 8
11 12
2 1
6 5
10 9
YES
1 2
3 4
5 6
7 8
9 10
11 12
13 14
Note
In the first test case, splitting into pairs (1,2)(1,2) and (3,4)(3,4) is suitable, same as splitting into (1,4)(1,4) and (3,2)(3,2).
In the second test case, (1+0)⋅2=1⋅(2+0)=2(1+0)⋅2=1⋅(2+0)=2 is not divisible by 44, so there is no partition.
首先,谈论形如a*b=kn,k为设定的基数,n为n倍的式子时,应当考虑余数的可能而不是奇偶;寻找规律的时候注意考虑是不是讨论重复了,比如最开始,k%21与k%41。
其次,对于不可能的情况没有找到,
×-》k0,
√-》k%40
因为加上4的倍数对于原来的a来说没有任何改变,情况变成了1-n的双双组队之和要是4的倍数。而符合的只有n/4对,小于n/2对。
再次,观察猜想到组队是相邻两数就大大减少难度。

2022-10-10
B. Promo
The store sells nn items, the price of the ii-th item is pipi. The store’s management is going to hold a promotion: if a customer purchases at least xx items, yy cheapest of them are free.
The management has not yet decided on the exact values of xx and yy. Therefore, they ask you to process qq queries: for the given values of xx and yy, determine the maximum total value of items received for free, if a customer makes one purchase.
Note that all queries are independent; they don’t affect the store’s stock.
Input
The first line contains two integers nn and qq (1≤n,q≤2⋅1051≤n,q≤2⋅105) — the number of items in the store and the number of queries, respectively.
The second line contains nn integers p1,p2,…,pn (1≤pi≤1061≤pi≤106), where pi — the price of the ii-th item.
The following qq lines contain two integers xixi and yiyi each (1≤yi≤xi≤n1≤yi≤xi≤n) — the values of the parameters xx and yy in the ii-th query.
Output
For each query, print a single integer — the maximum total value of items received for free for one purchase.
Example
input
Copy
5 3 5 3 1 5 2 3 2 1 1 5 3
output
Copy
8 5 6
Note
In the first query, a customer can buy three items worth 5,3,5, the two cheapest of them are 3+5=8.
In the second query, a customer can buy two items worth 5 and 5, the cheapest of them is 5.
In the third query, a customer has to buy all the items to receive the three cheapest of them for free; their total price is 1+2+3=6
简单的前缀和,意识到是求长为x的最大段中前y个之和
!!错误是索引的计算
√:p[n-x+y]-p[n-x]
×:p[n-y-1]-p[n-x]

2022-10-11
B. Fun with Even Subarrays
You are given an array aa of nn elements. You can apply the following operation to it any number of times:
● Select some subarray from aa of even size 2k2k that begins at position l 1≤l≤l+2⋅k−1≤n, k≥1k≥1) and for each ii between 00 and k−1k−1 (inclusive), assign the value al+k+ial+k+i to al+i
For example, if a=[2,1,3,4,5,3] , then choose l=1 and k=2 , applying this operation the array will become a=[3,4,3,4,5,3]
Find the minimum number of operations (possibly zero) needed to make all the elements of the array equal.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤2⋅104 ) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer nn (1≤n≤2⋅105 ) — the length of the array.
The second line of each test case consists of nn integers a1,a2,…,an ( 1≤ai≤n) — the elements of the array aa.
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅105 .
Output
Print tt lines, each line containing the answer to the corresponding test case — the minimum number of operations needed to make equal all the elements of the array with the given operation.
Example
input
Copy
5 3 1 1 1 2 2 1 5 4 4 4 2 4 4 4 2 1 3 1 1
output
Copy
0 1 1 2 0
Note
In the first test, all elements are equal, therefore no operations are needed.
In the second test, you can apply one operation with k=1k=1 and l=1l=1, set a1:=a2a1:=a2, and the array becomes [1,1] with 1 operation.
In the third test, you can apply one operation with k=1k=1 and l=4l=4, set a4:=a5a4:=a5, and the array becomes [4,4,4,4,4].
In the fourth test, you can apply one operation with k=1k=1 and l=3l=3, set a3:=a4a3:=a4, and the array becomes [4,2,3,3], then you can apply another operation with k=2 and l=1, set a1:=a3, a2:=a4, and the array becomes [3,3,3,3].
In the fifth test, there is only one element, therefore no operations are needed.

CodeForces-B相关推荐

  1. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  4. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  5. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  6. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  7. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  10. [题解]RGB Substring (hard version)-前缀和(codeforces 1196D2)

    题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 &quo ...

最新文章

  1. java visualvm远程监控_深入理解JVM虚拟机12:JVM性能管理神器VisualVM介绍与实战
  2. 从技术角度分析推荐系统案例
  3. C#中ref和out的原理
  4. java map初始化方式_java中Map和List初始化的两种方法
  5. UIView使用UIMotionEffect效果
  6. Halcon|读取3D相机点云数据
  7. 强制删除tfs未迁入项的两个方法。
  8. 英语初级学习系列-00-Name-介绍自己
  9. linux目录架构及常用的基本命令
  10. 微信上传图文素材接口报41005错误解决方法
  11. 从CSDN用户密码泄露谈一些非技术安全对策
  12. Ibatis -- 一次执行多条SQL
  13. Percona Data Recovery Tool 单表恢复
  14. 虹科和ELPRO推出符合GxP标准的自助式温度分布验证套装
  15. MATLAB函数step()对单位负反馈系统求阶跃响应
  16. 对话MVP丨腾讯崔冉的十年“技术马拉松”
  17. 【Linux】【操作】Linux操作集锦系列之三——进程管理系列之(一) 进程信息查看
  18. SQLServer从mdf和ldb还原数据库
  19. 数字文化下的未来柔性团队
  20. c语言中循环体表达式,C语言的循环语句

热门文章

  1. 昆仑通泰历史数据导出到u盘_MCGS配方组导出到U盘案例-专业自动化论坛-中国工控网论坛...
  2. webview ERR_UNKNOWN_URL_SCHEME
  3. 加勒比海盗——最优装载问题
  4. 将VS2019设置成英文版
  5. Flask开发微电影网站(一)
  6. python案例演示_Python中日期时间案例演示
  7. linux webdav服务,Ubuntu 配置WebDav服务器
  8. go第三方日志库uber-go/zap、lumberjack
  9. 微型计算机的性能主要取决于什么,微型计算机的性能主要取决于什么?
  10. 浮点运算单元(FPU)是什么?