#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
using namespace std;
map <ll, vector < pair <ll, ll> > > d;
map <ll, int> u;
ll a[1000000], n, m, q;
void calc (ll x)
{
if (u[x]) return;
u[x] = 1;
if (!x) return;
ll l = (x - 1) / 2, r = x - 1 - l;
calc (l);
calc (r);
ll ptr1 = 0, ptr2 = 0;
while (ptr1 != d[l].size () || ptr2 != d[r].size ())
{
if (ptr1 != d[l].size () && ptr2 != d[r].size () && d[l][ptr1].first == d[r][ptr2].first)
{
d[x].emplace_back (d[l][ptr1].first, d[l][ptr1].second + d[r][ptr2].second);
ptr1++;
ptr2++;
continue;
}
if (ptr1 < d[l].size () && (ptr2 == d[r].size () || d[l][ptr1] < d[r][ptr2]))
{
d[x].push_back (d[l][ptr1]);
ptr1++;
}
else
{
d[x].push_back (d[r][ptr2]);
ptr2++;
}
}
d[x].emplace_back (x, 1);
}
ll ord_stat (ll x, ll c, ll len, ll l, ll r)
{
if (len == x) return (l + r) / 2;
ll m = (l + r) / 2;
ll len_l = (len - 1) / 2, len_r = len - 1 - len_l;
ll k = lower_bound (d[len_l].begin (), d[len_l].end (), make_pair (x, 0LL)) - d[len_l].begin ();
if (k != d[len_l].size () && d[len_l][k].first == x)
{
if (d[len_l][k].second >= c) return ord_stat (x, c, len_l, l, m - 1);
else return ord_stat (x, c - d[len_l][k].second, len_r, m + 1, r);
}
else return ord_stat (x, c, len_r, m + 1, r);
}
struct seg
{
ll x, c, i;
bool operator < (const seg& b) const
{
return (x == b.x ? i < b.i : x > b.x);
}
};
vector <seg> v;
int main ()
{
cin >> m >> n >> q;
for (ll i = 0; i < n; i++)
{
scanf ("%lld", &a[i]);
if (i) calc (a[i] - a[i-1] - 1);
else calc (a[i] - 1);
}
calc (m - (n ? a[n-1] : 0));
for (ll i = 0; i < n; i++)
for (auto x : d[a[i] - (i ? a[i-1] : 0) - 1])
v.push_back ({x.first, x.second, i});
for (auto x : d[m - (n ? a[n-1] : 0)])
v.push_back ({x.first, x.second, n});
sort (v.begin(), v.end());
ll sum = 0, ptr = 0;
for (ll i = 0; i < q; i++)
{
ll b;
scanf ("%lld", &b);
if (b <= n)
{
printf ("%lld\n", a[b-1]);
continue;
}
b -= n;
if (sum + v[ptr].c < b)
{
do
{
sum += v[ptr].c;
ptr++;
}
while (ptr != v.size () && sum + v[ptr].c < b);
}
ll l = (v[ptr].i ? a[v[ptr].i - 1] + 1 : 1), r = (v[ptr].i != n ? a[v[ptr].i] - 1 : m);
printf ("%lld\n", ord_stat (v[ptr].x, b - sum, r - l + 1, l, r));
}
}
Compilation message
ogledala.cpp: In function 'void calc(ll)':
ogledala.cpp:39:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (ptr1 != d[l].size () || ptr2 != d[r].size ())
~~~~~^~~~~~~~~~~~~~~
ogledala.cpp:39:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (ptr1 != d[l].size () || ptr2 != d[r].size ())
~~~~~^~~~~~~~~~~~~~~
ogledala.cpp:41:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ptr1 != d[l].size () && ptr2 != d[r].size () && d[l][ptr1].first == d[r][ptr2].first)
~~~~~^~~~~~~~~~~~~~~
ogledala.cpp:41:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ptr1 != d[l].size () && ptr2 != d[r].size () && d[l][ptr1].first == d[r][ptr2].first)
~~~~~^~~~~~~~~~~~~~~
ogledala.cpp:51:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ptr1 < d[l].size () && (ptr2 == d[r].size () || d[l][ptr1] < d[r][ptr2]))
~~~~~^~~~~~~~~~~~~~
ogledala.cpp:51:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ptr1 < d[l].size () && (ptr2 == d[r].size () || d[l][ptr1] < d[r][ptr2]))
~~~~~^~~~~~~~~~~~~~~
ogledala.cpp: In function 'll ord_stat(ll, ll, ll, ll, ll)':
ogledala.cpp:74:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (k != d[len_l].size () && d[len_l][k].first == x)
~~^~~~~~~~~~~~~~~~~~~
ogledala.cpp: In function 'int main()':
ogledala.cpp:136:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (ptr != v.size () && sum + v[ptr].c < b);
~~~~^~~~~~~~~~~~
ogledala.cpp:100:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%lld", &a[i]);
~~~~~~^~~~~~~~~~~~~~~
ogledala.cpp:122:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%lld", &b);
~~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
45 ms |
2416 KB |
Output is correct |
4 |
Correct |
39 ms |
2560 KB |
Output is correct |
5 |
Correct |
78 ms |
8292 KB |
Output is correct |
6 |
Correct |
72 ms |
8288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
2936 KB |
Output is correct |
2 |
Correct |
40 ms |
3128 KB |
Output is correct |
3 |
Execution timed out |
4034 ms |
278136 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3896 ms |
204720 KB |
Output is correct |
2 |
Correct |
3744 ms |
192620 KB |
Output is correct |
3 |
Execution timed out |
4114 ms |
276980 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |