Submission #101220

# Submission time Handle Problem Language Result Execution time Memory
101220 2019-03-17T16:55:02 Z mraron medians (balkan11_medians) C++14
5 / 100
143 ms 12336 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=200101;
struct fenwick {
	int arr[MAXN];
	
	fenwick() {memset(arr,0,sizeof arr);}
	
	void incr(int x, int by) {
		for(;x<MAXN;x+=(x&(-x))) {
			arr[x]+=by;
		}
	} 
	
	int sum(int x) {
		int sum=0;
		for(;x>0;x-=(x&(-x))) {
			sum+=arr[x];
		}
		
		return sum;
	}
};




int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	vector<int> t(n);
	for(int i=0;i<n;++i) cin>>t[i];
	set<int> s;
	for(int i=1;i<=2*n-1;++i) s.insert(i);
	fenwick fw;
	fw.incr(t[0], 1);
	s.erase(t[0]);
	vector<int> ans;
	ans.push_back(t[0]);
	
	auto med=[&]() -> int {
		int all=fw.sum(MAXN-1);
		int kell=(all+1)/2;
		int akt=MAXN-1;
		for(int i=20;i>=0;i--) {
			int curr=akt-(1<<i);
			if(curr>=1) {
				if(fw.sum(curr)>=kell) {
					akt=curr;
				}
			}
		}
		
		return akt;
	};
	
	auto addmin=[&](){
		int val=*s.begin();
		s.erase(val);
		fw.incr(val, 1);
		ans.push_back(val);
	};
	
		
	auto addmax=[&](){
		auto it=s.end();
		it--;
		int val=*it;
		s.erase(val);
		fw.incr(val, 1);
		ans.push_back(val);
	};
	
	for(int i=1;i<n;++i) {
		if(s.find(t[i])==s.end()) {
			if(med()<t[i]) {
				addmin();
				addmin();
			}else if(med()>t[i]) {
				addmax();
				addmax();
			}else {
				addmin();
				addmax();
			}
		}else {
			s.erase(t[i]);
			fw.incr(t[i], 1);
			ans.push_back(t[i]);
			if(med()<t[i]) addmin();
			else addmax();
		}
	}
	
	for(auto i:ans) {
		cout<<i<<" ";
	}
	cout<<"\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1152 KB Output isn't correct
2 Incorrect 3 ms 1152 KB Output isn't correct
3 Incorrect 3 ms 1152 KB Output isn't correct
4 Incorrect 3 ms 1152 KB Output isn't correct
5 Incorrect 3 ms 1152 KB Output isn't correct
6 Correct 3 ms 1152 KB Output is correct
7 Incorrect 4 ms 1152 KB Output isn't correct
8 Incorrect 3 ms 1152 KB Output isn't correct
9 Incorrect 3 ms 1152 KB Output isn't correct
10 Incorrect 3 ms 1152 KB Output isn't correct
11 Incorrect 3 ms 1152 KB Output isn't correct
12 Incorrect 4 ms 1152 KB Output isn't correct
13 Incorrect 4 ms 1280 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1408 KB Output isn't correct
2 Incorrect 6 ms 1536 KB Output isn't correct
3 Incorrect 12 ms 1920 KB Output isn't correct
4 Incorrect 26 ms 2944 KB Output isn't correct
5 Incorrect 49 ms 4828 KB Output isn't correct
6 Incorrect 81 ms 8184 KB Output isn't correct
7 Incorrect 143 ms 12336 KB Output isn't correct