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 lint long long
#define endl '\n'
#define pii pair<int, int>
#define pll pair<lint, lint>
#define For(i,n) for (int i = 0; i < n; i++)
#define FOR For(i, n)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const lint N = 3e5+100;
struct Space {
lint len; lint starti; lint stopi;
bool operator <(const Space other) const {
return len == other.len ? starti < other.starti : len > other.len;
}
};
set<Space> spaces; // length, stopbin
set<lint> bins;
map<lint, lint> res;
int main() {
fastio;
lint m,n,q; cin >> m >> n >> q;
bins.insert(0);
bins.insert(m+1);
FOR {
lint x; cin >> x;
res[i+1] = x;
bins.insert(x);
}
// construct spaces
auto it = bins.begin(); lint pv = *it; it++;
for (; it != bins.end(); it++) {
lint v = *it;
lint space = v-pv-1;
//cerr << "adding space: " << space << " " << pv << " " << v << endl;
spaces.insert({space, pv, v});
pv = v;
}
// save queries
vector<lint> queries(q);
lint mxq = 0; // greatest query
For(i,q) {
lint x; cin >> x; queries[i] = x;
mxq = max(x, mxq);
}
for(int i = n+1; i <= mxq; i++) {
// lady i arrives
auto space = *spaces.begin();
lint len = space.len;
lint starti = space.starti;
lint stopi = space.stopi;
spaces.erase(spaces.begin());
lint nbin = (starti + stopi) / 2;
//bins.insert(nbin);
//cerr << "lady " << i << ": " << nbin << " space=" << len << "=" << starti << "," << stopi << endl;
res[i] = nbin;
//cerr << "adding space: " << nbin-starti-1 << " " << starti << " " << nbin << endl;
spaces.insert({ nbin-starti-1, starti, nbin });
//cerr << "adding space: " << stopi-nbin-1 << " " << nbin << " " << stopi << endl;
spaces.insert({ stopi-nbin-1, nbin, stopi });
}
for (int lady : queries) cout << res[lady] << " ";
cout << endl;
}
Compilation message (stderr)
ogledala.cpp: In function 'int main()':
ogledala.cpp:57:8: warning: unused variable 'len' [-Wunused-variable]
57 | lint len = space.len;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |