#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 100100
#define MAXB 300100
ll m;
int n, q;
ll a[MAXB];
int32_t main(void)
{
fast_io;
cin >> m >> n >> q;
FOR(i, 1, n + 1)
cin >> a[i];
set<pair<ll, pll>> s;
if (a[1] > 1)
s.insert({a[1] - 1, {-1, a[1] - 1}});
if (a[n] < m)
s.insert({m - a[n], {-(a[n] + 1), m}});
FOR(i, 2, n + 1)
{
if (a[i] == a[i - 1] + 1)
continue;
s.insert({a[i] - a[i - 1] - 1, {-(a[i - 1] + 1), a[i] - 1}});
}
FOR(i, n + 1, min((ll)MAXB, m + 1))
{
pll p = s.rbegin() -> sc;
auto it = s.end();
it--;
s.erase(it);
p.fr = -p.fr;
a[i] = (p.fr + p.sc) / 2;
if (a[i] != p.fr)
s.insert({a[i] - p.fr, {-p.fr, a[i] - 1}});
if (a[i] != p.sc)
s.insert({p.sc - a[i], {-(a[i] + 1), p.sc}});
}
while (q--)
{
int b;
cin >> b;
cout << a[b] << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
41 ms |
4716 KB |
Output is correct |
4 |
Correct |
35 ms |
4716 KB |
Output is correct |
5 |
Correct |
83 ms |
10428 KB |
Output is correct |
6 |
Correct |
79 ms |
11056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
21640 KB |
Output is correct |
2 |
Correct |
153 ms |
21612 KB |
Output is correct |
3 |
Correct |
209 ms |
22764 KB |
Output is correct |
4 |
Correct |
212 ms |
22744 KB |
Output is correct |
5 |
Correct |
208 ms |
22980 KB |
Output is correct |
6 |
Correct |
203 ms |
23008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
204 ms |
43372 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |