제출 #21000

#제출 시각아이디문제언어결과실행 시간메모리
21000model_codeSwap (BOI16_swap)C++11
100 / 100
183 ms38064 KiB
#include <iostream>
#include <climits>

using namespace std;

struct T {
	T(int val) : val(val) { }
	T(T* a, T* b, bool* d) : val(0), a(a), b(b), d(d) { }
	
	int val;
	T* a;
	T* b;
	bool* d;
	
	int query() {
		if(val) {
			return val;
		} else if(*d) {
			return a->query();
		} else {
			return min(a->query(), b->query());
		}
	}
	bool del(int x) {
		if(val) {
			if(val == x) {
				val = INT_MAX;
				return true;
			}
			return false;
		} else if(*d) {
			return a->del(x);
		} else {
			if(a->del(x)) {
				*d = true;
				return true;
			}
			if(b->del(x)) {
				*d = true;
				swap(*a, *b);
				return true;
			}
			return false;
		}
	}
};

T* t[202020];

int main() {
	
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		t[i] = new T(x);
	}
	
	for(int i = 2; i <= n; ++i) {
		T* a = t[i / 2];
		T* b = t[i];
		bool* d = new bool(false);
		t[i / 2] = new T(a, b, d);
		t[i] = new T(b, a, d);
	}
	
	for(int i = 1; i <= n; ++i) {
		int val = t[i]->query();
		t[i]->del(val);
		if(i != 1) cout << ' ';
		cout << val;
	}
	cout << '\n';
	
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...