QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 256 MB Puntuación total: 100 Hackeable ✓

#17741. 101 Things To Do Before You Graduate

Estadísticas

It's the finals week of Busy Beaver's senior year, and he just remembered about the list of must-do activities to complete before graduating he received during freshman orientation.

You are given an array of $N$ numbers $a_1, \ldots, a_N$, where $a_i$ represents the joy of completing the $i^\text{th}$ activity.

Due to his limited time at MIT, he has decided to only complete a contiguous subsegment of these activities. Additionally, to make the most out of it, the subsegment must contain at least two activities.

While procrastinating when preparing for his finals, he came up with a sophisticated way of scoring a subsegment. The score of the subsegment from index $l$ to $r$ is the minimum XOR of two distinct activities. Formally, the subsegment from index $l$ to $r$ has a score of $\min\limits_{l \leq i < j \leq r} a_i \oplus a_j$.

Busy Beaver's favorite number is $K$, so he would like to calculate the number of subsegments with score $K$. Can you help him?

Input

The first line contains two integers $N$, $K$ ($2 \le N \le 10^5$, $0 \le K < 2^{30}$).

The second line contains $N$ space-separated integers $a_1, \dots, a_N$ ($1 \le a_i < 2^{30}$).

Output

Output a single integer: the number of contiguous subsegments of size at least two with score $K$.

Scoring

  • ($15$ points) $N \leq 5000$.
  • ($10$ points) $K = 0$.
  • ($25$ points) Array $a$ is sorted in non-decreasing order ($a_{1} \leq \ldots \leq a_{N}$).
  • ($50$ points) No additional constraints.

Examples

Input 1

5 2
1 3 1 4 5

Output 1

3

Note

There are three subsegments that should be counted:

  • $l = 1, r = 2$.
  • $l = 2, r = 3$.
  • $l = 2, r = 4$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.