CF1500B.Two chandeliers

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered both chandeliers that can change its color cyclically. For example: red – brown – yellow – red – brown – yellow and so on.

There are many chandeliers that differs in color set or order of colors. And the person responsible for the light made a critical mistake — they bought two different chandeliers.

Since chandeliers are different, some days they will have the same color, but some days — different. Of course, it looks poor and only annoys Vasya. As a result, at the kk-th time when chandeliers will light with different colors, Vasya will become very angry and, most probably, will fire the person who bought chandeliers.

Your task is to calculate the day, when it happens (counting from the day chandeliers were installed). You can think that Vasya works every day without weekends and days off.

瓦西里是一家大型建筑公司的首席执行官。和其他大老板一样,他拥有一间宽敞且陈设豪华的办公室,办公室内装有两盏水晶吊灯。为了保持工作动力,瓦西里要求办公室灯光的颜色每天都要发生变化。因此,他订购了两盏均可按固定周期变换颜色的吊灯。例如:红色 → 棕色 → 黄色 → 红色 → 棕色 → 黄色 → ……

市面上有许多吊灯,它们所支持的颜色集合或颜色变化顺序各不相同。而负责采购灯光设备的人员犯了一个严重错误——他们买了两盏不同的吊灯。

由于这两盏吊灯不同,某些天它们会发出相同颜色的光,而另一些天则会发出不同颜色的光。显然,这种不协调的灯光效果显得非常糟糕,只会让瓦西里感到烦躁。结果,在吊灯第 kk 次发出不同颜色的那一天,瓦西里将变得极为愤怒,并极有可能解雇当初采购吊灯的那个人。

你的任务是计算出这一事件发生的日期(从吊灯安装启用之日算起第几天)。你可以认为瓦西里全年无休,每天都上班。

输入格式

The first line contains three integers nn, mm and kk (1≤n,m≤500 0001 \le n, m \le 500\,000; 1≤k≤10121 \le k \le 10^{12}) — the number of colors in the first and the second chandeliers and how many times colors should differ to anger Vasya.

The second line contains nn different integers aia_i (1≤ai≤2⋅max⁡(n,m)1 \le a_i \le 2 \cdot \max(n, m)) that describe the first chandelier's sequence of colors.

The third line contains mm different integers bjb_j (1≤bi≤2⋅max⁡(n,m)1 \le b_i \le 2 \cdot \max(n, m)) that describe the second chandelier's sequence of colors.

At the ii-th day, the first chandelier has a color axa_x, where x=((i−1)mod  n)+1)x = ((i - 1) \mod n) + 1) and the second one has a color byb_y, where y=((i−1)mod  m)+1)y = ((i - 1) \mod m) + 1).

It's guaranteed that sequence aa differs from sequence bb, so there are will be days when colors of chandeliers differs.

第一行包含三个整数 nn、mm 和 kk(1≤n,m≤500 0001 \le n, m \le 500\,000;1≤k≤10121 \le k \le 10^{12}),分别表示第一盏和第二盏枝形吊灯的颜色种类数,以及使瓦西娅生气所需颜色不同的天数。

第二行包含 nn 个互不相同的整数 aia_i(1≤ai≤2⋅max⁡(n,m)1 \le a_i \le 2 \cdot \max(n, m)),描述第一盏枝形吊灯的颜色序列。

第三行包含 mm 个互不相同的整数 bjb_j(1≤bi≤2⋅max⁡(n,m)1 \le b_i \le 2 \cdot \max(n, m)),描述第二盏枝形吊灯的颜色序列。

在第 ii 天,第一盏枝形吊灯的颜色为 axa_x,其中 x=((i−1) mod n)+1x = ((i - 1) \bmod n) + 1;第二盏枝形吊灯的颜色为 byb_y,其中 y=((i−1) mod m)+1y = ((i - 1) \bmod m) + 1。

保证序列 aa 与序列 bb 不同,因此必然存在若干天,两盏枝形吊灯的颜色不同。

输出格式

Print the single integer — the index of day when Vasya will become angry.

输出一个整数——即瓦西娅将生气的那一天的序号。

输入输出样例

  • 输入#1

    4 2 4
    4 2 3 1
    2 1

    输出#1

    5
  • 输入#2

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

    输出#2

    47
  • 输入#3

    1 2 31
    1
    1 2

    输出#3

    62

说明/提示

In the first example, the chandeliers will have different colors at days 11, 22, 33 and 55. That's why the answer is 55.

在第一个例子中,枝形吊灯将在第 11、22、33 和 55 天呈现不同的颜色。因此答案为 55。

输入解题思路,AI测评打分。不知道怎么写?

首页