This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, pair<ll, ll>> iii;
const int N = 3e5 + 5;
ll a[N], b[N], ans[N];
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m, n, q; cin >> m >> n >> q;
for(int i = 1; i <= n; ++i)cin >> a[i];
for(int i = 1; i <= q; ++i)cin >> b[i];
for(int i = 1; i <= n; ++i)ans[i] = a[i];
priority_queue<iii> pq;
if(a[1] > 1)pq.push(mp(a[1] - 1, mp(-1, -(a[1] - 1))));
for(int i = 1; i < n; ++i){
if(a[i] + 1 < a[i + 1]){
pq.push(mp(a[i + 1] - a[i] - 1, mp(-(a[i] + 1), -(a[i + 1] - 1))));
}
}
if(a[n] < m)pq.push(mp(m - a[n], mp(-(a[n] + 1), -m)));
for(int i = n + 1; i < N; ++i){
iii cur = pq.top(); pq.pop();
ans[i] = -cur.se.fi + (cur.fi - 1)/2;
if(-cur.se.fi < ans[i]){
pq.push(mp(ans[i] - (-cur.se.fi), mp(cur.se.fi, -(ans[i] - 1))));
}
if(ans[i] < -cur.se.se){
pq.push(mp(-cur.se.se - ans[i], mp(-(ans[i] + 1), cur.se.se)));
}
}
for(int i = 1; i <= q; ++i){
cout << ans[b[i]] << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |