QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647664 | #9249. Elimination Series Once More | Mu_Silk# | WA | 2ms | 11904kb | C++20 | 2.4kb | 2024-10-17 15:08:17 | 2024-10-17 15:08:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2000010;
int n,k;
int a[N],pos[N],ans[N],id[N],num;
int cnt[N<<2];
void pushup(int p){
cnt[p]=cnt[p<<1]+cnt[p<<1|1];
}
void build(int p,int l,int r){
if(l==r){
id[l]=p;
return;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
}
void update(int p,int l,int r,int x){
if(l==r){
cnt[p]++;
return;
}
int mid=(l+r)>>1;
if(x<=mid) update(p<<1,l,mid,x);
else update(p<<1|1,mid+1,r,x);
pushup(p);
}
void query(int p,int q,int pos){
num=0;
int l=1,r=n;
int sum=0;
int opt=0;
while(true){
// cerr<<"! "<<p<<" "<<q<<" "<<l<<" "<<r<<"\n";
int fa=q>>1;
int op=fa<<1;
if(op==q) op=fa<<1|1;
int rest=cnt[op];
if(p==fa) rest+=sum;
if(rest){
while(p!=fa){
int mid=(l+r)>>1;
int opp=p<<1;
if(pos<=mid) opp=p<<1|1;
int res=(mid-l+1)-cnt[opp]-sum;
if(rest>=res){
rest-=res;
sum=0;
if(pos<=mid){
p=p<<1;
r=mid;
}else{
p=p<<1|1;
l=mid+1;
}
opt+=res;
}else{
sum+=rest;
rest=0;
opt+=rest;
if(opt>k) return;
num++;
break;
}
}
if(rest) return;
if(opt>k) return;
q=fa;
}else{
q=fa;
num++;
}
if(q==1||p==q) break;
}
}
void solve(){
cin>>n>>k;
n=(1<<n);
for(int i=1;i<=n;i++){
cin>>a[i];
pos[a[i]]=i;
}
build(1,1,n);
for(int i=n;i>=1;i--){
int p=id[pos[i]];
// cerr<<i<<" "<<p<<"\n";
query(1,p,pos[i]);
ans[pos[i]]=num;
update(1,1,n,pos[i]);
// cerr<<i<<"\n";
}
for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
cout<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n=1;
// cin>>n;
while(n--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11844kb
input:
2 1 1 2 3 4
output:
0 1 1 2
result:
ok 4 number(s): "0 1 1 2"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 11904kb
input:
3 5 2 4 7 5 3 8 6 1
output:
0 1 2 2 1 3 2 0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'