#P17210. 【模板】半在线决策单调性
【模板】半在线决策单调性
Problem Description
You are given a sequence of length and a sequence .
Define the weight of an interval as
$$b_r+\sum\limits_{i=l}^r\sum\limits_{j=i+1}^r[a_i=a_j]$$where if and only if is true, otherwise .
For each , you need to partition into several segments so that the sum of the weights of all segments is minimized. Formally, you need to find some indices such that:
- .
- .
Based on this, minimize .
Input Format
The first line contains an integer , representing the length of the sequences.
The second line contains integers describing the sequence of length .
The third line contains integers describing the sequence of length .
Output Format
Output one line with integers, where the -th integer is the answer for the prefix .
6
1 2 1 1 2 1
2 2 2 2 2 2
2 2 3 5 5 6
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, $n \leq 5\times 10^5, 1 \leq a_i \leq n, 0 \leq b_i \leq 10^9$.
Translated by ChatGPT 5