CF1179E.Alesya and Discrete Math

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

We call a function good if its domain of definition is some set of integers and if in case it's defined in xx and x−1x-1, f(x)=f(x−1)+1f(x) = f(x-1) + 1 or f(x)=f(x−1)f(x) = f(x-1).

Tanya has found nn good functions f1,…,fnf_{1}, \ldots, f_{n}, which are defined on all integers from 00 to 101810^{18} and fi(0)=0f_i(0) = 0 and fi(1018)=Lf_i(10^{18}) = L for all ii from 11 to nn. It's an notorious coincidence that nn is a divisor of LL.

She suggests Alesya a game. Using one question Alesya can ask Tanya a value of any single function in any single point. To win Alesya must choose integers lil_{i} and rir_{i} (0≤li≤ri≤10180 \leq l_{i} \leq r_{i} \leq 10^{18}), such that fi(ri)−fi(li)≥Lnf_{i}(r_{i}) - f_{i}(l_{i}) \geq \frac{L}{n} (here fi(x)f_i(x) means the value of ii-th function at point xx) for all ii such that 1≤i≤n1 \leq i \leq n so that for any pair of two functions their segments [li,ri][l_i, r_i] don't intersect (but may have one common point).

Unfortunately, Tanya doesn't allow to make more than 2⋅1052 \cdot 10^{5} questions. Help Alesya to win!

It can be proved that it's always possible to choose [li,ri][l_i, r_i] which satisfy the conditions described above.

It's guaranteed, that Tanya doesn't change functions during the game, i.e. interactor is not adaptive

我们称一个函数是“好”的,如果它的定义域是某个整数集合,且当它在 xx 和 x−1x-1 处均有定义时,满足 f(x)=f(x−1)+1f(x) = f(x-1) + 1 或 f(x)=f(x−1)f(x) = f(x-1)。

塔尼娅找到了 nn 个“好”函数 f1,…,fnf_{1}, \ldots, f_{n},它们均在从 00 到 101810^{18} 的所有整数上定义,且对所有 i∈[1,n]i\in[1,n] 均有 fi(0)=0f_i(0) = 0 以及 fi(1018)=Lf_i(10^{18}) = L。一个众所周知的巧合是:nn 整除 LL。

她向阿列西娅提议一个游戏。阿列西娅每次提问可向塔尼娅询问任意一个函数在任意一个点上的取值。为赢得游戏,阿列西娅必须为每个 ii(1≤i≤n1 \le i \le n)选择整数 lil_{i} 和 rir_{i}(满足 0≤li≤ri≤10180 \leq l_{i} \leq r_{i} \leq 10^{18}),使得对所有 ii 都有 fi(ri)−fi(li)≥Lnf_{i}(r_{i}) - f_{i}(l_{i}) \geq \frac{L}{n}(此处 fi(x)f_i(x) 表示第 ii 个函数在点 xx 处的取值),并且任意两个函数所对应的区间 [li,ri][l_i, r_i] 互不相交(但允许恰好有一个公共端点)。

不幸的是,塔尼娅不允许提问次数超过 2⋅1052 \cdot 10^{5} 次。请帮助阿列西娅获胜!

可以证明:总存在满足上述条件的区间 [li,ri][l_i, r_i]。

保证塔尼娅在游戏过程中不会更改函数,即交互器是非自适应的。

输入格式

The first line contains two integers nn and LL (1≤n≤10001 \leq n \leq 1000, 1≤L≤10181 \leq L \leq 10^{18}, nn is a divisor of LL) — number of functions and their value in 101810^{18}.

第一行包含两个整数 nn 和 LL(1≤n≤10001 \leq n \leq 1000,1≤L≤10181 \leq L \leq 10^{18},且 nn 是 LL 的约数)—— 分别表示函数的个数及其在 101810^{18} 处的取值。

输出格式

When you've found needed li,ril_i, r_i, print "!""!" without quotes on a separate line and then nn lines, ii-th from them should contain two integers lil_i, rir_i divided by space.

当找到所需的 li,ril_i, r_i 后,在单独一行输出不带引号的 "!",然后输出 nn 行,其中第 ii 行应包含两个由空格分隔的整数 lil_i 和 rir_i。

输入输出样例

  • 输入#1

    5 5
    ? 1 0
    ? 1 1
    ? 2 1
    ? 2 2
    ? 3 2
    ? 3 3
    ? 4 3
    ? 4 4
    ? 5 4
    ? 5 5
    !
    0 1
    1 2
    2 3
    3 4
    4 5

    输出#1

    0
    1
    1
    2
    2
    3
    3
    4
    4
    4
    5

说明/提示

In the example Tanya has 55 same functions where f(0)=0f(0) = 0, f(1)=1f(1) = 1, f(2)=2f(2) = 2, f(3)=3f(3) = 3, f(4)=4f(4) = 4 and all remaining points have value 55.

Alesya must choose two integers for all functions so that difference of values of a function in its points is not less than Ln\frac{L}{n} (what is 11 here) and length of intersection of segments is zero.

One possible way is to choose pairs [0[0, 1]1], [1[1, 2]2], [2[2, 3]3], [3[3, 4]4] and [4[4, 5]5] for functions 11, 22, 33, 44 and 55 respectively.

在该示例中,塔尼娅有 55 个相同的函数,满足 f(0)=0f(0) = 0、f(1)=1f(1) = 1、f(2)=2f(2) = 2、f(3)=3f(3) = 3、f(4)=4f(4) = 4,其余所有点的函数值均为 55。

阿列西娅必须为每个函数选定两个整数,使得该函数在其所选两点处的函数值之差不小于 Ln\frac{L}{n}(本题中该值为 11),且所选区间段的交集长度为零。

一种可行方案是:分别为第 11、22、33、44、55 个函数选择区间对 [0,1][0, 1]、[1,2][1, 2]、[2,3][2, 3]、[3,4][3, 4] 和 [4,5][4, 5]。

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

首页