#P11949. [KTSC 2025] 木筏制作 / raft

    ID: 13349 远端评测题 10000ms 1024MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2025交互题KOI(韩国)

[KTSC 2025] 木筏制作 / raft

背景

版权信息:译自 2025年度 国际情报 올림피아드 (Olympiad) 代表学生 选拔考试 R2T4。[CC BY-NC-SA 4.0]

滥用本题评测将被封号。

题目描述

给定长度为 nn 的正整数数列 a0∼an−1a_0 \sim a_{n-1} 和长度为 mm 的正整数数列 b0∼bm−1b_0\sim b_{m-1}。

对于 a,ba,b,定义好的序列为满足以下条件的序列 h0∼hk−1h_0\sim h_{k-1}:

  • 能够把 hh 划分成两个子序列 p,qp,q,使得 p=a∧q=b\textcolor{red}{\boldsymbol{p=a\land q=b}}。(子序列可以不连续。)

定义好的序列 h0∼hk−1h_0\sim h_{k-1} 的权值为

$$\max_{0\le l\le r\lt k} \left((r-l+1)\cdot \min_{i\in [l,r]} \{h_i\} \right)$$

定义 f(a′,b′)f(a',b') 为:当 a=a′,b=b′a=a',b=b' 时,好的序列的权值的最大值。

有 qq 次询问。第 ii 次询问给定 Li,RiL_i,R_i,求出 f(a,[bLi,bLi+1,…,bRi])f(a,[b_{L_i},b_{L_i+1},\ldots,b_{R_i}])。

实现细节

你不需要,也不应该实现 main 函数。

你应当实现以下的函数:

vector<long long> max_stability(vector<int> a, vector<int> b,
vector<int> L, vector<int> R)
  • a:长度为 nn 的正整数数列。
  • b:长度为 mm 的正整数数列。
  • L,RL,R:长度为 qq 的非负整数序列,Li,RiL_i,R_i 描述一次询问。
  • 返回一个长度为 qq 的非负整数序列 cc,cic_i 表示询问 (Li,Ri)(L_i,R_i) 的答案。

输入格式

Sample Grader 输入格式如下:

第一行,三个正整数 n,m,qn,m,q。

第二行,nn 个正整数 a0∼an−1a_0\sim a_{n-1}。

第三行,mm 个正整数 b0∼bm−1b_0\sim b_{m-1}。

接下来 qq 行,第 ii 行两个非负整数 Li−1,Ri−1L_{i-1},R_{i-1}。

输出格式

输出一行 qq 个非负整数 c0,c1,…,cq−1c_0,c_1,\ldots,c_{q-1}。

5 4 2
3 3 1 6 1
3 5 7 6
0 1
0 3
12 20
5 8 8
9 9 9 9 9
1 2 3 4 5 6 7 8
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
45 45 45 45 45 45 45 49
3 2 1
1000000000 1000000000 1000000000
1000000000 1000000000
0 1
5000000000

提示

样例交互

样例交互 11

$n = 5, m = 4, q = 2, a = [3, 3, 1, 6, 1], b = [3, 5, 7, 6], L = [0, 0], R = [1, 3]$。

交互库调用

max_stability([3, 3, 1, 6, 1], [3, 5, 7, 6], [0, 0], [1, 3]);

考虑第一个询问 L0=0,R0=1L_0=0,R_0=1。

令 $h = [\textbf{\textcolor{red}{3}, \textcolor{red}{3}, 3, 5}, \textcolor{red}{1}, \textcolor{red}{6}, \textcolor{red}{1}]$,可以验证答案为 min⁡{3,3,3,5}×4=12\min \{3,3,3,5\}\times 4=12。

考虑第二个询问 L1=0,R1=3L_1=0,R_1=3。

令 $h = [\textcolor{red}3, \textcolor{red}3, \textcolor{red}1, 3, \textbf{5, 7, \textcolor{red}6, 6}, \textcolor{red}1]$,可以验证答案为 min⁡{5,7,6,6}×4=20\min \{5,7,6,6\}\times 4=20。

所以返回 [12,20][12,20]。

样例交互 22

交互库调用

max_stability([9, 9, 9, 9, 9], [1, 2, 3, 4, 5, 6, 7, 8], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]);

返回 [45,45,45,45,45,45,45,49][45, 45, 45, 45, 45, 45, 45, 49]。

样例交互 33

交互库调用

max_stability([1000000000, 1000000000, 1000000000], [1000000000, 1000000000], [0], [1])

返回 [5 000 000 000][5\, 000\, 000\, 000]。

数据范围

  • 1≤n,m≤1.5×1051\le n,m\le 1.5\times 10^5;
  • 1≤q≤5×1051\le q\le 5\times 10^5;
  • 1≤ai,bi≤1091\le a_i,b_i\le 10^9;
  • 0≤li≤ri<m0\le l_i\le r_i\lt m。

子任务

  • Subtask 1 (10 pts)\text{Subtask 1 (10 pts)}:n,m,q≤3×103n,m,q\le 3\times 10^3。
  • Subtask 2 (8 pts)\text{Subtask 2 (8 pts)}:q≤300q\le 300。
  • Subtask 3 (20 pts)\text{Subtask 3 (20 pts)}:
    • ∀0≤i<q\forall 0\le i\lt q,都有:
      • 要么 Li=0L_i=0,要么 $\displaystyle b_{L_i-1}\lt \min \{b_{L_i},b_{L_{i}+1},\ldots,b_{R_i}\}$;
      • 要么 Ri=m−1R_i=m-1,要么 $\displaystyle b_{R_i+1}\lt \min \{b_{L_i},b_{L_{i}+1},\ldots,b_{R_i}\}$。
  • Subtask 4 (6 pts)\text{Subtask 4 (6 pts)}:ai≤50,bi≤50a_i\le 50,b_i\le 50。
  • Subtask 5 (14 pts)\text{Subtask 5 (14 pts)}:a0=a1=…=an−1a_0=a{1}=\ldots=a_{n-1}。
  • Subtask 6 (11 pts)\text{Subtask 6 (11 pts)}:b0≥b1≥…≥bm−1b_0\ge b_1\ge \ldots \ge b_{m-1}。
  • Subtask 7 (13 pts)\text{Subtask 7 (13 pts)}:∀0≤i≤q\forall 0\le i\le q,Li=0L_i=0。
  • Subtask 8 (7 pts)\text{Subtask 8 (7 pts)}:R0−L0=R1−L1=…=Rq−1−Lq−1R_0-L_0=R_1-L_1=\ldots=R_{q-1}-L_{q-1}。
  • Subtask 9 (11 pts)\text{Subtask 9 (11 pts)}:无额外约束。