#include <bits/stdc++.h>
#define maxn 1000005
using namespace std;
int n,k;
int a[maxn];
vector<int>sol;
int s[maxn];
bool bio[maxn];
void precalc()
{
s[0]=0;
for(int i=1;i<=n;i++)s[i]=s[i-1]+(1<<a[i]);
}
void solve(int l,int r,int x)
{
if(l>r)
{
sol.push_back(x);
bio[sol.size()-1]=false;
return;
}
if(l==r)
{
int is=1<<x;
sol.push_back(a[l]);
bio[sol.size()-1]=true;
is-=1<<a[l];
int br=0;
while(is>0)
{
if(is%2)
{
sol.push_back(br);
bio[sol.size()-1]=false;
}
br++;
is/=2;
}
return;
}
int left=l;
int right=r;
int br=1<<(x-1);
int t=l;
while(left<=right)
{
int mid=(left+right)/2;
if(s[mid]-s[l-1]>br)right=mid-1;
else {
t=mid;
left=mid+1;
}
}
solve(l,t,x-1);
solve(t+1,r,x-1);
}
int najv2(int x)
{
int l=0;
int r=30;
int sss=0;
while(l<=r)
{
int mid=(l+r)/2;
int br=(1<<mid)-1;
if(br>x)r=mid-1;
else{
sss=mid;
l=mid+1;
}
}
return sss;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
precalc();
solve(1,n,30);
int sz=sol.size();
int d=n+k-sz;
for(int i=0;i<sz;i++)cout<<sol[i]<<" ";
/*for(int i=0;i<sz;i++)
{
if(d==0 || bio[i])cout<<sol[i]<<" ";
else{
int mmm=najv2(d);
int minn=min(mmm,sol[i]);
for(int j=1;j<=(1<<minn);j++)cout<<sol[i]-minn<<" ";
d-=1<<minn;
d++;
}
}*/
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:94:9: warning: unused variable 'd' [-Wunused-variable]
int d=n+k-sz;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
15200 KB |
Output is correct |
2 |
Correct |
245 ms |
15324 KB |
Output is correct |
3 |
Correct |
230 ms |
15544 KB |
Output is correct |
4 |
Correct |
279 ms |
15544 KB |
Output is correct |
5 |
Correct |
266 ms |
15628 KB |
Output is correct |
6 |
Correct |
220 ms |
15628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
191 ms |
15628 KB |
Expected EOF |
2 |
Incorrect |
242 ms |
15872 KB |
Expected EOF |
3 |
Incorrect |
288 ms |
15872 KB |
Expected EOF |
4 |
Incorrect |
258 ms |
15872 KB |
Expected EOF |
5 |
Incorrect |
264 ms |
15872 KB |
Expected EOF |
6 |
Incorrect |
219 ms |
15872 KB |
Expected EOF |
7 |
Incorrect |
229 ms |
15872 KB |
Expected EOF |
8 |
Incorrect |
250 ms |
15872 KB |
Expected EOF |
9 |
Incorrect |
249 ms |
16516 KB |
Expected EOF |
10 |
Incorrect |
114 ms |
16516 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
156 ms |
16516 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
3 ms |
16516 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
3 ms |
16516 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
3 ms |
16516 KB |
Unexpected end of file - int32 expected |