TopCoder

User's AC Ratio

100.0% (2/2)

Submission's AC Ratio

22.2% (2/9)

Tags

Description

給定兩個 非嚴格遞增 的整數陣列 $L$ 與 $R$,請將它們合併為一個 非嚴格遞增 的新陣列 $\text{arr}$。

你需要實作一個函式 merge,將合併後的結果放入陣列 $\text{arr}$ 中。

  • 請注意,你的 merge 函式應在 線性時間 $O(n)$ 內完成(其中 $n = n_1 + n_2$)。
    使用 std::sort 等一般排序函式將會發生 TLE

使用範例程式碼

評測時,你所實作的 merge 函式會被放入以下程式碼中進行測試:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void merge(vector<int> &arr, vector<int> &L, vector<int> &R){
    // TODO
}

int main(){

    // input
    int n1, n2;
    int x1, a1, b1, x2, a2, b2;
    const int MOD = 1e9;

    cin >> n1 >> n2;
    cin >> x1 >> a1 >> b1 >> x2 >> a2 >> b2;
    vector<int> L(n1), R(n2);

    L[0] = x1;
    for (int i = 1; i < n1; i++) {
        L[i] = (1LL * L[i-1] * a1 + b1) % MOD + 1;
    }
    sort(L.begin(), L.end());

    R[0] = x2;
    for (int i = 1; i < n2; i++) {
        R[i] = (1LL * R[i-1] * a2 + b2) % MOD + 1;
    }
    sort(R.begin(), R.end());

    // process
    vector<int> arr(n1 + n2);
    merge(arr, L, R);

    // output
    int output = 0;
    for (int i = 0; i < n1 + n2; i++) {
        output ^= (i + arr[i]);
    }
    cout << output << "\n";

    return 0;
}

上傳說明

請上傳你實作的 merge 函式,並包含需要使用的標頭檔與命名空間,例如:

#include <...>
using namespace ...;

void merge(vector<int> &arr, vector<int> &L, vector<int> &R){
    // TODO
}

Input Format

第一行輸入兩個正整數 $n_1, n_2$,分別代表 $L$ 與 $R$ 的長度。
- 第二行輸入六個正整數 $x_1, a_1, b_1, x_2, a_2, b_2$,作為生成陣列 $L$ 與 $R$ 的參數。

Constraints
- $1 \leq n_1, n_2 \leq 5 \times 10 ^ 6$
- $1 \leq x_1, a_1, b_1, x_2, a_2, b_2 \leq 5 \times 10 ^ 6$
- 傳入的 $L, R$ 均為非嚴格遞增的陣列(已排序)。

Output Format

輸出一個正整數,代表下列運算結果:

$$ \bigoplus_{i=0} ^ {n_1 + n_2 - 1} \left( i + arr[i] \right) $$

其中 $\bigoplus$ 表示 bitwise XOR 運算。

Sample Input 1

5 6
1 2 3 2 3 4

Sample Output 1

1287

Hints

範例測資中,輸入所生成的 $L$ 與 $R$ 分別如下:

  • $L$: 1 6 16 36 76
  • $R$: 2 11 38 119 362 1091

合併後的 $\text{arr}$ 應為:
1 2 6 11 16 36 38 76 119 362 1091

Reminder

  • 你只需要確保合併後的陣列 $\text{arr}$ 為 非嚴格遞增(non-decreasing) 即可。
  • 其他後續的 XOR 運算程式碼已在題目中準備妥當,不需要額外處理。
  • 建議在測試過程中,將 $L$、$R$、$\text{arr}$ 印出來確認合併邏輯是否正確。

Problem Source

Subtasks

No. Testdata Range Score
1 0~9 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 131072 131072 1
1 1000 131072 131072 1
2 1000 131072 131072 1
3 1000 131072 131072 1
4 1000 131072 131072 1
5 1000 131072 131072 1
6 1000 131072 131072 1
7 1000 131072 131072 1
8 1000 131072 131072 1
9 1000 131072 131072 1