Cod sursa(job #2473731)
Utilizator | Mihnea Andreescu FunnyStocky | Data | 14 octombrie 2019 10:10:22 |
---|---|---|---|
Problema | Nums | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 1 kb |
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 100000 + 7;
int n;
bool e[N];
int aib[N];
void ins(int x)
{
if (e[x])
return;
e[x] = 1;
for (int i = x; i < N; i += i & (-i))
aib[i] += 1;
}
int getk(int k)
{
int res = 0, cur = 0;
for (int step = (1 << 17); step; step /= 2)
if (res + step < N && aib[res + step] + cur < k)
{
res += step;
cur += aib[res];
}
res++;
return res;
}
int main()
{
freopen ("nums.in", "r", stdin);
freopen ("nums.out", "w", stdout);
int q;
cin >> q;
while (q--)
{
int t, x;
cin >> t >> x;
if (t == 1)
ins(x);
else
cout << getk(x) << "\n";
}
return 0;
}