제출 #331727

#제출 시각아이디문제언어결과실행 시간메모리
331727Sho10Santa Claus (RMI19_santa)C++14
30 / 100
1094 ms5612 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,ans[100005];
struct house{
    ll pos,h,val;
};
house a[100005];
ll check(ll l,ll r){
for(ll i=r+1;i<=n;i++)
{
    if(a[i].h==0){
        return 0;
    }
}
multiset<ll>s;
for(ll i=1;i<=r;i++)
{
    if(a[i].h==0){
        s.insert(a[i].val);
    }else {
    if(i<l){
        auto it=s.lower_bound(a[i].val);
        if(it!=s.end()){
            s.erase(it);
        }
    }
}
}
for(ll i=r;i>=l;i--)
{
    if(a[i].h==1){
        auto it=s.lower_bound(a[i].val);
        if(it!=s.end()){
            s.erase(it);
        }
    }
}
return 1-(s.size()!=0);
}
int32_t main(){
CODE_START;
cin>>t;
while(t--){
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].pos;
    }
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].h;
    }
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].val;
    }
  ll last=0;
  for(ll i=1;i<=n;i++)
  {
      while(last<i&&check(last+1,i)){
        last++;
      }
      if(last==0){
        cout<<"-1"<<' ';
      }else {
      cout<<2*a[i].pos-a[last].pos<<' ';
      }

  }
  cout<<endl;
}
}
#Verdict Execution timeMemoryGrader output
Fetching results...