Submission #274191

# Submission time Handle Problem Language Result Execution time Memory
274191 2020-08-19T09:37:17 Z egekabas Santa Claus (RMI19_santa) C++14
10 / 100
297 ms 5880 KB
#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];
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) cout << "-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()){
            cout << "-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;
        }
        cout << 2*a[i].x-a[j].x << ' ';
    }
    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 12 ms 640 KB Output isn't correct
5 Incorrect 26 ms 888 KB Output isn't correct
6 Incorrect 45 ms 1272 KB Output isn't correct
7 Incorrect 82 ms 2040 KB Output isn't correct
8 Incorrect 138 ms 3156 KB Output isn't correct
9 Incorrect 166 ms 4984 KB Output isn't correct
10 Incorrect 297 ms 5880 KB Output isn't correct