結果
問題 | No.2978 Lexicographically Smallest and Largest Subarray |
ユーザー |
![]() |
提出日時 | 2024-12-02 07:40:18 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 215 ms / 2,000 ms |
コード長 | 953 bytes |
コンパイル時間 | 15,309 ms |
コンパイル使用メモリ | 380,044 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 1499.00 |
最終ジャッジ日時 | 2024-12-02 07:40:48 |
合計ジャッジ時間 | 26,713 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
fn main() { let (n, q) = { let a = read(); (a[0], a[1]) }; assert!(n % 2 == 0 && q >= n / 2 * 3); let query = |x: usize, y: usize| -> usize { assert!(x != y && x.max(y) < n); println!("? {} {n} {} {n}", x + 1, y + 1); read()[0] }; let mut list = vec![vec![]; 2]; for i in (1..n).step_by(2) { let x = query(i - 1, i); list[x].push(i - 1); list[x ^ 1].push(i); } let mut min = list[1][0]; let mut max = list[0][0]; for (a, b) in list[0].iter().zip(list[1].iter()).skip(1) { if query(*a, max) == 0 { max = *a; } if query(min, *b) == 0 { min = *b; } } println!("! {} {} {} {n}", min + 1, min + 1, max + 1); } fn read() -> Vec<usize> { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim().split_whitespace().flat_map(|s| s.parse()).collect() }