#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n;
struct node{
int x, h, v;
} a[500009];
int used[500009];
int ans[500009];
void solve(){
cin >> n;
int latest = 0;
for(int i = 0; i < n; ++i)
cin >> a[i].x;
for(int i = 0; i < n; ++i){
cin >> a[i].h;
if(a[i].h == 0) latest = i;
}
for(int i = 0; i < n; ++i){
cin >> a[i].v;
used[i] = -1;
}
multiset<int> pr;
for(int i = 0; i <= latest; ++i){
if(i != latest) ans[i] = -1;
if(a[i].h == 0)
pr.insert(a[i].v);
else{
if(pr.lower_bound(a[i].v) != pr.end()){
a[i].h = 0;
pr.erase(pr.lower_bound(a[i].v));
}
}
}
int j = 1e9;
multiset<pii, greater<pii>> kids;
for(int i = latest; i < n; ++i){
if(j == 1e9){
for(j = i; j >= 0; --j){
if(a[j].h)
if(pr.lower_bound(a[j].v) != pr.end()){
used[j] = *pr.lower_bound(a[j].v);
pr.erase(pr.lower_bound(a[j].v));
}
if(pr.empty())
break;
}
}
if(j < 0) j = 0;
if(a[i].h){
kids.insert({a[i].v, i});
}
while(pr.size()){
int cur = *pr.begin();
if(kids.lower_bound(mp(cur, (int)1e9)) != kids.end()){
kids.erase(kids.lower_bound(mp(cur, (int)1e9)));
pr.erase(pr.begin());
}
else
break;
}
if(pr.size()){
ans[i] = -1;
continue;
}
while(j < i){
if(used[j] < 0){
++j;
continue;
}
int cur = used[j];
if(kids.lower_bound(mp(cur, (int)1e9)) != kids.end()){
kids.erase(kids.lower_bound(mp(cur, (int)1e9)));
++j;
}
else
break;
}
ans[i] = 2*a[i].x-a[j].x;
}
for(int i = n-1; i >= 1; --i)
if(a[i].x == a[i-1].x)
ans[i-1] = ans[i];
for(int i = 0; i < n; ++i)
cout << ans[i] << ' ';
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
int t;
cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
4 |
Incorrect |
13 ms |
640 KB |
Output isn't correct |
5 |
Incorrect |
27 ms |
892 KB |
Output isn't correct |
6 |
Incorrect |
46 ms |
1400 KB |
Output isn't correct |
7 |
Incorrect |
82 ms |
2168 KB |
Output isn't correct |
8 |
Incorrect |
136 ms |
3064 KB |
Output isn't correct |
9 |
Incorrect |
165 ms |
5496 KB |
Output isn't correct |
10 |
Incorrect |
247 ms |
6256 KB |
Output isn't correct |