結果

問題 No.1888 Odd Insertion
ユーザー 沙耶花沙耶花
提出日時 2022-03-25 22:09:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 1,400 bytes
コンパイル時間 4,235 ms
コンパイル使用メモリ 260,400 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2024-04-22 06:50:01
合計ジャッジ時間 20,580 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 123 ms
14,336 KB
testcase_07 AC 113 ms
14,336 KB
testcase_08 AC 395 ms
14,336 KB
testcase_09 AC 394 ms
14,336 KB
testcase_10 AC 394 ms
14,336 KB
testcase_11 AC 394 ms
14,336 KB
testcase_12 AC 441 ms
14,464 KB
testcase_13 AC 401 ms
14,208 KB
testcase_14 AC 411 ms
14,336 KB
testcase_15 AC 406 ms
14,208 KB
testcase_16 AC 149 ms
14,336 KB
testcase_17 AC 403 ms
14,208 KB
testcase_18 AC 139 ms
14,336 KB
testcase_19 AC 146 ms
14,336 KB
testcase_20 AC 146 ms
14,336 KB
testcase_21 AC 146 ms
14,208 KB
testcase_22 AC 145 ms
14,208 KB
testcase_23 AC 145 ms
14,336 KB
testcase_24 AC 145 ms
14,208 KB
testcase_25 AC 149 ms
14,336 KB
testcase_26 AC 382 ms
14,336 KB
testcase_27 AC 378 ms
14,336 KB
testcase_28 AC 377 ms
14,208 KB
testcase_29 AC 131 ms
14,208 KB
testcase_30 AC 129 ms
14,208 KB
testcase_31 AC 131 ms
14,208 KB
testcase_32 AC 402 ms
14,208 KB
testcase_33 AC 382 ms
14,336 KB
testcase_34 AC 377 ms
14,336 KB
testcase_35 AC 372 ms
14,208 KB
testcase_36 AC 369 ms
14,208 KB
testcase_37 AC 371 ms
14,208 KB
testcase_38 AC 370 ms
14,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001
using P = pair<int,int>;
P op(P a,P b){
	pair<int,int> r;
	r.first = max({a.first,b.first});
	r.second = r.first;
	if(a.first==r.second){
		r.second = max(a.second,b.first);
	}
	else{
		r.second = max(a.first,b.second);
	}
	return r;
}

P e(){
	return make_pair(0,0);
}


int main(){
	
	int n;
	cin>>n;
	vector<int> pos(n+2,0);
	fenwick_tree<int> F(n);
	set<int> S;
	rep(i,n){
		int pp;
		cin>>pp;
		//cin>>PP[i].first;
		S.insert(i+1);
		//PP[i].second = 0;
		pos[pp] = i;
		//F.add(i,1);
	}
	S.insert(n+1);
	vector<int> a,b;
	rep(i,n){
		auto it=  S.begin();
		int r0 = *it;
		it++;
		int r1 = *it;
		
		int p0 = pos[r0];
		int p1=  pos[r1];
		if(p0>p1){
			swap(p0,p1);
			swap(r0,r1);
		}
		int v0 = F.sum(0,p0);
		int v1 = F.sum(0,p1);
		//cout<<r0<<','<<r1<<','<<v0<<','<<v1<<endl;
		if(v1%2==0&&r1!=n+1){
			F.add(p1,1);
			a.push_back(r1);
			b.push_back(v1+1);
			S.erase(r1);
		}
		else if(v0%2==0&&r0!=n+1){
			F.add(p0,1);
			a.push_back(r0);
			b.push_back(v0+1);
			S.erase(r0);
		}
		else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	//reverse(a.begin(),a.end());
	//reverse(b.begin(),b.end());
	
	cout<<"Yes"<<endl;
	rep(i,a.size()){
		cout<<a[i]<<' '<<b[i]<<endl;
	}
	return 0;
}
0