답안 #249363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249363 2020-07-14T16:50:37 Z vanic OGLEDALA (COI15_ogledala) C++14
22 / 100
4000 ms 271508 KB
#include <iostream>
#include <algorithm>
#include <math.h>
#include <set>
#include <queue>

using namespace std;

const int maxn=3e5+5;
typedef long long ll;

class Compare{
public:
	bool operator()(pair < ll, ll > a, pair < ll, ll > b){
		if(a.first!=b.first){
			return a.first<b.first;
		}
		return a.second>b.second;
	}
};

priority_queue < pair < ll, ll >, vector < pair < ll, ll > >, Compare > svi;
set < pair < ll, ll > > s;
ll a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll m, n, q;
	cin >> m >> n >> q;
	s.insert({0, m-1});
	set < pair < ll, ll > >::const_iterator it;
	pair < ll, ll > p;
	for(int i=0; i<n; i++){
		cin >> a[i];
		a[i]--;
		if(n<3e5){
			it=s.upper_bound({a[i], a[i]});
			it--;
			p=*it;
			s.erase(it);
			if(p.first!=a[i]){
				s.insert({p.first, a[i]-1});
			}
			if(p.second!=a[i]){
				s.insert({a[i]+1, p.second});
			}
		}
		
	}
	for(it=s.begin(); it!=s.end(); it++){
		p=*it;
		svi.push({p.second-p.first+1, p.first});
	}
	ll val;
	ll pos=n;
	ll b;
	ll br;
	for(int i=0; i<q; i++){
		cin >> b;
		if(b<=pos){
			cout << a[b-1]+1 << '\n';
			continue;
		}
		while(pos<b){
			p=svi.top();
			svi.pop();
			br=p.first;
//			cout << "radim " << p.first << " " << p.second << endl;
			val=p.second+(br-1)/2;
			if(val!=p.second){
				svi.push({val-p.second, p.second});
			}
			if(val!=p.second+br-1){
				svi.push({p.second+br-1-val, val+1});
			}
			pos++;
		}
		cout << val+1 << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 8800 KB Output is correct
2 Correct 57 ms 8776 KB Output is correct
3 Correct 164 ms 18908 KB Output is correct
4 Correct 152 ms 18908 KB Output is correct
5 Correct 158 ms 19168 KB Output is correct
6 Correct 163 ms 19140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4059 ms 271508 KB Time limit exceeded
2 Halted 0 ms 0 KB -