A1385 | [COCI-2020-2021-contest3]#4 Specijacija
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
You are given a positive integer n and a sequence a1, a2, . . . , an of positive integers, such that i(i−1) 2 < ai ≤ i(i+1) The sequence parameterizes a tree with (n+1)(n+2)2 vertices, consisting of n + 1 levels with 1, 2, . . . , n + 1 vertices, in the following way: 1 2 4 7 5 8 3 6 9 10 The tree parameterized by a = (1, 2, 6). The i-th level contains vertices i(i−1) 2 + 1, . . . , i(i+1) 2 . The vertex ai has two children, and the rest of the vertices on the level have one child each.
We want to answer q queries of the form “what is the largest common ancestor of x and y”, i.e. the vertex with the largest label which is an ancestor of both x and y
We want to answer q queries of the form “what is the largest common ancestor of x and y”, i.e. the vertex with the largest label which is an ancestor of both x and y
输入格式
The first line contains integers n, q and t (1 ≤ n, q ≤ 200 000, t ∈ {0, 1}), the number of parameters, the number of queries, and a value which will be used to determine the labels of vertices in the queries.
The second line contains a sequence of n integers ai (
i(i−1)2 < ai ≤i(i+1) 2 ) which parameterize the tree.
The i-th of the following q lines contains two integers xei and yei (1 ≤ xei , yei ≤ (n+1)(n+2) 2 ) which will be used to determine the labels of vertices in the queries.
Let zi be the answer to the i-th query, and let z0 = 0. The labels in the i-th query xi and yi are: xi = (xei − 1 + t · zi−1) mod (n+1)(n+2) 2 + 1,
yi = (yei − 1 + t · zi−1) mod (n+1)(n+2) 2 + 1,
where mod is the remainder of integer divison.
Remark: Note that if t = 0, it holds xi = xei and yi = yei , so all queries are known from input. If t = 1, the queries are not known in advance, but are determined using answers to previous queries.
The second line contains a sequence of n integers ai (
i(i−1)2 < ai ≤i(i+1) 2 ) which parameterize the tree.
The i-th of the following q lines contains two integers xei and yei (1 ≤ xei , yei ≤ (n+1)(n+2) 2 ) which will be used to determine the labels of vertices in the queries.
Let zi be the answer to the i-th query, and let z0 = 0. The labels in the i-th query xi and yi are: xi = (xei − 1 + t · zi−1) mod (n+1)(n+2) 2 + 1,
yi = (yei − 1 + t · zi−1) mod (n+1)(n+2) 2 + 1,
where mod is the remainder of integer divison.
Remark: Note that if t = 0, it holds xi = xei and yi = yei , so all queries are known from input. If t = 1, the queries are not known in advance, but are determined using answers to previous queries.
输出格式
Output q lines. In the i-th line, output the largest common ancestor of xi and yi.
输入输出样例
输入 #1
3 5 0 1 2 6 7 10 8 5 6 2 9 10 2 3
输出 #1
1 5 1 6 1
Clarification of the examples:
The tree from both examples is shown on the figure in the statement.
Labels of verticies in queries in the second example are:
x1 = 7, y1 = 10,
x2 = 9, y2 = 6,
x3 = 2, y3 = 8,
x4 = 1, y4 = 2,
x5 = 3, y5 = 4.
The tree from both examples is shown on the figure in the statement.
Labels of verticies in queries in the second example are:
x1 = 7, y1 = 10,
x2 = 9, y2 = 6,
x3 = 2, y3 = 8,
x4 = 1, y4 = 2,
x5 = 3, y5 = 4.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted