답안 #27514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27514 2017-07-13T08:26:45 Z 김현수(#1153) OGLEDALA (COI15_ogledala) C++14
41 / 100
4000 ms 108276 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 100005;

ll l, n, m, a[N], qry[N], cur[N];
vector<ll> dt[N], v[N];

priority_queue<pll> pq;

ll geti (vector<ll> &V, ll I, ll P) {
	for(ll i=max(0ll, I-3);i<I;i++) if(V[i] == P) return i;
	return -1;
}

void add (vector<ll> &V, ll A) {
	if(A <= 0 || geti(V, V.size(), A) != -1) return;
	V.push_back(A);
}

void kth (ll I, ll C, ll O, ll S, ll E, ll K) {
	if(C == O) {printf("%lld\n",(S+E)/2); return;}
	ll L = E-S+1, I1 = geti(v[I], C, (L-1)/2), I2 = (L/2 == (L-1)/2 ? I1 : I1+1);
	if(I1>=O && dt[I][I1] >= K) kth(I, I1, O, S, (S+E)/2-1, K);
	else kth(I, I2, O, (S+E)/2+1, E, K - (I1>=O ? dt[I][I1] : 0));
}

void calc (vector<ll> &D, vector<ll> &V, ll O) {
	for(ll i=0;i<O;i++) D[i] = 0;
	D[O] = 1;
	for(ll i=O+1;i<V.size();i++) {
		ll I1 = geti(V, i, (V[i]-1)/2), I2 = (V[i]/2 == (V[i]-1)/2 ? I1 : I1+1);
		D[i] = (I1 != -1 ? D[I1] : 0) + (I2 != -1 ? D[I2] : 0);
	}
}

int main() {
	scanf("%lld%lld%lld",&l,&n,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	a[n+1] = l+1;
	for(ll i=1;i<=n+1;i++) {
		add(v[i], a[i]-a[i-1]-1);
		for(ll j=0;j<v[i].size();j++) {
			add(v[i], v[i][j]/2);
			add(v[i], (v[i][j]-1)/2);
		}
		reverse(v[i].begin(), v[i].end());
	}
	for(ll i=1;i<=n+1;i++) {
		cur[i] = v[i].size();
		dt[i].resize(v[i].size());
		if(--cur[i] >= 0) {
			calc(dt[i], v[i], cur[i]);
			pq.push({v[i][cur[i]], -i});
		}
	}
	ll cq = 1, dn = n;
	for(ll i=1;i<=m;i++) {
		scanf("%lld",&qry[i]);
		if(qry[i] <= n) {
			cq++;
			printf("%lld\n",a[qry[i]]);
		}
	}
	while(!pq.empty()) {
		ll C = -pq.top().second, V = dt[C][v[C].size()-1]; pq.pop();
		for(;cq <= m && qry[cq] <= dn + V; cq++) {
			kth(C, v[C].size()-1, cur[C], a[C-1]+1, a[C]-1, qry[cq]-dn);
		}
		if(cq > m) break;
		dn += V;
		if(--cur[C] >= 0) {
			calc(dt[C], v[C], cur[C]);
			pq.push({v[C][cur[C]], -C});
		}
	}
}

Compilation message

ogledala.cpp: In function 'void calc(std::vector<long long int>&, std::vector<long long int>&, ll)':
ogledala.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ll i=O+1;i<V.size();i++) {
                ^
ogledala.cpp: In function 'int main()':
ogledala.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll j=0;j<v[i].size();j++) {
               ^
ogledala.cpp:39:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld",&l,&n,&m);
                                ^
ogledala.cpp:40:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
                                          ^
ogledala.cpp:60:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&qry[i]);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9056 KB Output is correct
2 Correct 3 ms 9056 KB Output is correct
3 Correct 36 ms 10384 KB Output is correct
4 Correct 33 ms 10428 KB Output is correct
5 Correct 129 ms 16756 KB Output is correct
6 Correct 99 ms 17176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9188 KB Output is correct
2 Correct 3 ms 9188 KB Output is correct
3 Correct 353 ms 102000 KB Output is correct
4 Correct 363 ms 103140 KB Output is correct
5 Correct 449 ms 107212 KB Output is correct
6 Correct 463 ms 108276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2229 ms 65804 KB Output is correct
2 Correct 2393 ms 65492 KB Output is correct
3 Correct 3809 ms 96248 KB Output is correct
4 Execution timed out 4000 ms 97868 KB Execution timed out
5 Halted 0 ms 0 KB -