DMOPC '22 Contest 1 P6 - Linear Swap

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

You are given an array A of N integers. There is a list of M operations that you must apply to the array in some order. The i-th operation has 3 parameters ai, bi, and si, and it can be applied by calling the following function:

Copy
bool apply(int a, int b, int s) {
    int C = a;
    for (int i = s; i <= N; i++) {
        if (C > A[i]) swap(C,A[i]);
    }
    return C <= b;
}

The operation is successfully applied if and only if the function returns true. Your task is to determine whether there is some ordering of the operations such that all of the operations can be applied successfully. To ensure the integrity of your solution, there may be up to T test cases.

Constraints

1T5×105

1N,M5×105

1Ai,ai,bi109

1siN

The sum of N over all test cases does not exceed 5×105.

The sum of M over all test cases does not exceed 5×105.

Subtask 1 [10%]

The sum of N over all test cases does not exceed 15.

The sum of M over all test cases does not exceed 15.

Subtask 2 [20%]

The sum of N over all test cases does not exceed 5×103.

The sum of M over all test cases does not exceed 5×103.

Subtask 3 [70%]

No additional constraints.

Input Specification

The first line contains an integer T, the number of test cases. The remaining lines describe the test cases.

The first line of each test case contains 2 integers N and M.

The second line of each test case contains N integers A1,A2,,AN.

The remaining M lines of each test case each contain 3 integers ai, bi, and si, describing the operations of the test case.

Output Specification

For each test case, output one line containing YES if there is an ordering of the operations such that all of the operations can be applied successfully, or NO otherwise.

Sample Input

Copy
1
5 3
3 1 4 1 5
2 3 5
6 1 1
3 2 3

Sample Output

Copy
YES

Explanation for Sample

One possible solution is as follows:

  1. Apply the third operation. This transforms A into [3,1,4,3,5]. Since C=1 at the end of the process and 12, this operation was applied successfully.
  2. Apply the first operation. This transforms A into [3,1,4,3,5]. Since C=2 at the end of the process and 23, this operation was applied successfully.
  3. Apply the second operation. This transforms A into [6,3,4,3,5]. Since C=1 at the end of the process and 11, this operation was applied successfully.

Comments

There are no comments at the moment.