跳到正文

个人记录

11

dengshenghao约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年8月10日
收录
2026年8月10日
更新
2026年8月10日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+7;
int n,a[N],s[N];
int lowbit(int x){
	return x&-x; 
}
void change(int x,int z){
	while(x<=n){
		s[x]+=z;
		x+=lowbit(x);
	}
}
int get(int x){
	int res=0,sum=0,ans=1e18;
	for(int i=22;i>=0;i--){
		if(sum+(1ll<<i)>n) continue;
		if(res+s[sum+(1ll<<i)]>x) continue;
		if(res+s[sum+(1ll<<i)]==x){
			ans=min(ans,sum+(1ll<<i));
			continue;
		}
		res+=s[sum+(1ll<<i)];
		sum+=(1ll<<i);
	}
	return ans;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		change(i,1);
	}
	int cnt=0;
	while(cnt<n){
		vector<int>v;
		for(int i=1;i*i*i<=n-cnt;i++){
			int p=i*i*i;
			v.push_back(get(p));
		}
		for(auto now:v){
			cnt++; 
			cout<<a[now]<<' ';
			change(now,-1); 
		}cout<<'\n';
	}
	return 0;
}
原文