Submission #274332

#TimeUsernameProblemLanguageResultExecution timeMemory
274332Atill83Santa Claus (RMI19_santa)C++14
20 / 100
1094 ms2936 KiB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;

int x[MAXN], h[MAXN], v[MAXN];

bool check(int m, int i){
    multiset<int> st;


    for(int j = i; j >= m; j--){
        if(h[j]){
            st.insert(v[j]);
        }
    }
    for(int j = i; j > 0; j--){
        if(h[j] == 0){
            auto u = st.upper_bound(v[j]);

            if(u == st.begin()) return 0;
            st.erase(prev(u));
        }else if(j < m){
            st.insert(v[j]);
        }
    }
    return 1;

}

void solve(){
    set<int> elv;
    cin>>n;
    for(int i = 1; i <= n; i++){
        cin>>x[i];
    }
    int lst = 0;
    for(int i = 1; i <= n; i++){
        cin>>h[i];
        if(!h[i]) 
            lst = i;
    }
    
    for(int i = 1; i <= n; i++)
        cin>>v[i];

    for(int i = 1; i <= n; i++){

        if(i < lst){
            cout<<"-1 ";
        }else{
            bool tru = 1;
            int l = 1, r = i;
            while(l < r){
                int m = (l + r + 1) / 2;
                if(check(m, i)){
                    l = m;
                }else
                {
                    r = m - 1;
                }
            
            }
            if(!check(l, i)){
                cout<<"-1 ";
            }else{
                cout<<2*x[i] - x[l]<<" ";
            }
        }
    }
    cout<<endl;
}







int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    int t;
    cin>>t;

    while(t--) solve();
    

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message (stderr)

santa.cpp: In function 'void solve()':
santa.cpp:62:18: warning: unused variable 'tru' [-Wunused-variable]
   62 |             bool tru = 1;
      |                  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...