QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#677334 | #9249. Elimination Series Once More | H_ZzZ# | WA | 1ms | 8052kb | C++23 | 1.6kb | 2024-10-26 11:23:39 | 2024-10-26 11:23:39 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7852kb
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: 7952kb
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: 0
Accepted
time: 1ms
memory: 7960kb
input:
3 0 1 2 7 4 5 8 3 6
output:
0 1 2 0 0 3 0 1
result:
ok 8 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 7904kb
input:
3 5 3 7 1 2 4 8 5 6
output:
1 2 0 1 2 3 2 2
result:
ok 8 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 8008kb
input:
3 3 3 4 8 2 7 6 1 5
output:
1 2 3 1 2 2 0 2
result:
ok 8 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 7912kb
input:
3 3 4 2 6 8 3 5 1 7
output:
2 1 2 3 1 2 0 2
result:
ok 8 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 8052kb
input:
3 4 5 8 1 3 2 4 6 7
output:
2 3 0 1 1 2 2 2
result:
ok 8 numbers
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 7952kb
input:
3 1 7 3 8 6 5 2 4 1
output:
2 1 3 2 2 1 2 0
result:
wrong answer 4th numbers differ - expected: '1', found: '2'