이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
unsigned n, t, prv;
struct Seg{
int tree[1u << 19u]{};
const unsigned sz = 1u << 18u;
void insert(unsigned x){
x |= sz; tree[x]++;
while(x >>= 1u) tree[x]++;
}
void erase(unsigned x){
x |= sz; tree[x]--;
while(x >>= 1u) tree[x]--;
}
int count(unsigned x){ return tree[x | sz]; }
unsigned begin(){
unsigned x = 1;
while(x < sz){
if(tree[x << 1u]) x <<= 1u;
else x = x << 1u | 1u;
}
return x - sz;
}
unsigned rbegin(){
unsigned x = 1;
while(x < sz){
if(tree[x << 1u | 1u]) x = x << 1u | 1u;
else x <<= 1u;
}
return x - sz;
}
}st;
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> t;
for(unsigned i=1; i<n+n; i++) if(i ^ t) st.insert(i);
cout << t << " "; prv = t;
for(unsigned i=1; i<n; i++){
cin >> t;
if(st.count(t)){
cout << t << " "; st.erase(t);
unsigned v = t < prv ? st.begin() : st.rbegin();
cout << v << " "; st.erase(v); prv = t; continue;
}
unsigned v = t <= prv ? st.begin() : st.rbegin();
cout << v << " "; st.erase(v);
v = t < prv ? st.begin() : st.rbegin();
cout << v << " "; st.erase(v);
prv = t;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |