# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
587252 |
2022-07-01T14:22:07 Z |
krit3379 |
Swap (BOI16_swap) |
C++17 |
|
1 ms |
212 KB |
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 200005
int a[N],b[N];
bitset<N> vis;
priority_queue<int,vector<int>,greater<int>> q;
int main(){
int n,i,mi;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i]);
if(n%2==0)a[n+1]=1e9;
for(i=1;i*2<=n;i++){
mi=min({a[i],a[i*2],a[i*2+1]});
if(b[i]||q.empty()||q.top()>mi){
if(mi==a[i])b[i]=a[i],b[i*2]=a[i*2],b[i*2+1]=a[i*2+1];
else if(mi==a[i*2])b[i]=a[i*2],b[i*2]=a[i],b[i*2+1]=a[i*2+1];
else b[i]=a[i*2+1],q.push(a[i]),vis[i*2+1]=true;
}
else{
b[i]=q.top();
q.pop();
q.push(a[i]);
}
}
for(;i<=n;i++){
if(!vis[i])q.push(a[i]);
if(!b[i])b[i]=q.top(),q.pop();
}
for(i=1;i<=n;i++)printf("%d ",b[i]);
return 0;
}
Compilation message
swap.cpp: In function 'int main()':
swap.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
swap.cpp:14:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | for(i=1;i<=n;i++)scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |