#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define sz() size()
#define fr first
#define sc second
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;
const int mod=1e9+7;
const int modp=1999999973;
const int modulo=998244353;
const int nmax=100005;
int t,n,x[nmax],v[nmax],tree[4*nmax],lazy[4*nmax];
bitset<nmax>h;
void build(int l,int r,int nod){
if(l==r){
tree[nod]=lazy[nod]=0;
}
else{
int mid=l+(r-l)/2;
tree[nod]=lazy[nod]=0;
build(l,mid,2*nod);
build(mid+1,r,2*nod+1);
}
return;
}
void push(int l,int r,int nod){
if(lazy[nod]!=0){
tree[nod]+=lazy[nod];
if(l!=r){
lazy[2*nod]+=lazy[nod];
lazy[2*nod+1]+=lazy[nod];
}
lazy[nod]=0;
}
return;
}
void update(int l,int r,int le,int re,int val,int nod){
push(le,re,nod);
if(l>re || r<le) return;
else if(le>=l && re<=r){
lazy[nod]+=val;
push(le,re,nod);
return;
}
else{
int mid=le+(re-le)/2;
update(l,r,le,mid,val,2*nod);
update(l,r,mid+1,re,val,2*nod+1);
tree[nod]=min(tree[2*nod],tree[2*nod+1]);
return;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
srand(chrono::steady_clock::now().time_since_epoch().count());
cin >> t;
while(t--){
int lastelf=0;
build(1,nmax,1);
cin >> n;
for(int i=1;i<=n;i++) cin >> x[i];
for(int i=1;i<=n;i++){
int tz;
cin >> tz;
h[i]=tz;
if(h[i]==0) lastelf=i;
}
for(int i=1;i<=n;i++) {
cin >> v[i];
++v[i];
}
if(lastelf==0){
assert(true==true);
}
int left_max=0,curr=1;
if(h[1]==0) update(v[1],nmax,1,nmax,-1,1);
if(h[1]==1) update(v[1],nmax,1,nmax,1,1);
while(curr<=n && (curr<lastelf || tree[1]<0)){
cout << "-1 ";
++curr;
if(curr<=n){
if(h[curr]==0) update(v[curr],nmax,1,nmax,-1,1);
if(h[curr]==1) update(v[curr],nmax,1,nmax,1,1);
}
}
if(curr<=n){
multiset<int>gifts;
for(int i=curr;i<=n;i++){
bool ok=false;
do{
if(left_max>=(i)) break;
ok=false;
if(h[left_max+1]==1){
update(v[left_max+1],nmax,1,nmax,-1,1);
if(tree[1]>=0){
left_max++;
ok=true;
}
else{
auto it=gifts.lower_bound(v[left_max+1]);
if(it!=gifts.end()){
update(*it,nmax,1,nmax,1,1);
if(tree[1]>=0){
ok=true;
gifts.erase(it);
left_max++;
}
else{
update(*it,nmax,1,nmax,-1,1);
update(v[left_max+1],nmax,1,nmax,1,1);
}
}
else update(v[left_max+1],nmax,1,nmax,1,1);
}
}
else{
left_max++;
gifts.insert(v[left_max]);
ok=true;
}
}while(ok==true);
if(i+1<=n) update(v[i+1],nmax,1,nmax,1,1);
cout << 2LL*x[i] - x[left_max+1] << ' ';
}
}
cout << '\n' << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
4480 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
4480 KB |
Output isn't correct |
3 |
Incorrect |
18 ms |
4736 KB |
Output isn't correct |
4 |
Incorrect |
32 ms |
4992 KB |
Output isn't correct |
5 |
Incorrect |
54 ms |
5368 KB |
Output isn't correct |
6 |
Incorrect |
85 ms |
5752 KB |
Output isn't correct |
7 |
Incorrect |
160 ms |
6392 KB |
Output isn't correct |
8 |
Incorrect |
229 ms |
7032 KB |
Output isn't correct |
9 |
Incorrect |
267 ms |
8568 KB |
Output isn't correct |
10 |
Incorrect |
443 ms |
9248 KB |
Output isn't correct |