# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
735900 |
2023-05-05T01:42:02 Z |
baokhue232005 |
Swap (BOI16_swap) |
C++14 |
|
14 ms |
28628 KB |
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option
#include<bits/stdc++.h>
using namespace std;
#define all(flg) flg.begin(), flg.end()
#define pb push_back
#define fi first
#define se second
#define eb emplace_back
#define ii pair<int, int>
#define vi vector<int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define ld long double
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const int mod = 1e9 + 7;
const int maxN = 1e6 + 5;
int n, a[maxN];
int x, y, z, k;
int cnt = n;
vi vc[maxN];
bool used[maxN];
int calc(int node, int dep = 0){
if(dep > 100) exit(0);
if(node <= n){
if(used[node]) return mod;
else return node;
}
int res = mod;
for(int cc : vc[node]){
int val = calc(cc, dep + 1);
res = min(res, val);
}
return res;
}
int cutt(int node, int vl){
if(node <= n){
if(node == vl) used[node] = 1;
return node;
}
int res = mod;
for1(i, 0, (int)vc[node].size() - 1){
int cc = vc[node][i];
int val = calc(cc, vl);
res = min(res, val);
if(res == vl){
vc[node].erase(vc[node].begin() + i);
return vl;
}
}
return res;
}
int ans[maxN];
void asn(int plc){
int vl = calc(a[plc]);
ans[plc] = vl;
cutt(a[plc], vl);
}
signed main(){
// freopen(".inp", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
memset(used, 0, sizeof(used));
memset(a, 0, sizeof(a));
for1(i, 1, n) cin >> a[i];
cnt = n;
used[0] = 1;
for1(i, 1, n){
int vl = calc(a[i]);
int left = i * 2;
int right = i * 2 + 1;
int semi = min(calc(a[right]), calc(a[left]));
if(semi >= vl){
asn(i);
continue;
}
if(calc(a[left]) < calc(a[right])){
swap(a[i], a[left]);
asn(i);
continue;
}
int node = ++cnt;
vc[node].pb(a[left]);
vc[node].pb(a[i]);
ans[i] = a[right];
used[a[right]] = 1;
a[left] = node;
a[right] = node;
}
for1(i, 1, n) cout << ans[i] << " ";
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
28628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
28628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
28628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
28628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
28628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |