Logo
(追記) (追記ここまで)

34107번 - Collecting Stamps 4 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB259838.095%

문제

JOI-kun lives in the country of IOI, which is famous for its large lake. Today, a stamp rally competition will be held around the lake.

Around the lake, there are 2ドルN$ evenly spaced locations, numbered from 1ドル$ to 2ドルN$ in a clockwise manner. Additionally, there are 2ドルN$ one-way roads connecting adjacent locations. Road $i$ (1ドル ≤ i ≤ 2N - 1$) goes from location $i$ to location $i+1,ドル and road 2ドルN$ goes from location 2ドルN$ to location 1ドル$. At the midpoint of each road, there is a stamp station.

There are $N$ colors of stamps numbered from 1ドル$ to $N$. The color of the stamp that can be obtained at the stamp station on road $i$ (1ドル ≤ i ≤ 2N$) is given by $A_i$. For each color $j$ (1ドル ≤ j ≤ N$), there are exactly 2ドル$ stamp stations where the stamp of that color can be obtained.

JOI-kun, equipped with many stamp cards, participates in the stamp rally competition. Each stamp card has two spaces, left and right, where stamps can be pressed. At most one stamp can be placed in each space. Initially, all stamp cards are blank.

The process of the stamp rally competition for JOI-kun is as follows:

  1. First, he selects one of the 2ドルN$ locations as the starting point and moves there. If he selects location $i$ (1ドル ≤ i ≤ 2N$), he must pay a participation cost of $C_i$.
  2. Next, he can instruct the event organizers to swap adjacent stamp stations. Specifically, he can swap the stamp stations on roads 2ドルN$ and 1ドル,ドル or swap the stations on roads $i - 1$ and $i$ for any $i$ (2ドル ≤ i ≤ 2N$). Each swap costs $X,ドル and JOI-kun can issue as many swap commands as he wants, possibly none. Swaps are executed immediately upon command. However, to prevent cheating, it is not allowed to exchange stamp stations that cross the starting location that JOI-kun has chosen. That is, if he starts at location 1ドル,ドル swapping the stations on roads 2ドルN$ and 1ドル$ is forbidden. If he starts at location $i$ (2ドル ≤ i ≤ 2N$), swapping the stations on roads $i - 1$ and $i$ is forbidden.
  3. After that, JOI-kun starts from his chosen location and moves clockwise, visiting each of the 2ドルN$ stamp stations in sequence. When visiting a stamp station, he can press the stamp onto his stamp cards as many times as he likes. He can also stamp both the left and right spaces of a single card at the same station. However, for each stamp card, he must always stamp the left space before the right space; that is, he cannot stamp the right space if the left space of that stamp card is still empty.

JOI-kun wants to collect many distinct types of stamp cards that are stamped on both spaces. Let stamped card $(a, b)$ be a stamp card with color $a$ stamped on the left and color $b$ stamped on the right. Two stamped cards $(a_1, b_1)$ and $(a_2, b_2)$ are considered the same type if and only if $a_1 = a_2$ and $b_1 = b_2$. Since there are $N$ colors of stamps, there are a total of $N^2$ possible types of stamped cards.

You need to answer $Q$ queries to help JOI-kun. The $q$-th query (1ドル ≤ q ≤ Q$) asks the following:

  • What is the minimum total cost required for JOI-kun to collect at least $K_q$ types of stamped cards by the end of the rally? It is provable that under the given constraints, JOI-kun can always collect at least $K_q$ types of stamped cards by spending a sufficiently large cost.

Given the information about stamp colors, participation costs, swap costs, and queries, write a program to answer JOI-kun’s $Q$ queries.

입력

Read the following data from the standard input.

$N$ $X$

$A_1$ $A_2$ $\cdots$ $A_{2N}$

$C_1$ $C_2$ $\cdots$ $C_{2N}$

$Q$

$K_1$

$K_2$

$\vdots$

$K_Q$

출력

Write $Q$ lines to the standard output, where the $q$-th line (1ドル ≤ q ≤ Q$) contains the minimum total cost required to collect at least $K_q$ types of stamped cards.

제한

  • 2ドル ≤ N ≤ 500,円 000$.
  • 1ドル ≤ X ≤ 500,円 000$.
  • $(A_1, A_2, \dots , A_{2N})$ is a permutation of $(1, 1, 2, 2, \dots , N, N)$.
  • 1ドル ≤ C_i ≤ 10^{18}$ (1ドル ≤ i ≤ 2N$).
  • 1ドル ≤ Q ≤ 500,円 000$.
  • 1ドル ≤ K_q ≤ N^2$ (1ドル ≤ q ≤ Q$).
  • Given values are all integers.

서브태스크

번호배점제한
15

$N ≤ 4$.

220

$N ≤ 5000,ドル $Q = 1,ドル $K_1 = N^2$.

320

$N ≤ 5000,ドル $Q = 1$.

419

$N ≤ 5000$.

521

$Q = 1$.

615

No additional constraints.

예제 입력 1

3 2
1 2 2 3 1 3
6 1 4 5 4 7
2
8
9

예제 출력 1

3
4

Consider the case where JOI-kun selects location 2ドル$ as the starting point and instructs the exchange of the stamp stations installed on road 3ドル$ and road 4ドル$.

In this case,

  • The total cost paid by JOI-kun is $C_2 + X \times 1 = 3$.
  • JOI-kun visits the stamp stations in the order of roads 2,ドル 3, 4, 5, 6, 1,ドル and the stamp colors available at each station in sequence are 2,ドル 3, 2, 1, 3, 1$.
  • The number of types of stamp cards stamped on both spaces that JOI-kun can collect is 8ドル$.
    • For example, to obtain a stamped card with a stamp of color 3 on the left and a stamp of color 1ドル$ on the right, JOI-kun can stamp the left side at road 3ドル$ and the right side at road 1ドル$.
    • However, note that it is impossible to obtain a stamped card with a stamp of color 1ドル$ on the left and color 2ドル$ on the right.

Since it is impossible to obtain 8ドル$ or more types of stamped cards with a cost of 2ドル$ or less, the first line of the output should be 3ドル$.

Additionally, if JOI-kun selects location 3ドル$ as the starting point and does not instruct any stamp station exchange, he can obtain 9ドル$ types of stamped cards.

In this case, the total cost paid by JOI-kun is $C_3 + X \times 0 = 4$. Since it is impossible to obtain 9ドル$ or more types of stamped cards with a cost of 3ドル$ or less, the second line of the output should be 4ドル$.

This input example satisfies the constraints of subtasks 1, 4, 6.

예제 입력 2

8 1
1 2 6 1 6 3 8 4 5 5 3 4 7 2 7 8
4 5 3 6 2 9 1 4 6 3 8 5 2 9 4 7
1
64

예제 출력 2

7

Consider the case where JOI-kun chooses location 10ドル$ as the starting point and instructs the stamp station exchanges in the following order:

  • Exchange the stamp station installed on road 15ドル$ with the one on road 16ドル$.
  • Exchange the stamp station installed on road 2ドル$ with the one on road 3ドル$.
  • Exchange the stamp station installed on road 16ドル$ with the one on road 1ドル$.
  • Exchange the stamp station installed on road 1ドル$ with the one on road 2ドル$.

In this case, JOI-kun can obtain 64ドル$ types of stamped cards, and the total cost paid is $C_{10} + X \times 4 = 7$.

This input example satisfies the constraints of subtasks 2, 3, 4, 5, 6.

예제 입력 3

9 4
4 3 5 3 8 1 5 8 1 7 6 2 4 9 6 9 2 7
12 9 4 8 7 1 20 5 8 7 4 13 5 9 10 3 7 8
6
39
81
73
79
64
52

예제 출력 3

1
18
3
10
1
1

This input example satisfies the constraints of subtasks 4, 6.

힌트

출처

Camp > JOI Spring Training Camp > JOI 2024/2025 Spring Training Camp 2-2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /