QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#677338#9249. Elimination Series Once MoreH_ZzZ#WA 1ms7960kbC++231.6kb2024-10-26 11:24:562024-10-26 11:24:57

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 11:24:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7960kb
  • [2024-10-26 11:24:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
int __ = 1;
using pii=pair<int,int>;
const int N=2e6+50;
int a[N],pos[N],ans[N];
int n,k,m;
bool check(int mid,int x)
{
    int len=pow(2,x);
    if(len>mid)return 0;
    bool f=0;
    for(int j=1;j<=m;j+=len)
    {
        int cnt=0;
        for(int k=j;k<j+len;k++)
            if(a[k]>mid)cnt++;
        if(cnt<=k)f=1;
    }
    return f;
}
void solve(){
    cin>>n>>k;
    m=pow(2,n);
    for(int i=1;i<=m;i++)
    {
        cin>>a[i];
        pos[a[i]]=i;
    }
    if(k>=1)
    {
        int l=m+1,r;
        for(int i=n;i>=0;i--)
        {
            int last=l-1;
            r=last,l=1;
            while(l<r)
            {
                int mid=(l+r) >> 1;
                if(check(mid,i)) r=mid;
                else l=mid+1;
            }
            for(int j=last;j>=l;j--)
                ans[pos[j]]=i;
            if(l==1)break;
        }
    }else
    {
        // for(int i = 0; i < n; i++)
        // {
        //     int len = 1 << i;
        //     for(int j = len * 2; j <= m; j+= len * 2)
        //     {
        //         if(a[j] > a[j - len]) ans[pos[a[j - len]]] = i;
        //         else ans[pos[a[j]]] = i, swap(a[j],a[j - len] );
        //     }
        // }
        // ans[pos[m]] = n;
    }
    for(int i=1;i<=m;i++)cout<<ans[i]<<" ";cout<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    // freopen("1.in.txt","r",stdin);
    // cin >> __;
    while (__--){
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7916kb

input:

2 1
1 2 3 4

output:

0 1 1 2 

result:

ok 4 number(s): "0 1 1 2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7916kb

input:

3 5
2 4 7 5 3 8 6 1

output:

1 2 2 2 1 3 2 0 

result:

ok 8 numbers

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 7960kb

input:

3 0
1 2 7 4 5 8 3 6

output:

0 0 0 0 0 0 0 0 

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'