Mai intai trebuie sa te autentifici.
Cod sursa(job #1676987)
Utilizator | Data | 6 aprilie 2016 11:49:38 | |
---|---|---|---|
Problema | Nums | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 3.17 kb |
/*#include <fstream>
#include <cmath>
#include <string>
#include <map>
#include <algorithm>
#define Pe pair <string, int>
#define mp make_pair
#define str first
#define index second
using namespace std;
const int MaxN = (1 << 17);
ifstream cin("nums.in");
ofstream cout("nums.out");
map <string, bool> psh; ///Is updated in tree
Pe Updt[MaxN];
int SegTree[2 * MaxN], Up_index[MaxN];
int RgLim, n, updt_nr;
class Num {
public:
bool type;
int pos, index;
};
Num op[MaxN];
inline bool cmp(const Pe &a, const Pe &b) {
if(a.str.size() == b.str.size()) {
return a.str < b.str;
}
return a.str.size() < b.str.size();
}
inline int LfSon(int node) {
return 2 * node;
}
inline int RgSon(int node) {
return 2 * node + 1;
}
inline void LimInit() {
RgLim = log2(updt_nr);
RgLim += ((1 << RgLim) < updt_nr);
RgLim = (1 << RgLim);
}
void Update(int pos, int l = 1, int r = RgLim, int node = 1) {
if(l == r) {
SegTree[node] = 1;
return;
}
int med = (l + r) / 2;
if(pos <= med) {
Update(pos, l, med, LfSon(node));
}
else {
Update(pos, med + 1, r, RgSon(node));
}
SegTree[node] = SegTree[LfSon(node)] + SegTree[RgSon(node)];
}
string Query(int pos, int l = 1, int r = RgLim, int node = 1) {
if(l == r) {
return Updt[l].str;
}
int med = (l + r) / 2;
if(pos <= SegTree[LfSon(node)]) {
return Query(pos, l, med, LfSon(node));
}
return Query(pos - SegTree[LfSon(node)], med + 1, r, RgSon(node));
}
int main() {
cin >> n;
for(int i = 1; i <= n; ++i) {
bool type;
cin >> type;
op[i].type = type;
if(type) {
string str;
cin >> str;
if(psh[str]) {
continue;
}
++updt_nr;
Updt[updt_nr] = mp(str, updt_nr);
psh[str] = true;
op[i].index = updt_nr;
}
else {
int val;
cin >> val;
op[i].pos = val;
}
}
sort(Updt + 1, Updt + updt_nr + 1, cmp);
LimInit();
for(int i = 1; i <= updt_nr; ++i) {
Up_index[Updt[i].index] = i;
}
for(int i = 1; i <= n; ++i) {
if(op[i].type) {
Update(Up_index[op[i].index]);
}
else {
cout << Query(op[i].pos) << '\n';
}
}
return 0;
}
*/
#include <fstream>
#include <algorithm>
#include <vector>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
ifstream cin("nums.in");
ofstream cout("nums.out");
int n;
class Cmp {
public:
inline bool operator () (const string &a, const string &b) const {
if(a.size() == b.size()) {
return a < b;
}
return a.size() < b.size();
}
};
tree <string, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update> OrderSet;
int main() {
cin >> n;
for(int i = 1; i <= n; ++i) {
bool type;
cin >> type;
if(type) {
string str;
cin >> str;
OrderSet.insert(str);
}
else {
int pos;
cin >> pos;
cout << *OrderSet.find_by_order(pos - 1) << '\n';
}
}
return 0;
}