Alice and Bob find out a new, cool king game to play, and they want to play the game with you. You will enjoy the game, right?
Alice and Bob will give you two integer sequences $a_1, a_2, \dots, a_N$, $w_1, w_2, \dots, w_N$ with length $N$.
Alice and Bob allow you to do the following operations for many(possibly zero) times:
Now, they will give you $Q$ indepenedent queries. In the $i$-th query, they give you four integers $L_i, R_i, x_i, y_i$. They want you to make the integers $a_{L_i}, a_{L_i + 1}, \dots, a_{R_i}$ has $z$ distinct integers, such that $z \in [x_i, y_i]$. Also, since they are poor, they want you to spend as little as possible.
Please write a program to help them calculate the answers (minimum dollar that they have to spend).
小 A 和小 B 最近發現一個酷酷的國王遊戲,他們想和你一起玩。
他們會給你兩個整數序列 $a_1, a_2, \dots, a_N$, $w_1, w_2, \dots, w_N$ 長度皆為 $N$
你可以做以下操作任意多次(可以不做)
現在,他們將對你詢問 $Q$ 次 (不同的詢問之間互相獨立 不影響)。 第 $i$ 次詢問,會有四個整數 $L_i, R_i, x_i, y_i$。目標是要讓 $a_{L_i}, a_{L_i+1}, \dots, a_{R_i}$ 中恰有 $z$ 個不同的整數,其中 $z \in [x_i, y_i]$。同時因為他們很窮,所以希望你花越少代價越好
請寫一個程式幫幫他們計算答案 (最少需要花多少錢)
The first line of the input contains two integers $N, Q$, indicating the length of the sequences, and the number of queries.
The second line contains $N$ integers $a_1, a_2, \dots, a_N$.
The third line contains $N$ integers $w_1, w_2, \dots, w_N$.
In the following $Q$ lines, the $i$-th line indicates the $i$-th query. The $i$-th line contains four integers $L_i, R_i, x_i, y_i$.
The meanings of the parameters above have been explained in the problem statement.
輸入第一行有兩個整數 $N, Q$, 分別代表序列的長度和詢問的數量
第二行有 $N$ 個整數 $a_1, a_2, \dots, a_N$
第三行有 $N$ 個整數 $w_1, w_2, \dots, w_N$
接下來 $Q$ 行之中的第 $i$ 行包含第 $i$ 筆詢問,每行皆有四個整數 $L_i, R_i, x_i, y_i$
各個參數的意義皆在題目中有解釋
For each query, print the answer to the query in one line.
對於每筆詢問,請各自輸出一行整數代表答案
2021 台清交程式競賽 pK
No. | Testdata Range | Score |
---|---|---|
1 | 0~37 | 100 |