Robin Hood and the Major Oak

B. Robin Hood and the Major Oak

Problem

In Sherwood, the trees are our shelter, and we are all children of the forest.

The Major Oak in Sherwood is known for its majestic foliage, which provided shelter to Robin Hood and his band of merry men and women.

The Major Oak grows i i i^i ii new leaves in the i i i-th year. It starts with 1 1 1 leaf in year 1 1 1.

Leaves last for k k k years on the tree. In other words, leaves grown in year i i i last between years i i i and i + k − 1 i+k-1 i+k1 inclusive.

Robin considers even numbers lucky. Help Robin determine whether the Major Oak will have an even number of leaves in year n n n.

Input

The first line of the input contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

Each test case consists of two integers n n n, k k k ( 1 ≤ n ≤ 1 0 9 1 \le n \le 10^9 1n109, 1 ≤ k ≤ n 1 \le k \le n 1kn) — the requested year and the number of years during which the leaves remain.

Output

For each test case, output one line, “YES” if in year n n n the Major Oak will have an even number of leaves and “NO” otherwise.

You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.

Example

Input
5
1 1
2 1
2 2
3 2
4 4
Output
NO
YES
NO
NO
YES

Note

In the first test case, there is only 1 1 1 leaf.

In the second test case, k = 1 k=1 k=1, so in the 2 2 2-nd year there will be 2 2 = 4 2^2=4 22=4 leaves.

In the third test case, k = 2 k=2 k=2, so in the 2 2 2-nd year there will be 1 + 2 2 = 5 1+2^2=5 1+22=5 leaves.

In the fourth test case, k = 2 k=2 k=2, so in the 3 3 3-rd year there will be 2 2 + 3 3 = 4 + 27 = 31 2^2 + 3^3 = 4 + 27 = 31 22+33=4+27=31 leaves.

Code

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//队列
// #include <queue>//堆/优先队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll t;
    cin>>t;

    while(t--)
    {
        ll n,k;
        cin>>n>>k;

        ll ans=n*(n+1)/2-(n-k)*(n-k+1)/2;
        if(ans&1) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    
    return 0;
}
### 回答1: robin_hood::unordered_set是一种基于开放寻址的哈希表实现,它是C++ STL中的一个无序集合容器。与标准的unordered_set相比,robin_hood::unordered_set有着更高的性能。 robin_hood::unordered_set的实现方式采用了"robin hood"哈希算法,这种算法通过再哈希的方式处理冲突,将冲突的元素移到更远的位置,从而保持高效的查找性能。这种算法使得插入和删除操作具有O(1)的时间复杂度,而查找操作虽然在最坏情况下也是O(n),但实际上在大多数情况下是O(1)的。 此外,robin_hood::unordered_set在内存使用上也比标准的unordered_set更为高效。它采用了连续的内存布局,并使用了布隆过滤器来减少哈希冲突的数量,从而减少了内存的占用。 使用robin_hood::unordered_set时,可以通过插入、删除和查找等操作来管理集合中的元素。插入操作可以将元素添加到集合中,删除操作可以从集合中移除指定的元素,而查找操作可以判断集合中是否存在某个元素。 总的来说,robin_hood::unordered_set是一种高效的无序集合容器,适用于需要频繁进行插入、删除和查找操作的场景。它通过"robin hood"哈希算法和优化的内存使用方式,在性能和内存占用方面均有优势。 ### 回答2: Robin Hood是一个著名的英雄人物,他以偷取富人财物来帮助穷人而闻名。而unordered_set是C++ STL库中的一个数据结构,它是一个无序的集合,允许快速地插入、查找和删除元素。 尽管二者似乎没有直接联系,但是我们可以通过一些类比来理解它们之间的关系。就像Robin Hood通过偷取富人的财物来帮助穷人一样,unordered_set可以用来解决一些问题,比如查找和删除元素,这些问题在其他数据结构中可能需要更多的时间和资源。 就像Robin Hood能够迅速地从富人身上夺取财物,unordered_set在最佳情况下能够以O(1)的时间复杂度插入、查找和删除元素,这取决于哈希函数的性能。这使得它在一些需要高效率操作的场景中非常有用,比如去重、查找等。 然而,就像Robin Hood有时候可能会遇到困难一样,unordered_set也有一些限制。由于其无序的特点,它在有序访问元素方面相对较弱。此外,当元素数量较大时,哈希冲突的概率也会增加,导致性能下降。因此,在某些情况下,我们可能需要考虑使用其他更适合的数据结构。 总之,尽管Robin Hood和unordered_set在本质上是不同的,但通过类比,我们可以更好地理解unordered_set的特点和用途。无论是Robin Hood还是unordered_set,它们都有自己独特的功能和限制,我们需要根据具体的问题和需求来选择使用它们。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值