結果
問題 | No.2978 Lexicographically Smallest and Largest Subarray |
ユーザー |
|
提出日時 | 2024-12-02 19:40:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 199 ms / 2,000 ms |
コード長 | 861 bytes |
コンパイル時間 | 1,991 ms |
コンパイル使用メモリ | 199,124 KB |
最終ジャッジ日時 | 2025-02-26 10:38:52 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; bool deb = 1; int N,Q; int ask(int l,int r){ cout<<"? "<<l<<" "<<N<<" "<<r<<" "<<N<<endl; int X; cin>>X; return X; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>Q; queue<int> B,S; for(int i=1;i<N;i+=2){ if(ask(i,i+1)){ B.push(i+1); S.push(i); } else{ S.push(i+1); B.push(i); } } while(B.size()>1){ int p=B.front(); B.pop(); int q=B.front(); B.pop(); B.push(ask(p,q)?q:p); } while(S.size()>1){ int p=S.front(); S.pop(); int q=S.front(); S.pop(); S.push(!ask(p,q)?q:p); } cout<<"! "<<S.front()<<" "<<S.front()<<" "<<B.front()<<" "<<N<<"\n"; }