結果

問題 No.3086 Re One Two
ユーザー kotatsugame
提出日時 2025-04-04 21:28:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 69,956 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2025-04-04 21:29:51
合計ジャッジ時間 5,807 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int N,A[2<<17],B[2<<17];
int pr[2<<17],ch[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	vector<int>B1;
	for(int i=0;i<N;i++)
	{
		cin>>A[i]>>B[i],pr[i]=ch[i]=-1;
		if(B[i]==1)B1.push_back(i);
	}
	for(int i=0;i<N;i++)
	{
		if(A[i]==1)
		{
			assert(ch[i+1]==-1);
			pr[i]=i+1;
			ch[i+1]=i;
		}
		if(B[i]==2)
		{
			int j=lower_bound(B1.begin(),B1.end(),i)-B1.begin();
			assert(j<B1.size());
			j=B1[j];
			assert(i<j);
			assert(ch[j]==-1);
			pr[i]=j;
			ch[j]=i;
		}
	}
	for(int i=0;i<N;i++)if(pr[i]==-1)
	{
		int u=i;
		while(u!=-1)
		{
			cout<<u+1<<"\n";
			u=ch[u];
		}
	}
}
0