Submission #198096

#TimeUsernameProblemLanguageResultExecution timeMemory
198096model_codeSanta Claus (RMI19_santa)C++17
30 / 100
1079 ms2808 KiB
/**
* user:  karagyozov-c76
* fname: Ivo
* lname: Karagyozov
* task:  santa
* score: 30.0
* date:  2019-10-11 07:14:23.928835
*/
#include <bits/stdc++.h>

const int32_t MAX_N = 96068; 

int32_t n, x[MAX_N + 5], h[MAX_N + 5], v[MAX_N + 5];

bool check(int32_t left, int32_t right) {
	for(int32_t i = right + 1; i < n; i++) {
		if(h[i] == 0) {
			return false;
		}
	}

	std::multiset< int32_t > s;
	for(int32_t i = 0; i <= right; i++) {
		if(h[i] == 0) {
			s.insert(v[i]);
		}
		else {
			if(i < left) {
				auto it = s.lower_bound(v[i]);
				if(it != s.end()) {
					s.erase(it);
				}
			}
		}
	}

	for(int32_t i = right; i >= left; i--) {
		if(h[i] == 1) {
			auto it = s.lower_bound(v[i]);
			if(it != s.end()) {
				s.erase(it);
			}
		}
	}

	return s.empty();
}

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

	int32_t t;
	std::cin >> t;

	for(int32_t cs = 1; cs <= t; cs++) {
		std::cin >> n;

		for(int32_t i = 0; i < n; i++) {
			std::cin >> x[i];	
		}
		for(int32_t i = 0; i < n; i++) {
			std::cin >> h[i];
		}
		for(int32_t i = 0; i < n; i++) {
			std::cin >> v[i];
		}

		int32_t last = -1;
		for(int32_t i = 0; i < n; i++) {
			while(last < i && check(last + 1, i)) {
				last++;
			}

			if(last == -1) {
				std::cout << -1 << " ";
			}
			else {
				std::cout << 2 * x[i] - x[last] << " ";
			}
		}

		std::cout << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...