이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
};
priority_queue<Space> spaces;
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.push({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);
if (!res[x]) res[x] = 1;
}
for(int i = n+1; i <= mxq; i++) {
// lady i arrives
auto space = spaces.top();
lint len = space.len;
lint starti = space.starti;
lint stopi = space.stopi;
spaces.pop();
lint nbin = (starti + stopi) / 2;
//bins.insert(nbin);
//cerr << "lady " << i << ": " << nbin << " space=" << len << "=" << starti << "," << stopi << endl;
if (res[i]) res[i] = nbin;
//cerr << "adding space: " << nbin-starti-1 << " " << starti << " " << nbin << endl;
spaces.push({ nbin-starti-1, starti, nbin });
//cerr << "adding space: " << stopi-nbin-1 << " " << nbin << " " << stopi << endl;
spaces.push({ stopi-nbin-1, nbin, stopi });
}
for (int lady : queries) cout << res[lady] << " ";
cout << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
ogledala.cpp: In function 'int main()':
ogledala.cpp:58:8: warning: unused variable 'len' [-Wunused-variable]
58 | 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... |