제출 #274191

#제출 시각아이디문제언어결과실행 시간메모리
274191egekabasSanta Claus (RMI19_santa)C++14
10 / 100
297 ms5880 KiB
#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 timeMemoryGrader output
Fetching results...