結果
| 問題 |
No.2740 Old Maid
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2024-04-21 00:23:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,613 bytes |
| コンパイル時間 | 4,850 ms |
| コンパイル使用メモリ | 267,852 KB |
| 最終ジャッジ日時 | 2025-02-21 07:34:44 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 2 WA * 60 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
int op(int a,int b){
return min(a, b);
}
int e(){
return 998244353;
}
int main(){
int n; cin >> n;
vector<int> p(n), q(n);
rep(i,0,n){
cin >> p[i];
p[i]--;
q[p[i]] = i;
}
segtree<int,op,e> seg1(n / 2);
segtree<int,op,e> seg2(n / 2);
rep(i,0,n){
if (i % 2 == 0){
seg1.set(i / 2, p[i]);
}else{
seg2.set(i / 2, p[i]);
}
}
map<int, pair<int,int>> kukan;
map<pair<int,int>, int> kug;
int cnt = 0;
priority_queue<pair<pair<int,int>, int>> pq;
auto calc = [&](pair<int,int> t) -> pair<int,int> {
if (t.first % 2 == 0){
int x = seg1.prod(t.first / 2, t.second / 2);
int y = seg2.prod(q[x] / 2, t.second / 2);
return pair(x, y);
}else{
int x = seg2.prod(t.first / 2, t.second / 2);
int y = seg1.prod(q[x] / 2 + 1, t.second / 2 + 1);
return pair(x, y);
}
};
auto hant = [&](pair<int,int> a) -> pair<int,int> {
return pair(-a.first, -a.second);
};
auto pqpush = [&](pair<int,int> t) -> void {
kukan[cnt] = t;
kug[t] = cnt;
pq.push(pair(hant(calc(t)), cnt));
cnt++;
};
pqpush(pair(0, n));
vector<int> ans;
while(!pq.empty()){
auto k = pq.top();
pair<int,int> tmp = hant(k.first);
pq.pop();
ans.push_back(tmp.first);
ans.push_back(tmp.second);
pair<int,int> h = kukan[k.second];
int a = q[tmp.first];
int b = q[tmp.second];
if (h.first < a){
pqpush(pair(h.first, a));
}
if (b + 1 < h.second){
pqpush(pair(b + 1, h.second));
}
if (a + 1 < b){
pqpush(pair(a + 1, b));
}
}
rep(i,0,n){
cout << ans[i] + 1;
if (i == n-1) cout << '\n';
else cout << ' ' ;
}
}
shobonvip