結果

問題 No.2978 Lexicographically Smallest and Largest Subarray
ユーザー chestnut_68
提出日時 2024-12-14 11:04:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 174,300 KB
実行使用メモリ 25,476 KB
平均クエリ数 1499.00
最終ジャッジ日時 2024-12-14 11:05:01
合計ジャッジ時間 16,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,Q;cin>>N>>Q;
	queue<int> mq,Mq;
	for(int i=1;i<=N;i+=2){
		cout<<"? "<<i<<" "<<N<<" "<<i+1<<" "<<N<<endl;
		int f;
		cin>>f;
		if(f==-1)return 0;
		if(f){
			Mq.push(i+1);
			mq.push(i);
		}
		else{
			Mq.push(i);
			mq.push(i+1);
		}
	}
	
	while(Mq.size()>1){
		queue<int> tmq,tMq;
		
		while(Mq.size()>1){
			auto a=Mq.front();
			Mq.pop();
			auto b=Mq.front();
			Mq.pop();
			cout<<"? "<<a<<" "<<N<<" "<<b<<" "<<N<<endl;
			int f;
			if(f==-1)return 0;
			cin>>f;
			if(f){
				tMq.push(b);
			}
			else{
				tMq.push(a);
			}
		}
		while(tMq.size()){
			Mq.push(tMq.front());
			tMq.pop();
		}
		while(mq.size()>1){
			auto a=mq.front();
			mq.pop();
			auto b=mq.front();
			mq.pop();
			cout<<"? "<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
			int f;
			cin>>f;
			if(f==-1)return 0;
			if(f){
				tmq.push(a);
			}
			else{
				tmq.push(b);
			}
		}
		while(tmq.size()){
			mq.push(tmq.front());
			tmq.pop();
		}
	}
	cout<<"! "<<mq.front()<<" "<<mq.front()<<" "<<Mq.front()<<" "<<N<<endl;
}
0