# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
201439 |
2020-02-10T14:54:39 Z |
red1108 |
Swap (BOI16_swap) |
C++17 |
|
5 ms |
376 KB |
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;typedef long double ld;typedef unsigned long long ul;typedef unsigned int ui;typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 2e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cout << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cout << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cout << endl;}
int in[200010],n;
int f(int x, int v){
if(x>n/2) return x;
if(v<in[x*2]&&v<in[x*2+1]) return x;
if(in[x*2]<v&&v<in[x*2+1]) return f(x*2,v);
int y = min(v, in[x*2]);
int a = f(x*2+1,y), b = f(x*2,y);
if(in[x*2]<v) return max(a,b);
return min(a,b);
}
int main(){
fastio;
cin>>n;
for(int i=1;i<=n;i++) cin>>in[i];
in[n+1]=n+1;
for(int i=1;i<=n/2;i++){
if(in[i]<in[i*2]&&in[i]<in[i*2+1]) continue;
if(in[i*2]<in[i]&&in[i*2]<in[i*2+1]){swap(in[i],in[i*2]);continue;}
int x = min(in[i],in[i*2]),y=max(in[i],in[i*2]),z=in[i*2+1];
int a = f(i*2+1,x), b = f(i*2,x);
if(a<b){in[i*2]=y;in[i*2+1]=x;}
else {in[i*2]=x;in[i*2+1]=y;}
in[i]=z;
}
for(int i=1;i<=n;i++) cout<<in[i]<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |