結果
| 問題 |
No.1888 Odd Insertion
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-03-25 22:01:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,380 bytes |
| コンパイル時間 | 5,072 ms |
| コンパイル使用メモリ | 256,308 KB |
| 最終ジャッジ日時 | 2025-01-28 12:06:46 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 WA * 17 |
ソースコード
#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<pair<int,int>> PP(n);
vector<int> pos(n+1,0);
fenwick_tree<int> F(n);
rep(i,n){
cin>>PP[i].first;
PP[i].second = 0;
pos[PP[i].first] = i;
F.add(i,1);
}
segtree<P,op,e> seg(PP);
vector<int> a,b;
rep(i,n){
auto ret= seg.all_prod();
int p0 = pos[ret.first];
int p1= pos[ret.second];
if(p0>p1){
swap(p0,p1);
swap(ret.first,ret.second);
}
int v0 = F.sum(0,p0);
int v1 = F.sum(0,p1);
if(v1%2==0&&ret.second!=0){
F.add(p1,-1);
a.push_back(ret.second);
b.push_back(v1+1);
seg.set(p1,make_pair(0,0));
}
else if(v0%2==0){
F.add(p0,-1);
a.push_back(ret.first);
b.push_back(v0+1);
seg.set(p0,make_pair(0,0));
}
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;
}
沙耶花