답안 #258580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258580 2020-08-06T07:29:07 Z 최은수(#5046) Swap (BOI16_swap) C++17
0 / 100
1 ms 404 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int v[400010],ans[200010];
int type[200010]; // 1 left 2 right
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=0;i++<n;)
        cin>>v[i];
    for(int i=n;i++<n*2+1;)
        v[i]=n+1;
    for(int i=0;i++<n;)
    {
        int j=i*2;
        int k=i*2+1;
        vector<int>vv;
        for(int p=i;p>1;p/=2)
        {
            if(type[p/2]==0);
            else if(type[p/2]==1&&p%2==0);
            else if(type[p/2]==2&&p%2==1);
            else if(type[p/2]==4);
            else
                break;
            vv.eb(p);
        }
        reverse(all(vv));
        int mn=!vv.empty()?v[vv[0]/2]:v[i];
        for(int&p:vv)
        {
            if(type[p/2]==0)
            {
                if(p%2==0)
                    mn=min(mn,v[p]);
                else
                    mn=min(mn,v[p^1]);
            }
            else if(type[p/2]==1);
            else if(type[p/2]==2);
            else if(p%2==0);
            else
                mn=v[p^1];
        }
        ans[i]=min({mn,v[j],v[k]});
        if(ans[i]==mn)
        {
            int mn2=!vv.empty()?v[vv[0]/2]:v[i];
            for(int&p:vv)
            {
                if(type[p/2]==0)
                {
                    if(p%2==0)
                    {
                        if(mn2==mn||v[p]==mn)
                            type[p/2]=mn2==mn?4:2;
                        mn2=min(mn2,v[p]);
                    }
                    else
                    {
                        if(mn2==mn||v[p^1]==mn)
                            type[p/2]=mn2==mn?2:4;
                        mn2=min(mn,v[p^1]);
                    }
                }
                else if(type[p/2]==1);
                else if(type[p/2]==2);
                else if(p%2==0);
                else
                    mn2=v[p^1];
            }
            type[i]=3;
        }
        else if(ans[i]==v[j])
            type[i]=1;
        else
            type[i]=0;
        cout<<ans[i]<<' ';
    }
    cout<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -