#include <stdio.h>
#include <algorithm>
#include <vector>
#include <ctime>
#include <cstdlib>
int log2(int n) {
int pow = 0;
while ((1 << (pow+1)) <= n) {
++pow;
}
return pow;
}
struct Fenwick {
const int size, pow2;
std::vector<int> data;
Fenwick(const std::vector<bool>& a)
: size((int)a.size())
, pow2(1 << log2(size))
{
data.resize(size);
for (int i = 0; i < (int)a.size(); i++) {
inc(i, a[i]);
}
}
// Сумма на отрезке [0, r]:
int sum(int r) const {
int result = 0;
for (; r >= 0; r = (r & (r+1)) - 1) {
result += data[r];
}
return result;
}
// Изменение элемента в позиции p на величину delta:
void inc(int p, int delta) {
for (; p < size; p = (p | (p+1))) {
data[p] += delta;
}
}
// Сумма на отрезке [l, r]:
int sum (int l, int r) const {
return sum(r) - sum(l-1);
}
// Нижняя граница для суммы s: sum[0]+...+sum[p-1] < s >= sum[0]+...+sum[p]
int lower_bound(int s) const {
int pos = 0;
for (int p = pow2; p >= 1; p /= 2) {
if (pos + p - 1 < size && data[pos + p - 1] < s) {
s -= data[pos + p - 1];
pos += p;
}
}
return pos;
}
};
int main() {
double t = clock();
int n, k, q;
scanf("%d %d %d", &n, &k, &q);
std::vector<int> answer(1+n, 0);
Fenwick fw(std::vector<bool>(1+n, true));
fw.inc(0, -1);
// Моделирование удаления элементов за O(n log(n))
while (n >= k) {
int sum = k, erased = 0, limit = n / k;
while (erased < limit) {
int number = fw.lower_bound(sum);
fw.inc(number, -1);
answer[number] = (int)answer.size() - n + erased;
sum += k - 1;
++erased;
}
n -= erased;
}
// Ответ на запросы:
while (q--) {
int item;
scanf("%d", &item);
printf("%d\n", answer[item]);
}
fprintf(stderr, "time = %0.3fs\n", (clock() - t) / CLOCKS_PER_SEC);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPGNzdGRsaWI+CgppbnQgbG9nMihpbnQgbikgewogICAgaW50IHBvdyA9IDA7CiAgICB3aGlsZSAoKDEgPDwgKHBvdysxKSkgPD0gbikgewogICAgICAgICsrcG93OwogICAgfQogICAgcmV0dXJuIHBvdzsKfQoKc3RydWN0IEZlbndpY2sgewogICAgCiAgICBjb25zdCBpbnQgc2l6ZSwgcG93MjsKICAgIAogICAgc3RkOjp2ZWN0b3I8aW50PiBkYXRhOwogICAgCiAgICBGZW53aWNrKGNvbnN0IHN0ZDo6dmVjdG9yPGJvb2w+JiBhKSAKICAgICAgICA6IHNpemUoKGludClhLnNpemUoKSkKICAgICAgICAsIHBvdzIoMSA8PCBsb2cyKHNpemUpKQogICAgewogICAgICAgIGRhdGEucmVzaXplKHNpemUpOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgKGludClhLnNpemUoKTsgaSsrKSB7CiAgICAgICAgICAgIGluYyhpLCBhW2ldKTsKICAgICAgICB9CiAgICB9CgogICAgLy8g0KHRg9C80LzQsCDQvdCwINC+0YLRgNC10LfQutC1IFswLCByXToKICAgIGludCBzdW0oaW50IHIpIGNvbnN0IHsKICAgICAgICBpbnQgcmVzdWx0ID0gMDsKICAgICAgICBmb3IgKDsgciA+PSAwOyByID0gKHIgJiAocisxKSkgLSAxKSB7CiAgICAgICAgICAgIHJlc3VsdCArPSBkYXRhW3JdOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgfQoKICAgIC8vINCY0LfQvNC10L3QtdC90LjQtSDRjdC70LXQvNC10L3RgtCwINCyINC/0L7Qt9C40YbQuNC4IHAg0L3QsCDQstC10LvQuNGH0LjQvdGDIGRlbHRhOgogICAgdm9pZCBpbmMoaW50IHAsIGludCBkZWx0YSkgewogICAgICAgIGZvciAoOyBwIDwgc2l6ZTsgcCA9IChwIHwgKHArMSkpKSB7CiAgICAgICAgICAgIGRhdGFbcF0gKz0gZGVsdGE7CiAgICAgICAgfQogICAgfQoKICAgIC8vINCh0YPQvNC80LAg0L3QsCDQvtGC0YDQ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QgPSBuIC8gazsKICAgICAgICB3aGlsZSAoZXJhc2VkIDwgbGltaXQpIHsKICAgICAgICAgICAgaW50IG51bWJlciA9IGZ3Lmxvd2VyX2JvdW5kKHN1bSk7CiAgICAgICAgICAgIGZ3LmluYyhudW1iZXIsIC0xKTsKICAgICAgICAgICAgYW5zd2VyW251bWJlcl0gPSAoaW50KWFuc3dlci5zaXplKCkgLSBuICsgZXJhc2VkOwogICAgICAgICAgICBzdW0gKz0gayAtIDE7CiAgICAgICAgICAgICsrZXJhc2VkOwogICAgICAgIH0KICAgICAgICBuIC09IGVyYXNlZDsKICAgIH0KICAgIAogICAgLy8g0J7RgtCy0LXRgiDQvdCwINC30LDQv9GA0L7RgdGLOgogICAgd2hpbGUgKHEtLSkgewogICAgICAgIGludCBpdGVtOwogICAgICAgIHNjYW5mKCIlZCIsICZpdGVtKTsKICAgICAgICBwcmludGYoIiVkXG4iLCBhbnN3ZXJbaXRlbV0pOwogICAgfQogICAgCiAgICBmcHJpbnRmKHN0ZGVyciwgInRpbWUgPSAlMC4zZnNcbiIsIChjbG9jaygpIC0gdCkgLyBDTE9DS1NfUEVSX1NFQyk7CiAgICAKICAgIHJldHVybiAwOwp9