Skip to main content
Back to problems
Codeforces
Medium
Arrays
Greedy
Binary Search
Skibidus and Fanum Tax (hard version)

Determine whether each required value can be placed into an array by choosing suitable positions under the problem's rules.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

Skibidus and Fanum Tax

gfg
Problem Statement

Problem

You are given an array and a set of required values. For each required value, decide whether it can be assigned to a valid position according to the constraints of the problem.

The hard version keeps the same core idea as the easier version, but the input sizes are larger and the solution must avoid naive repeated scanning.

Your task is to process the array efficiently and answer the required queries exactly as specified by the rules of the problem.

Goal

For each test case, output the result of applying the placement/checking process to every required value in order.

Input Format

  • The first line contains an integer tt — the number of test cases.
  • For each test case:
    • The first line contains integers describing the array/query sizes.
    • The next lines contain the array and the required values.

The exact format follows the standard Codeforces statement for this problem.

Output Format

For each test case, print the answer required by the checking/placement process, using the format specified by the original problem.

Constraints

  • Multiple test cases.
  • Large input size in the hard version.
  • An O(nlogn)O(n \log n) or similar efficient approach is expected.

Because the exact official constraints are not provided here, treat the problem as a medium-difficulty implementation and search task.

Examples
Sample cases returned by the problem API.

Example 1

Input

1
5 3
1 3 5 7 9
2 6 10

Output

YES
NO
NO

Explanation

Illustrative example only: each required value is checked against the available array positions, and the answer is printed for each query in order.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.