CF1562C.Rings

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Frodo was caught by Saruman. He tore a pouch from Frodo's neck, shook out its contents —there was a pile of different rings: gold and silver...

"How am I to tell which is the One?!" the mage howled.

"Throw them one by one into the Cracks of Doom and watch when Mordor falls!"

Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found nn rings. And the ii-th ring was either gold or silver. For convenience Saruman wrote down a binary string ss of nn characters, where the ii-th character was 0 if the ii-th ring was gold, and 1 if it was silver.

Saruman has a magic function ff, which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, f(001010)=10,f(111)=7,f(11011101)=221f(001010) = 10, f(111) = 7, f(11011101) = 221.

Saruman, however, thinks that the order of the rings plays some important role. He wants to find 22 pairs of integers (l1,r1),(l2,r2)(l_1, r_1), (l_2, r_2), such that:

  • 1≤l1≤n1 \le l_1 \le n, 1≤r1≤n1 \le r_1 \le n, r1−l1+1≥⌊n2⌋r_1-l_1+1\ge \lfloor \frac{n}{2} \rfloor
  • 1≤l2≤n1 \le l_2 \le n, 1≤r2≤n1 \le r_2 \le n, r2−l2+1≥⌊n2⌋r_2-l_2+1\ge \lfloor \frac{n}{2} \rfloor
  • Pairs (l1,r1)(l_1, r_1) and (l2,r2)(l_2, r_2) are distinct. That is, at least one of l1≠l2l_1 \neq l_2 and r1≠r2r_1 \neq r_2 must hold.
  • Let tt be the substring s[l1:r1]s[l_1:r_1] of ss, and ww be the substring s[l2:r2]s[l_2:r_2] of ss. Then there exists non-negative integer kk, such that f(t)=f(w)⋅kf(t) = f(w) \cdot k.

Here substring s[l:r]s[l:r] denotes slsl+1…sr−1srs_ls_{l+1}\ldots s_{r-1}s_r, and ⌊x⌋\lfloor x \rfloor denotes rounding the number down to the nearest integer.

Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists.

弗罗多被萨鲁曼抓住了。萨鲁曼从弗罗多的脖子上扯下一个袋子,抖出里面的东西——一堆各式各样的戒指:金戒指和银戒指……

“我怎么才能分辨出哪一枚是至尊魔戒?!”巫师怒吼道。

“把它们一个接一个地扔进末日裂罅,然后看魔多何时覆灭!”

在某个平行的中土世界里,当萨鲁曼抓住弗罗多时,他只找到了 nn 枚戒指。其中第 ii 枚戒指要么是金的,要么是银的。为方便起见,萨鲁曼写下了一个长度为 nn 的二进制字符串 ss,其中第 ii 个字符为 0 表示第 ii 枚戒指是金的,为 1 表示是银的。

萨鲁曼拥有一种魔法函数 ff,该函数接收一个二进制字符串,并将其先解释为一个二进制数,再将该二进制数转换为十进制整数后返回。例如,f(001010)=10f(001010) = 10,f(111)=7f(111) = 7,f(11011101)=221f(11011101) = 221。

然而,萨鲁曼认为戒指的排列顺序具有某种重要意义。他希望找到两对整数 (l1,r1)(l_1, r_1) 和 (l2,r2)(l_2, r_2),满足以下条件:

  • 1≤l1≤n1 \le l_1 \le n,1≤r1≤n1 \le r_1 \le n,且 r1−l1+1≥⌊n2⌋r_1-l_1+1\ge \lfloor \frac{n}{2} \rfloor;
  • 1≤l2≤n1 \le l_2 \le n,1≤r2≤n1 \le r_2 \le n,且 r2−l2+1≥⌊n2⌋r_2-l_2+1\ge \lfloor \frac{n}{2} \rfloor;
  • 两对 (l1,r1)(l_1, r_1) 和 (l2,r2)(l_2, r_2) 互不相同,即至少满足 l1≠l2l_1 \neq l_2 或 r1≠r2r_1 \neq r_2 中的一个;
  • 设 tt 是 ss 的子串 s[l1:r1]s[l_1:r_1],ww 是 ss 的子串 s[l2:r2]s[l_2:r_2],则存在一个非负整数 kk,使得 f(t)=f(w)⋅kf(t) = f(w) \cdot k。

此处子串 s[l:r]s[l:r] 表示 slsl+1…sr−1srs_l s_{l+1} \ldots s_{r-1} s_r,而 ⌊x⌋\lfloor x \rfloor 表示将 xx 向下取整(即取不大于 xx 的最大整数)。

请帮助萨鲁曼解决这个问题!题目保证在给定约束条件下至少存在一组解。

输入格式

Each test contains multiple test cases.

The first line contains one positive integer tt (1≤t≤1031 \le t \le 10^3), denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains one positive integer nn (2≤n≤2⋅1042 \le n \le 2 \cdot 10^4) — length of the string.

The second line of each test case contains a non-empty binary string of length nn.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。

第一行包含一个正整数 tt(1≤t≤1031 \le t \le 10^3),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个正整数 nn(2≤n≤2⋅1042 \le n \le 2 \cdot 10^4)—— 字符串的长度。

每个测试用例的第二行包含一个长度为 nn 的非空二进制字符串。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For every test case print four integers l1l_1, r1r_1, l2l_2, r2r_2, which denote the beginning of the first substring, the end of the first substring, the beginning of the second substring, and the end of the second substring, respectively.

If there are multiple solutions, print any.

对每个测试用例,输出四个整数 l1l_1、r1r_1、l2l_2、r2r_2,分别表示第一个子串的起始位置、第一个子串的结束位置、第二个子串的起始位置以及第二个子串的结束位置。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    7
    6
    101111
    9
    111000111
    8
    10000000
    5
    11011
    6
    001111
    3
    101
    30
    100000000000000100000000000000

    输出#1

    3 6 1 3
    1 9 4 9
    5 8 1 4
    1 5 3 5
    1 6 2 4
    1 2 2 3
    1 15 16 30

说明/提示

In the first testcase f(t)=f(1111)=15f(t) = f(1111) = 15, f(w)=f(101)=5f(w) = f(101) = 5.

In the second testcase f(t)=f(111000111)=455f(t) = f(111000111) = 455, f(w)=f(000111)=7f(w) = f(000111) = 7.

In the third testcase f(t)=f(0000)=0f(t) = f(0000) = 0, f(w)=f(1000)=8f(w) = f(1000) = 8.

In the fourth testcase f(t)=f(11011)=27f(t) = f(11011) = 27, f(w)=f(011)=3f(w) = f(011) = 3.

In the fifth testcase f(t)=f(001111)=15f(t) = f(001111) = 15, f(w)=f(011)=3f(w) = f(011) = 3.

第一个测试用例中,f(t)=f(1111)=15f(t) = f(1111) = 15,f(w)=f(101)=5f(w) = f(101) = 5。

第二个测试用例中,f(t)=f(111000111)=455f(t) = f(111000111) = 455,f(w)=f(000111)=7f(w) = f(000111) = 7。

第三个测试用例中,f(t)=f(0000)=0f(t) = f(0000) = 0,f(w)=f(1000)=8f(w) = f(1000) = 8。

第四个测试用例中,f(t)=f(11011)=27f(t) = f(11011) = 27,f(w)=f(011)=3f(w) = f(011) = 3。

第五个测试用例中,f(t)=f(001111)=15f(t) = f(001111) = 15,f(w)=f(011)=3f(w) = f(011) = 3。

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

首页