QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#853864#9734. Identify Chorducup-team296#AC ✓56ms2284kbRust17.2kb2025-01-11 19:47:442025-01-11 19:47:45

Judging History

你现在查看的是最新测评结果

  • [2025-01-11 19:47:45]
  • 评测
  • 测评结果:AC
  • 用时:56ms
  • 内存:2284kb
  • [2025-01-11 19:47:44]
  • 提交

answer

// https://contest.ucup.ac/contest/1893/problem/9734
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::misc::test_type::TaskType;
use crate::algo_lib::misc::test_type::TestType;

type PreCalc = ();
fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &mut PreCalc) {
    let n = input.read_size();
    let mut query = |a: usize, b: usize| -> usize {
        output!(out, "? {} {}", a % n + 1, b % n + 1);
        out.flush();
        input.read_size()
    };
    let mut base = 0;
    let base_res = loop {
        let res = query(base, base + n / 2);
        if res != n / 2 {
            break res;
        }
        base = (base + n / 2 - 1) % n;
    };
    let end = base + n / 2;
    let (one_end, dist_to_end) = if query(base + 1, end) < base_res {
        let mut left = base + 1;
        let mut right = end - 1;
        while left < right {
            let mid = (left + right + 1) / 2;
            let res = query(mid, end);
            if res + (mid - base) == base_res {
                left = mid;
            } else {
                right = mid - 1;
            }
        }
        (left, base_res - (left - base))
    } else if query(base + n - 1, end) < base_res {
        let mut left = end + 1;
        let mut right = base + n - 1;
        while left < right {
            let mid = (left + right) / 2;
            let res = query(mid, end);
            if res + (base + n - mid) == base_res {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        (left, base_res - (base + n - left))
    } else {
        (base, base_res)
    };
    if dist_to_end == 1 {
        output!(out, "! {} {}", one_end % n + 1, end % n + 1);
    } else {
        if query(one_end, end + dist_to_end - 1) == 1 {
            output!(out, "! {} {}", one_end % n + 1, (end + dist_to_end - 1) % n + 1);
        } else {
            output!(
                out, "! {} {}", one_end % n + 1, (end + n - (dist_to_end - 1)) % n + 1
            );
        }
    }
    out.flush();
    assert_eq!(input.read_int(), 1);
}
pub static TEST_TYPE: TestType = TestType::MultiNumber;
pub static TASK_TYPE: TaskType = TaskType::Interactive;
pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
    let mut pre_calc = ();
    match TEST_TYPE {
        TestType::Single => solve(&mut input, &mut output, 1, &mut pre_calc),
        TestType::MultiNumber => {
            let t = input.read();
            for i in 1..=t {
                solve(&mut input, &mut output, i, &mut pre_calc);
            }
        }
        TestType::MultiEof => {
            let mut i = 1;
            while input.peek().is_some() {
                solve(&mut input, &mut output, i, &mut pre_calc);
                i += 1;
            }
        }
    }
    output.flush();
    match TASK_TYPE {
        TaskType::Classic => input.is_empty(),
        TaskType::Interactive => true,
    }
}


fn main() {
    let mut sin = std::io::stdin();
    let input = crate::algo_lib::io::input::Input::new(&mut sin);
    let mut stdout = std::io::stdout();
    let output = crate::algo_lib::io::output::Output::new(&mut stdout);
    run(input, output);
}
pub mod algo_lib {
pub mod collections {
pub mod vec_ext {
pub mod default {
pub fn default_vec<T: Default>(len: usize) -> Vec<T> {
    let mut v = Vec::with_capacity(len);
    for _ in 0..len {
        v.push(T::default());
    }
    v
}
}
}
}
pub mod io {
pub mod input {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::io::Read;
use std::mem::MaybeUninit;
pub struct Input<'s> {
    input: &'s mut (dyn Read + Send),
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
    eol: bool,
}
macro_rules! read_impl {
    ($t:ty, $read_name:ident, $read_vec_name:ident) => {
        pub fn $read_name (& mut self) -> $t { self.read() } pub fn $read_vec_name (& mut
        self, len : usize) -> Vec <$t > { self.read_vec(len) }
    };
    ($t:ty, $read_name:ident, $read_vec_name:ident, $read_pair_vec_name:ident) => {
        read_impl!($t, $read_name, $read_vec_name); pub fn $read_pair_vec_name (& mut
        self, len : usize) -> Vec < ($t, $t) > { self.read_vec(len) }
    };
}
impl<'s> Input<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;
    pub fn new(input: &'s mut (dyn Read + Send)) -> Self {
        Self {
            input,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            buf_read: 0,
            eol: true,
        }
    }
    pub fn new_with_size(input: &'s mut (dyn Read + Send), buf_size: usize) -> Self {
        Self {
            input,
            buf: default_vec(buf_size),
            at: 0,
            buf_read: 0,
            eol: true,
        }
    }
    pub fn get(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            self.at += 1;
            if res == b'\r' {
                self.eol = true;
                if self.refill_buffer() && self.buf[self.at] == b'\n' {
                    self.at += 1;
                }
                return Some(b'\n');
            }
            self.eol = res == b'\n';
            Some(res)
        } else {
            None
        }
    }
    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            Some(if res == b'\r' { b'\n' } else { res })
        } else {
            None
        }
    }
    pub fn skip_whitespace(&mut self) {
        while let Some(b) = self.peek() {
            if !b.is_ascii_whitespace() {
                return;
            }
            self.get();
        }
    }
    pub fn next_token(&mut self) -> Option<Vec<u8>> {
        self.skip_whitespace();
        let mut res = Vec::new();
        while let Some(c) = self.get() {
            if c.is_ascii_whitespace() {
                break;
            }
            res.push(c);
        }
        if res.is_empty() { None } else { Some(res) }
    }
    pub fn is_exhausted(&mut self) -> bool {
        self.peek().is_none()
    }
    pub fn is_empty(&mut self) -> bool {
        self.skip_whitespace();
        self.is_exhausted()
    }
    pub fn read<T: Readable>(&mut self) -> T {
        T::read(self)
    }
    pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
        let mut res = Vec::with_capacity(size);
        for _ in 0..size {
            res.push(self.read());
        }
        res
    }
    pub fn read_char(&mut self) -> u8 {
        self.skip_whitespace();
        self.get().unwrap()
    }
    read_impl!(u32, read_unsigned, read_unsigned_vec);
    read_impl!(u64, read_u64, read_u64_vec);
    read_impl!(usize, read_size, read_size_vec, read_size_pair_vec);
    read_impl!(i32, read_int, read_int_vec, read_int_pair_vec);
    read_impl!(i64, read_long, read_long_vec, read_long_pair_vec);
    read_impl!(i128, read_i128, read_i128_vec);
    fn refill_buffer(&mut self) -> bool {
        if self.at == self.buf_read {
            self.at = 0;
            self.buf_read = self.input.read(&mut self.buf).unwrap();
            self.buf_read != 0
        } else {
            true
        }
    }
    pub fn is_eol(&self) -> bool {
        self.eol
    }
}
pub trait Readable {
    fn read(input: &mut Input) -> Self;
}
impl Readable for u8 {
    fn read(input: &mut Input) -> Self {
        input.read_char()
    }
}
impl<T: Readable> Readable for Vec<T> {
    fn read(input: &mut Input) -> Self {
        let size = input.read();
        input.read_vec(size)
    }
}
impl<T: Readable, const SIZE: usize> Readable for [T; SIZE] {
    fn read(input: &mut Input) -> Self {
        unsafe {
            let mut res = MaybeUninit::<[T; SIZE]>::uninit();
            for i in 0..SIZE {
                let ptr: *mut T = (*res.as_mut_ptr()).as_mut_ptr();
                ptr.add(i).write(input.read::<T>());
            }
            res.assume_init()
        }
    }
}
macro_rules! read_integer {
    ($($t:ident)+) => {
        $(impl Readable for $t { fn read(input : & mut Input) -> Self { input
        .skip_whitespace(); let mut c = input.get().unwrap(); let sgn = match c { b'-' =>
        { c = input.get().unwrap(); true } b'+' => { c = input.get().unwrap(); false } _
        => false, }; let mut res = 0; loop { assert!(c.is_ascii_digit()); res *= 10; let
        d = (c - b'0') as $t; if sgn { res -= d; } else { res += d; } match input.get() {
        None => break, Some(ch) => { if ch.is_ascii_whitespace() { break; } else { c =
        ch; } } } } res } })+
    };
}
read_integer!(i8 i16 i32 i64 i128 isize u16 u32 u64 u128 usize);
macro_rules! tuple_readable {
    ($($name:ident)+) => {
        impl <$($name : Readable),+> Readable for ($($name,)+) { fn read(input : & mut
        Input) -> Self { ($($name ::read(input),)+) } }
    };
}
tuple_readable! {
    T
}
tuple_readable! {
    T U
}
tuple_readable! {
    T U V
}
tuple_readable! {
    T U V X
}
tuple_readable! {
    T U V X Y
}
tuple_readable! {
    T U V X Y Z
}
tuple_readable! {
    T U V X Y Z A
}
tuple_readable! {
    T U V X Y Z A B
}
tuple_readable! {
    T U V X Y Z A B C
}
tuple_readable! {
    T U V X Y Z A B C D
}
tuple_readable! {
    T U V X Y Z A B C D E
}
tuple_readable! {
    T U V X Y Z A B C D E F
}
}
pub mod output {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::cmp::Reverse;
use std::io::{stderr, Stderr, Write};
#[derive(Copy, Clone)]
pub enum BoolOutput {
    YesNo,
    YesNoCaps,
    PossibleImpossible,
    Custom(&'static str, &'static str),
}
impl BoolOutput {
    pub fn output(&self, output: &mut Output, val: bool) {
        (if val { self.yes() } else { self.no() }).write(output);
    }
    fn yes(&self) -> &str {
        match self {
            BoolOutput::YesNo => "Yes",
            BoolOutput::YesNoCaps => "YES",
            BoolOutput::PossibleImpossible => "Possible",
            BoolOutput::Custom(yes, _) => yes,
        }
    }
    fn no(&self) -> &str {
        match self {
            BoolOutput::YesNo => "No",
            BoolOutput::YesNoCaps => "NO",
            BoolOutput::PossibleImpossible => "Impossible",
            BoolOutput::Custom(_, no) => no,
        }
    }
}
pub struct Output<'s> {
    output: &'s mut dyn Write,
    buf: Vec<u8>,
    at: usize,
    auto_flush: bool,
    bool_output: BoolOutput,
    precision: Option<usize>,
    separator: u8,
}
impl<'s> Output<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;
    pub fn new(output: &'s mut dyn Write) -> Self {
        Self {
            output,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            auto_flush: false,
            bool_output: BoolOutput::YesNoCaps,
            precision: None,
            separator: b' ',
        }
    }
    pub fn new_with_auto_flush(output: &'s mut dyn Write) -> Self {
        Self {
            output,
            buf: default_vec(Self::DEFAULT_BUF_SIZE),
            at: 0,
            auto_flush: true,
            bool_output: BoolOutput::YesNoCaps,
            precision: None,
            separator: b' ',
        }
    }
    pub fn flush(&mut self) {
        if self.at != 0 {
            self.output.write_all(&self.buf[..self.at]).unwrap();
            self.output.flush().unwrap();
            self.at = 0;
        }
    }
    pub fn print<T: Writable>(&mut self, s: T) {
        s.write(self);
        self.maybe_flush();
    }
    pub fn print_line<T: Writable>(&mut self, s: T) {
        self.print(s);
        self.put(b'\n');
        self.maybe_flush();
    }
    pub fn put(&mut self, b: u8) {
        self.buf[self.at] = b;
        self.at += 1;
        if self.at == self.buf.len() {
            self.flush();
        }
    }
    pub fn maybe_flush(&mut self) {
        if self.auto_flush {
            self.flush();
        }
    }
    pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
        self.print_per_line_iter(arg.iter());
    }
    pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(self.separator);
            }
            e.write(self);
        }
    }
    pub fn print_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        self.print_iter(iter);
        self.put(b'\n');
    }
    pub fn print_per_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        for e in iter {
            e.write(self);
            self.put(b'\n');
        }
    }
    pub fn set_bool_output(&mut self, bool_output: BoolOutput) {
        self.bool_output = bool_output;
    }
    pub fn set_precision(&mut self, precision: usize) {
        self.precision = Some(precision);
    }
    pub fn reset_precision(&mut self) {
        self.precision = None;
    }
    pub fn get_precision(&self) -> Option<usize> {
        self.precision
    }
    pub fn separator(&self) -> u8 {
        self.separator
    }
    pub fn set_separator(&mut self, separator: u8) {
        self.separator = separator;
    }
}
impl Write for Output<'_> {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        let mut start = 0usize;
        let mut rem = buf.len();
        while rem > 0 {
            let len = (self.buf.len() - self.at).min(rem);
            self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
            self.at += len;
            if self.at == self.buf.len() {
                self.flush();
            }
            start += len;
            rem -= len;
        }
        self.maybe_flush();
        Ok(buf.len())
    }
    fn flush(&mut self) -> std::io::Result<()> {
        self.flush();
        Ok(())
    }
}
pub trait Writable {
    fn write(&self, output: &mut Output);
}
impl Writable for &str {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}
impl Writable for String {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}
impl Writable for char {
    fn write(&self, output: &mut Output) {
        output.put(*self as u8);
    }
}
impl Writable for u8 {
    fn write(&self, output: &mut Output) {
        output.put(*self);
    }
}
impl<T: Writable> Writable for [T] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}
impl<T: Writable, const N: usize> Writable for [T; N] {
    fn write(&self, output: &mut Output) {
        output.print_iter(self.iter());
    }
}
impl<T: Writable + ?Sized> Writable for &T {
    fn write(&self, output: &mut Output) {
        T::write(self, output)
    }
}
impl<T: Writable> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self.as_slice().write(output);
    }
}
impl Writable for () {
    fn write(&self, _output: &mut Output) {}
}
macro_rules! write_to_string {
    ($($t:ident)+) => {
        $(impl Writable for $t { fn write(& self, output : & mut Output) { self
        .to_string().write(output); } })+
    };
}
write_to_string!(u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
macro_rules! tuple_writable {
    ($name0:ident $($name:ident : $id:tt)*) => {
        impl <$name0 : Writable, $($name : Writable,)*> Writable for ($name0, $($name,)*)
        { fn write(& self, out : & mut Output) { self.0.write(out); $(out.put(out
        .separator); self.$id .write(out);)* } }
    };
}
tuple_writable! {
    T
}
tuple_writable! {
    T U : 1
}
tuple_writable! {
    T U : 1 V : 2
}
tuple_writable! {
    T U : 1 V : 2 X : 3
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5 A : 6
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5 A : 6 B : 7
}
tuple_writable! {
    T U : 1 V : 2 X : 3 Y : 4 Z : 5 A : 6 B : 7 C : 8
}
impl<T: Writable> Writable for Option<T> {
    fn write(&self, output: &mut Output) {
        match self {
            None => (-1).write(output),
            Some(t) => t.write(output),
        }
    }
}
impl Writable for bool {
    fn write(&self, output: &mut Output) {
        let bool_output = output.bool_output;
        bool_output.output(output, *self)
    }
}
impl<T: Writable> Writable for Reverse<T> {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
    }
}
static mut ERR: Option<Stderr> = None;
pub fn err() -> Output<'static> {
    unsafe {
        if ERR.is_none() {
            ERR = Some(stderr());
        }
        Output::new_with_auto_flush(ERR.as_mut().unwrap())
    }
}
}
pub mod output_macro {
#[macro_export]
macro_rules! output {
    ($output:expr, $($arg:tt)*) => {
        $output .print_line(format!($($arg)*));
    };
}
}
}
pub mod misc {
pub mod test_type {
pub enum TestType {
    Single,
    MultiNumber,
    MultiEof,
}
pub enum TaskType {
    Classic,
    Interactive,
}
}
}
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 2052kb

input:

2
6
2
1
1
1
4
1
1
1
1

output:

? 1 4
? 2 4
? 3 4
! 2 4
? 1 3
? 2 3
? 4 3
! 1 3

result:

ok ok (2 test cases)

Test #2:

score: 0
Accepted
time: 4ms
memory: 2104kb

input:

1000
15
5
4
1
2
1
19
5
4
4
4
3
1
1
17
5
4
4
3
4
1
1
15
6
6
7
3
1
14
5
4
3
5
5
1
15
3
2
3
3
1
1
17
8
6
7
5
4
3
4
4
1
20
6
7
7
5
1
13
5
5
4
3
3
2
3
1
18
3
4
2
4
4
3
1
1
13
4
5
3
3
4
1
1
14
2
3
1
3
2
1
17
8
8
5
6
4
2
2
1
1
12
5
4
3
3
1
1
10
5
3
4
4
3
1
14
6
5
2
1
1
1
19
8
8
7
5
7
6
1
1
19
6
5
4
6
6
1
1...

output:

? 1 8
? 2 8
? 5 8
? 6 8
! 5 8
? 1 10
? 2 10
? 6 10
? 4 10
? 3 10
? 3 12
! 3 12
? 1 9
? 2 9
? 5 9
? 3 9
? 4 9
? 3 11
! 3 11
? 1 8
? 2 8
? 15 8
? 1 13
! 1 3
? 1 8
? 2 8
? 5 8
? 3 8
? 2 11
! 2 5
? 1 8
? 2 8
? 5 8
? 3 8
? 2 9
! 2 9
? 1 9
? 8 16
? 9 16
? 7 16
? 3 16
? 5 16
? 4 16
? 5 1
! 5 14
? 1 11
? 2 ...

result:

ok ok (1000 test cases)

Test #3:

score: 0
Accepted
time: 7ms
memory: 2232kb

input:

1000
21
3
4
2
5
4
3
3
1
22
8
7
5
7
6
1
1
20
5
4
2
2
1
1
22
10
9
4
3
4
1
1
21
9
8
4
3
3
1
1
21
8
9
7
5
5
6
1
1
24
11
11
10
5
3
4
4
2
1
22
10
10
9
4
2
2
1
1
21
4
3
5
5
4
1
1
23
8
9
7
6
9
8
1
1
21
10
8
9
7
5
7
6
4
1
24
9
8
3
3
2
3
1
1
20
9
9
8
4
2
1
1
1
24
11
10
5
2
2
3
1
23
8
9
9
5
1
23
7
6
5
6
5
1
1
...

output:

? 1 11
? 2 11
? 21 11
? 16 11
? 19 11
? 20 11
? 21 12
! 21 10
? 1 12
? 2 12
? 7 12
? 4 12
? 3 12
? 3 17
! 3 17
? 1 11
? 2 11
? 6 11
? 4 11
? 5 11
! 5 11
? 1 12
? 2 12
? 7 12
? 9 12
? 8 12
? 7 15
! 7 15
? 1 11
? 2 11
? 6 11
? 8 11
? 7 11
? 7 13
! 7 13
? 1 11
? 2 11
? 21 11
? 16 11
? 19 11
? 18 11
? 1...

result:

ok ok (1000 test cases)

Test #4:

score: 0
Accepted
time: 7ms
memory: 2284kb

input:

1000
25
8
9
9
6
1
25
6
7
5
6
8
6
8
1
25
11
11
10
6
9
9
8
3
1
25
5
4
6
4
3
5
1
26
12
12
11
5
3
5
1
1
26
11
12
10
6
9
9
10
3
1
26
13
11
12
10
4
1
2
1
27
12
11
5
3
5
9
1
25
9
10
8
2
3
1
2
1
27
9
8
6
7
7
6
11
1
27
11
12
10
4
4
5
1
1
27
13
10
11
9
7
6
5
6
5
1
26
5
6
4
6
5
3
4
1
1
25
11
11
10
6
9
11
3
1
2...

output:

? 1 13
? 2 13
? 25 13
? 1 20
! 1 6
? 1 13
? 2 13
? 25 13
? 19 13
? 22 13
? 24 13
? 25 17
! 25 9
? 1 13
? 2 13
? 25 13
? 19 13
? 22 13
? 24 13
? 23 13
? 23 20
! 23 6
? 1 13
? 2 13
? 7 13
? 4 13
? 3 13
? 3 15
! 3 11
? 1 14
? 2 14
? 26 14
? 20 14
? 17 14
? 19 14
? 20 18
! 20 18
? 1 14
? 2 14
? 26 14
? ...

result:

ok ok (1000 test cases)

Test #5:

score: 0
Accepted
time: 7ms
memory: 2156kb

input:

1000
29
10
9
7
10
8
9
1
1
28
13
13
12
7
9
8
8
2
1
30
3
2
7
5
3
1
1
29
4
3
7
6
4
5
1
28
8
9
7
3
4
3
2
3
1
29
6
5
7
6
4
5
1
1
29
9
10
8
7
7
7
6
1
1
28
11
10
4
4
5
7
1
30
4
5
3
6
2
2
1
1
30
8
9
7
4
4
2
3
3
1
28
11
10
4
3
3
2
1
1
29
14
13
12
7
9
8
7
13
1
29
11
10
7
10
9
10
9
1
29
7
8
6
3
3
1
2
1
29
14
1...

output:

? 1 15
? 2 15
? 8 15
? 5 15
? 3 15
? 4 15
? 3 22
! 3 22
? 1 15
? 2 15
? 28 15
? 22 15
? 25 15
? 24 15
? 23 15
? 24 22
! 24 8
? 1 16
? 2 16
? 9 16
? 5 16
? 3 16
? 2 17
! 2 17
? 1 15
? 2 15
? 8 15
? 5 15
? 3 15
? 2 17
! 2 13
? 1 15
? 2 15
? 28 15
? 22 15
? 25 15
? 24 15
? 23 15
? 23 16
! 23 14
? 1 15
...

result:

ok ok (1000 test cases)

Test #6:

score: 0
Accepted
time: 0ms
memory: 2080kb

input:

1000
32
13
12
8
9
10
10
12
1
30
14
14
13
7
11
12
11
1
1
32
16
14
15
13
8
10
8
7
3
1
31
5
4
7
3
3
2
3
1
32
7
6
8
7
5
6
1
1
32
8
7
8
10
8
1
1
31
15
15
12
13
11
4
4
2
3
3
1
31
6
7
5
8
8
6
1
1
32
12
11
4
4
4
3
5
1
30
14
14
13
7
10
9
9
1
1
31
11
12
10
8
9
9
8
6
1
31
10
11
9
2
4
4
3
1
1
33
7
8
8
11
1
32
1...

output:

? 1 17
? 2 17
? 9 17
? 5 17
? 7 17
? 6 17
? 5 25
! 5 9
? 1 16
? 2 16
? 30 16
? 23 16
? 27 16
? 29 16
? 28 16
? 28 26
! 28 26
? 1 17
? 16 32
? 17 32
? 15 32
? 8 32
? 12 32
? 10 32
? 9 32
? 9 6
! 9 26
? 1 16
? 2 16
? 9 16
? 5 16
? 3 16
? 4 16
? 4 17
! 4 15
? 1 17
? 2 17
? 9 17
? 5 17
? 3 17
? 4 17
? 3...

result:

ok ok (1000 test cases)

Test #7:

score: 0
Accepted
time: 13ms
memory: 2160kb

input:

1000
34
17
16
16
15
7
4
5
4
2
1
33
8
7
6
4
4
3
5
1
33
11
12
10
8
10
8
9
1
1
34
11
12
10
8
10
8
9
7
1
34
11
10
8
12
12
11
1
1
35
14
15
15
5
1
34
8
9
7
8
9
7
6
10
1
34
14
13
8
11
11
10
1
1
34
16
15
8
12
13
13
8
1
33
9
10
8
8
4
6
5
1
1
33
16
15
14
8
12
14
5
1
34
16
16
16
1
1
33
13
14
12
4
4
4
3
5
1
34
...

output:

? 1 18
? 17 34
? 18 34
? 16 34
? 8 34
? 4 34
? 6 34
? 5 34
? 5 3
! 5 31
? 1 17
? 2 17
? 9 17
? 5 17
? 7 17
? 6 17
? 6 19
! 6 15
? 1 17
? 2 17
? 33 17
? 25 17
? 29 17
? 31 17
? 30 17
? 31 24
! 31 24
? 1 18
? 2 18
? 34 18
? 26 18
? 30 18
? 32 18
? 31 18
? 32 25
! 32 11
? 1 18
? 2 18
? 10 18
? 6 18
? 4...

result:

ok ok (1000 test cases)

Test #8:

score: 0
Accepted
time: 10ms
memory: 2228kb

input:

1000
36
18
17
17
17
2
1
36
3
4
2
8
4
2
1
1
36
13
12
9
12
10
11
12
1
36
5
4
9
6
4
3
5
1
36
18
17
17
16
8
5
6
5
2
1
36
12
11
3
5
5
4
1
1
35
13
14
12
6
8
6
5
1
1
36
13
12
4
5
4
3
1
1
36
14
13
9
9
11
10
1
1
36
16
15
9
11
9
8
15
1
36
9
8
9
6
6
5
1
1
36
8
9
7
9
7
5
6
9
1
36
17
16
8
4
3
4
7
1
36
15
14
6
5
...

output:

? 1 19
? 18 36
? 19 36
? 17 36
? 18 16
! 18 20
? 1 19
? 2 19
? 36 19
? 28 19
? 32 19
? 34 19
? 35 19
! 35 19
? 1 19
? 2 19
? 10 19
? 6 19
? 4 19
? 5 19
? 4 28
! 4 10
? 1 19
? 2 19
? 10 19
? 6 19
? 4 19
? 3 19
? 3 21
! 3 17
? 1 19
? 18 36
? 19 36
? 17 36
? 9 36
? 5 36
? 7 36
? 6 36
? 6 4
! 6 32
? 1 1...

result:

ok ok (1000 test cases)

Test #9:

score: 0
Accepted
time: 3ms
memory: 2108kb

input:

1000
37
17
17
16
7
5
7
6
3
1
36
17
17
16
8
5
7
8
1
1
38
9
8
7
4
4
3
5
1
37
15
14
6
4
4
3
1
1
37
12
13
11
2
4
2
1
1
36
8
9
7
9
7
5
6
1
1
37
6
7
5
9
7
5
4
1
1
37
18
15
16
14
9
10
8
7
8
5
1
37
17
17
16
7
3
1
2
1
37
8
7
7
3
5
4
1
1
37
10
11
9
9
11
9
8
1
1
37
18
18
17
16
9
13
15
15
7
1
36
3
4
2
9
6
4
3
1...

output:

? 1 19
? 2 19
? 37 19
? 28 19
? 24 19
? 26 19
? 27 19
? 27 24
! 27 14
? 1 19
? 2 19
? 36 19
? 28 19
? 24 19
? 26 19
? 27 19
? 28 26
! 28 26
? 1 20
? 2 20
? 11 20
? 6 20
? 8 20
? 7 20
? 7 22
! 7 18
? 1 19
? 2 19
? 10 19
? 14 19
? 12 19
? 13 19
? 13 21
! 13 21
? 1 19
? 2 19
? 37 19
? 28 19
? 24 19
? 2...

result:

ok ok (1000 test cases)

Test #10:

score: 0
Accepted
time: 6ms
memory: 2140kb

input:

1000
39
18
17
8
5
6
6
1
1
38
8
9
7
6
3
3
2
1
1
38
19
17
18
16
9
14
14
13
3
1
39
12
11
9
14
13
12
11
1
38
15
16
14
5
3
3
2
1
1
39
4
5
5
1
1
39
18
18
17
10
15
17
16
3
1
38
18
17
8
4
2
1
1
1
39
14
15
15
1
1
39
11
10
7
6
4
5
7
1
39
9
8
9
10
8
7
1
1
38
19
18
18
18
2
1
39
15
16
14
5
5
3
4
5
1
38
12
13
11
...

output:

? 1 20
? 2 20
? 11 20
? 15 20
? 13 20
? 14 20
? 13 25
! 13 25
? 1 20
? 2 20
? 38 20
? 29 20
? 34 20
? 32 20
? 33 20
? 33 21
! 33 21
? 1 20
? 19 38
? 20 38
? 18 38
? 9 38
? 14 38
? 16 38
? 15 38
? 15 12
! 15 26
? 1 20
? 2 20
? 11 20
? 6 20
? 4 20
? 3 20
? 2 30
! 2 10
? 1 20
? 2 20
? 38 20
? 29 20
? 2...

result:

ok ok (1000 test cases)

Test #11:

score: 0
Accepted
time: 0ms
memory: 2160kb

input:

1000
40
12
11
10
7
7
6
1
1
40
18
17
8
5
8
7
1
1
40
15
14
10
15
14
13
1
1
40
8
9
9
13
1
40
16
17
15
6
5
4
3
4
1
1
40
15
16
14
9
10
8
7
8
6
1
41
13
14
14
9
1
40
7
8
6
10
6
4
5
1
1
40
18
19
17
8
3
3
4
1
1
40
6
5
10
5
3
4
5
1
40
4
3
10
7
5
4
5
1
41
12
11
10
11
9
10
1
1
40
17
18
16
9
12
10
9
8
4
1
40
18
...

output:

? 1 21
? 2 21
? 11 21
? 6 21
? 8 21
? 7 21
? 7 26
! 7 26
? 1 21
? 2 21
? 11 21
? 16 21
? 13 21
? 12 21
? 12 27
! 12 27
? 1 21
? 2 21
? 11 21
? 6 21
? 4 21
? 3 21
? 3 33
! 3 33
? 1 21
? 2 21
? 40 21
? 1 28
! 1 14
? 1 21
? 2 21
? 40 21
? 31 21
? 26 21
? 29 21
? 28 21
? 27 21
? 28 23
! 28 23
? 1 21
? 2...

result:

ok ok (1000 test cases)

Test #12:

score: 0
Accepted
time: 7ms
memory: 2268kb

input:

1000
42
11
10
10
7
8
7
6
11
1
41
17
18
16
10
15
14
13
14
1
1
41
8
9
7
10
10
7
6
11
1
41
12
13
11
10
6
8
7
10
1
41
12
11
4
7
5
4
3
1
1
41
18
19
17
10
14
15
14
13
4
1
41
14
15
13
10
15
15
14
1
1
41
20
19
19
18
10
13
11
10
11
3
1
41
17
18
16
10
15
14
13
14
5
1
41
15
16
14
4
5
6
5
1
1
41
18
19
17
10
12
...

output:

? 1 22
? 2 22
? 12 22
? 7 22
? 4 22
? 5 22
? 6 22
? 6 27
! 6 17
? 1 21
? 2 21
? 41 21
? 31 21
? 36 21
? 39 21
? 38 21
? 37 21
? 38 33
! 38 33
? 1 21
? 2 21
? 41 21
? 31 21
? 36 21
? 39 21
? 40 21
? 40 26
! 40 16
? 1 21
? 2 21
? 41 21
? 31 21
? 36 21
? 34 21
? 35 21
? 36 26
! 36 16
? 1 21
? 2 21
? 11...

result:

ok ok (1000 test cases)

Test #13:

score: 0
Accepted
time: 26ms
memory: 2108kb

input:

1000
43
4
3
10
6
3
2
3
1
42
18
17
7
4
5
4
3
5
1
43
6
5
9
4
3
2
3
3
1
43
18
19
17
11
12
10
9
10
5
1
43
21
19
20
18
8
3
3
4
4
1
43
17
18
16
11
13
14
13
12
6
1
43
18
17
10
15
17
16
9
1
43
21
21
20
19
10
15
18
18
7
1
42
13
14
12
10
7
9
8
1
1
42
20
20
19
10
14
12
11
10
1
1
42
5
6
4
10
7
4
3
5
1
43
5
6
6
...

output:

? 1 22
? 2 22
? 12 22
? 7 22
? 4 22
? 3 22
? 3 23
! 3 21
? 1 22
? 2 22
? 12 22
? 17 22
? 14 22
? 15 22
? 16 22
? 16 24
! 16 20
? 1 22
? 2 22
? 12 22
? 7 22
? 4 22
? 5 22
? 6 22
? 5 23
! 5 21
? 1 22
? 2 22
? 43 22
? 33 22
? 38 22
? 36 22
? 35 22
? 34 22
? 35 30
! 35 14
? 1 22
? 21 42
? 22 42
? 20 42
...

result:

ok ok (1000 test cases)

Test #14:

score: 0
Accepted
time: 31ms
memory: 2152kb

input:

1000
44
22
20
21
19
9
4
3
5
3
1
44
11
10
11
9
8
7
8
1
1
43
11
12
10
6
5
3
4
1
1
43
21
18
19
17
11
16
15
16
5
1
44
19
18
11
16
19
19
1
1
44
16
15
11
14
13
12
13
15
1
44
17
18
16
6
5
4
3
4
5
1
44
10
9
7
4
4
3
1
1
43
13
14
12
4
7
5
4
3
5
1
43
4
5
3
11
6
3
2
1
1
44
9
8
8
3
5
4
5
1
44
20
21
21
3
1
44
17
...

output:

? 1 23
? 22 44
? 23 44
? 21 44
? 11 44
? 6 44
? 3 44
? 5 44
? 6 3
! 6 41
? 1 23
? 2 23
? 12 23
? 7 23
? 4 23
? 5 23
? 6 23
? 5 29
! 5 29
? 1 22
? 2 22
? 43 22
? 33 22
? 38 22
? 36 22
? 35 22
? 36 24
! 36 24
? 1 22
? 21 42
? 22 42
? 20 42
? 10 42
? 15 42
? 18 42
? 17 42
? 18 13
! 18 28
? 1 23
? 2 23
...

result:

ok ok (1000 test cases)

Test #15:

score: 0
Accepted
time: 16ms
memory: 2076kb

input:

1000
45
20
21
19
11
17
20
20
4
1
45
16
17
15
11
14
13
12
13
8
1
45
10
9
11
8
7
6
7
11
1
45
15
14
11
11
12
11
10
1
1
45
11
10
11
15
12
11
15
1
45
16
17
15
11
10
9
9
8
8
1
45
19
20
18
7
6
5
4
5
1
1
45
5
6
4
11
5
2
3
3
1
44
19
20
18
11
13
13
12
1
1
45
12
13
13
1
1
44
20
21
19
11
14
12
13
1
1
45
15
14
1...

output:

? 1 23
? 2 23
? 45 23
? 34 23
? 40 23
? 43 23
? 44 23
? 45 41
! 45 5
? 1 23
? 2 23
? 45 23
? 34 23
? 40 23
? 43 23
? 42 23
? 41 23
? 42 34
! 42 12
? 1 23
? 2 23
? 12 23
? 7 23
? 4 23
? 5 23
? 6 23
? 5 28
! 5 18
? 1 23
? 2 23
? 12 23
? 7 23
? 4 23
? 5 23
? 6 23
? 6 32
! 6 32
? 1 23
? 2 23
? 12 23
? 7...

result:

ok ok (1000 test cases)

Test #16:

score: 0
Accepted
time: 0ms
memory: 2112kb

input:

1000
46
18
17
10
12
9
8
9
1
1
46
9
8
11
9
6
7
1
1
46
22
21
11
16
14
16
1
1
46
19
18
11
15
16
15
14
15
1
46
5
6
6
9
1
46
21
20
9
6
9
8
1
1
46
18
17
8
12
9
8
7
1
1
46
16
15
6
10
7
6
5
1
1
46
22
22
21
10
5
2
2
1
1
46
5
4
11
9
6
5
1
1
45
19
20
18
11
13
14
14
1
1
46
14
15
13
11
12
11
10
11
10
1
46
18
19
...

output:

? 1 24
? 2 24
? 13 24
? 7 24
? 10 24
? 11 24
? 12 24
? 11 31
! 11 31
? 1 24
? 2 24
? 13 24
? 7 24
? 4 24
? 5 24
? 4 29
! 4 29
? 1 24
? 2 24
? 13 24
? 7 24
? 10 24
? 8 24
? 7 39
! 7 39
? 1 24
? 2 24
? 13 24
? 7 24
? 4 24
? 5 24
? 6 24
? 6 37
! 6 11
? 1 24
? 2 24
? 46 24
? 1 28
! 1 20
? 1 24
? 2 24
? ...

result:

ok ok (1000 test cases)

Test #17:

score: 0
Accepted
time: 26ms
memory: 2152kb

input:

1000
1000000000
499999999
499999999
499999998
250000000
374999999
312500000
343750000
359375000
367187500
371093750
373046874
372070312
371582032
371826173
371948243
372009278
372039796
372055054
372047425
372043611
372045519
372046473
372046950
372047188
372047307
372047367
372047396
372047381
3720...

output:

? 1 500000001
? 2 500000001
? 1000000000 500000001
? 750000001 500000001
? 875000001 500000001
? 812500001 500000001
? 843750001 500000001
? 859375001 500000001
? 867187501 500000001
? 871093751 500000001
? 873046876 500000001
? 872070314 500000001
? 871582033 500000001
? 871826174 500000001
? 87194...

result:

ok ok (1000 test cases)

Test #18:

score: 0
Accepted
time: 28ms
memory: 2228kb

input:

1000
1000000000
499999969
499999968
249999969
124999969
62500000
93750000
109374969
101562469
97656219
95703125
96679688
97167938
96923798
96801728
96740724
96771211
96755952
96748354
96752138
96750231
96749277
96748831
96749070
96749158
96749099
96749100
96749110
96749102
96749098
96749098
96749097...

output:

? 1 500000001
? 2 500000001
? 250000001 500000001
? 375000001 500000001
? 437500001 500000001
? 406250001 500000001
? 390625001 500000001
? 398437501 500000001
? 402343751 500000001
? 404296876 500000001
? 403320313 500000001
? 402832032 500000001
? 403076172 500000001
? 403198242 500000001
? 403259...

result:

ok ok (1000 test cases)

Test #19:

score: 0
Accepted
time: 18ms
memory: 2164kb

input:

1000
1000000000
474148191
474148190
250000000
349148191
286648191
255398191
239773191
242187501
238281251
237820066
237304688
237331785
237087645
237182617
237121582
237091064
237075805
237080016
237076202
237074295
237074851
237074374
237074135
237074176
237074117
237074105
237074102
237074097
2370...

output:

? 1 500000001
? 2 500000001
? 250000001 500000001
? 125000001 500000001
? 187500001 500000001
? 218750001 500000001
? 234375001 500000001
? 242187501 500000001
? 238281251 500000001
? 236328126 500000001
? 237304688 500000001
? 236816407 500000001
? 237060547 500000001
? 237182617 500000001
? 237121...

result:

ok ok (1000 test cases)

Test #20:

score: 0
Accepted
time: 43ms
memory: 2160kb

input:

1000
1000000000
230485382
230485383
230485381
249999930
124999930
167985382
136735382
121110382
117187430
117204132
115251007
116210867
115722586
115478445
115356375
115295340
115264822
115249563
115243378
115245748
115243841
115242887
115242902
115242664
115242767
115242707
115242677
115242662
1152...

output:

? 1 500000001
? 2 500000001
? 1000000000 500000001
? 750000001 500000001
? 875000001 500000001
? 937500001 500000001
? 906250001 500000001
? 890625001 500000001
? 882812501 500000001
? 886718751 500000001
? 884765626 500000001
? 883789064 500000001
? 884277345 500000001
? 884521486 500000001
? 88464...

result:

ok ok (1000 test cases)

Test #21:

score: 0
Accepted
time: 56ms
memory: 2148kb

input:

1000
1000000000
288090905
288090906
288090904
250000000
329346805
266846805
256840905
251221805
249028405
247315555
247075280
246338992
246586999
246342859
246220789
246277956
246247438
246232179
246224550
246220735
246218882
246219781
246219304
246219066
246218947
246218887
246218857
246218868
2462...

output:

? 1 500000001
? 2 500000001
? 1000000000 500000001
? 750000001 500000001
? 875000001 500000001
? 937500001 500000001
? 968750001 500000001
? 953125001 500000001
? 960937501 500000001
? 957031251 500000001
? 958984376 500000001
? 958007814 500000001
? 958496095 500000001
? 958251955 500000001
? 95812...

result:

ok ok (1000 test cases)

Test #22:

score: 0
Accepted
time: 25ms
memory: 2108kb

input:

1000
999999999
499999998
499999997
249999999
374999998
312499998
281249999
296874998
289062498
285156248
283203123
282226561
281738280
281494139
281372070
281433104
281402587
281387328
281379700
281383514
281381607
281380654
281381131
281381370
281381488
281381430
281381459
281381445
281381453
28138...

output:

? 1 500000000
? 2 500000000
? 250000001 500000000
? 125000001 500000000
? 187500001 500000000
? 218750001 500000000
? 203125001 500000000
? 210937501 500000000
? 214843751 500000000
? 216796876 500000000
? 217773438 500000000
? 218261719 500000000
? 218505860 500000000
? 218627930 500000000
? 218566...

result:

ok ok (1000 test cases)

Test #23:

score: 0
Accepted
time: 33ms
memory: 2136kb

input:

1000
999999999
499999957
499999958
499999956
249999957
125000000
187500000
218749957
203124957
195312457
191406207
189453082
188476520
187988282
188232380
188110353
188171388
188201863
188186604
188178975
188175203
188177068
188176157
188176591
188176353
188176234
188176174
188176144
188176149
18817...

output:

? 1 500000000
? 2 500000000
? 999999999 500000000
? 750000000 500000000
? 625000000 500000000
? 687500000 500000000
? 718750000 500000000
? 703125000 500000000
? 695312500 500000000
? 691406250 500000000
? 689453125 500000000
? 688476563 500000000
? 687988282 500000000
? 688232423 500000000
? 688110...

result:

ok ok (1000 test cases)

Test #24:

score: 0
Accepted
time: 8ms
memory: 2108kb

input:

1000
999999999
324545945
324545944
249999999
199545945
187500001
168295945
171875001
164062501
164389695
162436570
163085938
162597657
162353516
162314500
162292481
162283983
162277222
162276354
162273407
162274447
162273493
162273016
162273168
162273049
162272989
162272987
162272974
162272980
16227...

output:

? 1 500000000
? 2 500000000
? 250000001 500000000
? 125000001 500000000
? 187500001 500000000
? 156250001 500000000
? 171875001 500000000
? 164062501 500000000
? 160156251 500000000
? 162109376 500000000
? 163085938 500000000
? 162597657 500000000
? 162353516 500000000
? 162231446 500000000
? 162292...

result:

ok ok (1000 test cases)

Test #25:

score: 0
Accepted
time: 28ms
memory: 2100kb

input:

1000
999999999
487015083
487015084
487015082
249999935
362015083
299515083
268265083
252640083
244827583
246093685
244140560
243851021
243652278
243606881
243530207
243545846
243515329
243514948
243507700
243511133
243509225
243508271
243507794
243507556
243507581
243507522
243507526
243507511
24350...

output:

? 1 500000000
? 2 500000000
? 999999999 500000000
? 750000000 500000000
? 875000000 500000000
? 812500000 500000000
? 781250000 500000000
? 765625000 500000000
? 757812500 500000000
? 753906250 500000000
? 755859375 500000000
? 756835938 500000000
? 756347657 500000000
? 756591798 500000000
? 756469...

result:

ok ok (1000 test cases)

Test #26:

score: 0
Accepted
time: 27ms
memory: 2148kb

input:

1000
999999999
265285129
265285128
249999999
374264885
311764885
280514885
264889885
257472629
260983635
259030510
258053947
257565666
257321525
257350559
257289524
257291007
257275748
257281895
257278081
257276174
257275220
257275271
257275032
257275101
257275042
257275012
257275017
257275009
25727...

output:

? 1 500000000
? 2 500000000
? 250000001 500000000
? 125000001 500000000
? 62500001 500000000
? 31250001 500000000
? 15625001 500000000
? 7812501 500000000
? 11718751 500000000
? 9765626 500000000
? 8789063 500000000
? 8300782 500000000
? 8056641 500000000
? 7934571 500000000
? 7995606 500000000
? 80...

result:

ok ok (1000 test cases)

Test #27:

score: 0
Accepted
time: 27ms
memory: 2108kb

input:

1000
536870912
261621269
261621270
261621268
127403541
67108864
93849109
77071893
75497472
79691776
78290725
77242149
76717861
76809749
76678677
76652325
76645909
76635941
76637717
76633621
76633893
76632869
76633109
76632853
76632741
76632789
76632757
76632741
76632733
76632737
76632735
76632734
68...

output:

? 1 268435457
? 2 268435457
? 536870912 268435457
? 402653185 268435457
? 335544321 268435457
? 369098753 268435457
? 352321537 268435457
? 343932929 268435457
? 348127233 268435457
? 350224385 268435457
? 351272961 268435457
? 351797249 268435457
? 352059393 268435457
? 351928321 268435457
? 351862...

result:

ok ok (1000 test cases)

Test #28:

score: 0
Accepted
time: 42ms
memory: 2156kb

input:

1000
536870911
244408485
244408486
244408484
134217728
182757403
210854053
194076837
185688229
181493925
180660251
180445349
180135963
180183205
180052133
180070427
180037659
180035749
180029467
180031653
180029605
180028581
180028955
180028699
180028571
180028517
180028539
180028523
180028515
18002...

output:

? 1 268435456
? 2 268435456
? 536870911 268435456
? 402653184 268435456
? 469762048 268435456
? 503316480 268435456
? 486539264 268435456
? 478150656 268435456
? 473956352 268435456
? 471859200 268435456
? 472907776 268435456
? 472383488 268435456
? 472645632 268435456
? 472514560 268435456
? 472449...

result:

ok ok (1000 test cases)

Extra Test:

score: 0
Extra Test Passed