#P15585. [KTSC 2026] 绝妙区间 2 / Wonderful Interval 2

    ID: 17434 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>交互题2026KTSC(韩国)

[KTSC 2026] 绝妙区间 2 / Wonderful Interval 2

Problem Description

Youngwoo has two arrays A,BA, B of length NN. For any 0≤i≤N−10 \le i \le N - 1, we have A[i]≤B[i]A[i] \le B[i].

An interval [l,r][l, r] is a wonderful interval if and only if it satisfies all of the following conditions:

  • l,rl, r are integers.
  • 0≤l≤r≤N−10 \le l \le r \le N - 1.
  • By repeatedly performing the following operation, [A[l],⋯ ,A[r]][A[l], \cdots, A[r]] can be transformed into [B[l],⋯ ,B[r]][B[l], \cdots, B[r]]:
    • Let the current array be X=[X[0],X[1],⋯ ,X[r−l]]X = [X[0], X[1], \cdots, X[r - l]].
    • Choose two distinct integers i,ji, j (0≤i,j≤r−l0 \le i, j \le r - l) such that X[i]=X[j]X[i] = X[j], and then set X[i]←X[i]+1X[i] \gets X[i] + 1.

Youngwoo is curious about which intervals are wonderful intervals. Specifically, Youngwoo is given QQ queries, numbered 0∼Q−10 \sim Q - 1, represented by two arrays L,RL, R of length QQ.

Query jj (0≤j≤Q−10 \le j \le Q - 1) asks whether the interval [L[j],R[j]][L[j], R[j]] is a wonderful interval.

Write a program to answer Youngwoo’s queries.

Implementation Details

This is a functional interactive problem. You do not need to, and should not, implement the main function.

You should implement the following function:

vector<int> array_operation(vector<int> A, vector<int> B, vector<int> L, vector<int> R)
  • A,BA, B: integer arrays of size NN.
  • L,RL, R: integer arrays of size QQ.
  • Return an integer array SS of size QQ. If [L[j],R[j]][L[j], R[j]] is a wonderful interval, then S[j]S[j] should be 11, otherwise 00 (0≤j≤Q−10 \le j \le Q - 1).
  • This function is called exactly once.

Your source code should not call any input/output functions.

Input Format

The input format of the sample grader is as follows:

  • Line 11: NN QQ
  • For all 0≤i≤N−10 \le i \le N - 1:
    • Line 2+i2 + i: A[i]A[i] B[i]B[i]
  • For all 0≤i≤Q−10 \le i \le Q - 1:
    • Line 2+N+i2 + N + i: L[i]L[i] R[i]R[i]

Output Format

The sample grader prints the answer in the following format:

  • Line 11: the return value of array_operation
4 3
2 2
1 1
1 3
2 3
0 1
0 3
1 3

1 1 0

5 5
1 2
2 3
1 1
2 4
1 2
0 2
0 4
1 3
1 4
2 3

1 1 0 1 0

Hint

Constraints

  • 1≤N,Q≤250 0001 \le N, Q \le 250\, 000.
  • 1≤A[i]≤B[i]≤1091 \le A[i] \le B[i] \le 10^9 (0≤i≤N−10 \le i \le N - 1).
  • 0≤L[j]≤R[j]≤N−10 \le L[j] \le R[j] \le N - 1 (0≤j≤Q−10 \le j \le Q - 1).

Subtasks

ID Score Constraints
11 9 9 N,Q≤100N, Q \le 100, B[i]≤100B[i] \le 100
22 7 7 N,Q≤2 000N, Q \le 2\, 000, A[i]=1A[i] = 1
33 1616 A[i]=1A[i] = 1
44 1010 N,Q≤2 000N, Q \le 2\, 000
55 4 4 B[i]≤2B[i] \le 2
66 1313 B[i]≤100B[i] \le 100
77 3131 B[i]≤250 000B[i] \le 250\, 000
88 1010 No additional constraints

Samples

Sample 1

Consider the following call:
array_operation([2, 1, 1, 2], [2, 1, 3, 3], [0, 0, 1], [1, 3, 3])

  • [00, 11] is a wonderful interval. This is because the two arrays A[0]A[0], A[1]A[1] and B[0]B[0], B[1]B[1] are equal.
  • [00, 33] is a wonderful interval. This is because by performing the following operations, [22, 11, 11, 22] can be changed into [22, 11, 33, 33].
    • Choose i=3i = 3, j=0j = 0 and perform the operation. After the operation, the array becomes [22, 11, 11, 33].
    • Choose i=2i = 2, j=1j = 1 and perform the operation. After the operation, the array becomes [22, 11, 22, 33].
    • Choose i=2i = 2, j=0j = 0 and perform the operation. After the operation, the array becomes [22, 11, 33, 33].
  • [11, 33] is not a wonderful interval. It can be proven that no matter how you perform the operations, it is impossible to change [11, 11, 22] into [11, 33, 33].

Therefore, the function should return [11, 11, 00].

Sample 2

Consider the following call:
array_operation([1, 2, 1, 2, 1], [2, 3, 1, 4, 2], [0, 0, 1, 1, 2], [2, 4, 3, 4, 3])

Among all intervals, the wonderful intervals are [00, 22], [00, 33], [00, 44], [11, 44], [22, 22]. Therefore, the function should return [11, 11, 00, 11, 00].

Translated by ChatGPT 5