#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=1e6+99;
int n,t,a[N];
vector<int> g[N];
int main(){
cin>>n;
f(i,1,n+1){
cin>>a[i];
}
f(i,1,n+1){
pair<int,int> mn=mp(a[i],-1);
if(i*2<=n) g[i].pb(i*2);
if(i*2+1<=n) g[i].pb(i*2+1);
f(j,0,g[i].size()){
minm(mn,mp(a[g[i][j]],j));
}
if(mn.S==-1) continue;
swap(a[i],a[g[i][mn.S]]);
f(j,0,mn.S){
int u=g[i][j],v=g[i][mn.S];
g[min(u,v)].pb(max(u,v));
}
}
f(i,1,n+1){
cout<<a[i]<<" ";
}
}
Compilation message
swap.cpp: In function 'int main()':
swap.cpp:7:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define f(i,a,b) for(int i=a;i<b;i++)
......
34 | f(j,0,g[i].size()){
| ~~~~~~~~~~~~~~~
swap.cpp:34:3: note: in expansion of macro 'f'
34 | f(j,0,g[i].size()){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23784 KB |
Output is correct |
2 |
Correct |
10 ms |
23756 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23776 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23784 KB |
Output is correct |
2 |
Correct |
10 ms |
23756 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23776 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23784 KB |
Output is correct |
2 |
Correct |
10 ms |
23756 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23776 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23784 KB |
Output is correct |
2 |
Correct |
10 ms |
23756 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23776 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23784 KB |
Output is correct |
2 |
Correct |
10 ms |
23756 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23776 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |