제출 #1366958

#제출 시각아이디문제언어결과실행 시간메모리
1366958digitaldreamerPizza Party (CCO24_day1problem2)C++20
0 / 12
1715 ms114072 KiB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mid (l + ((r - l) / 2))
#define F first
#define S second

void solve()
{
	int64_t n, m, x, y, z, p = 1 ;
	cin >> n ;
	vector<int64_t> a(n), b(n) ;
	for(auto &it : a) cin >> it ;
	for(auto &it : b) cin >> it ;
	vector<int64_t> c = a, d = b ;
	sort(c.begin() , c.end()), sort(d.begin() , d.end()) ;
	if(c != d) 
	{
		cout << -1 << endl;
	    return ;
	}
	
	vector<int64_t> v1(n), v2(n) ;
	map<int64_t , int64_t> id ;
	for(int64_t i = 0 ; i < n ; i++) id[b[i]] = i ;
	multiset<pair<int64_t , int64_t>> st ;
	for(int64_t i = 0 ; i < n ; i++)
	{
		//cout << " ==> " << i << endl;
		if(!st.size() || st.begin()->F > id[b[i]]) st.insert({id[b[i]] , p++}), v1[i] = p - 1, v2[id[b[i]]] = p - 1 ;
		auto [i1 , i2] = *prev(st.lower_bound({id[b[i]] , -1})) ;
		st.insert({id[b[i]] , i2}), v1[i] = i2, v2[id[b[i]]] = i2, st.erase(st.find({i1 , i2})) ; 
		/*cout << st.size() << " : " << endl;
		for(auto it : st) cout << it.F << " : " << it.S << " : " << endl;*/
	}
	
	for(auto it : v1) cout << it << ' ' ;
	cout << endl;
	for(auto it : v2) cout << it << ' ' ; 
	cout << endl;
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1 ;
    //cin >> tt;
    while (tt--) solve() ;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…