結果

問題 No.2771 Personal Space
ユーザー kotatsugame
提出日時 2024-05-31 22:04:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 83,764 KB
実行使用メモリ 21,096 KB
最終ジャッジ日時 2024-12-20 23:33:53
合計ジャッジ時間 7,130 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<queue>
#include<cassert>
using namespace std;
int C[3<<17];
int P[3<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		int N,M;cin>>N>>M;
		C[0]=M;
		set<int>S;
		priority_queue<pair<int,int> >Q;
		auto add=[&](int u){
			S.insert(u);
			auto it=S.upper_bound(u);
			if(it==S.end())
			{
				if(u+1<=N)Q.push(make_pair(N-u,-N));
			}
			else
			{
				int r=*it;
				if(u+1<r)
				{
					int mid=(u+r)/2;
					Q.push(make_pair(min(mid-u,r-mid),-mid));
				}
			}
			it--;
			if(it==S.begin())
			{
				if(u>=2)Q.push(make_pair(u-1,-1));
			}
			else
			{
				it--;
				int l=*it;
				if(l+1<u)
				{
					int mid=(l+u)/2;
					Q.push(make_pair(min(mid-l,u-mid),-mid));
				}
			}
		};
		add(M);
		for(int i=1;i<N;i++)
		{
			assert(!Q.empty());
			int id=-Q.top().second;
			Q.pop();
			C[i]=id;
			add(id);
		}
		for(int i=0;i<N;i++)P[C[i]-1]=i+1;
		for(int i=0;i<N;i++)cout<<P[i]<<(i+1==N?"\n":" ");
	}
}
0