Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- #include<map>
- #include<set>
- #include<math.h>
- #include<algorithm>
- #include<time.h>
- #include<stdio.h>
- #include<stack>
- #include<queue>
- #include<deque>
- #include<fstream>
- #include<unordered_set>
- #include<unordered_map>
- #include<bitset>
- #include<cstdio>
- using namespace std;
- struct vertex {
- int next[26];
- int dp;
- int leaf;
- };
- vertex t[1000013];
- int sz;
- void add_string(const string & s)
- {
- int v = 0;
- for (size_t i = 0; i<s.length(); ++i) {
- char c = s[i] - 'a';
- if (t[v].next[c] == -1) {
- memset(t[sz].next, 255, sizeof t[sz].next);
- t[v].next[c] = sz++;
- }
- v = t[v].next[c];
- t[v].dp++;
- }
- t[v].leaf ++;
- }
- string s = "";
- string k_por(int k, int v)
- {
- for (int i = 0; i <= 25; i++)
- {
- if (t[v].next[i] != -1)
- {
- if (t[t[v].next[i]].dp < k)
- {
- k -= t[i].dp;
- }
- else
- {
- s += char(i + 'a');
- k_por(k, t[v].next[i]);
- }
- }
- }
- return s;
- }
- int main()
- {
- memset(t[0].next, 255, sizeof t[0].next);
- sz = 1;
- int n, k;
- cin >> n;
- string s;
- for (int i = 1; i <= n; i++)
- {
- cin >> s;
- if (s[0] >= 'a' && s[0] <= 'z')
- {
- add_string(s);
- }
- else
- {
- int k=0;
- for (int i = 0; i<s.size(); i++)
- {
- k *= 10;
- k += s[i] - '0';
- }
- cout << k_por(k, 0) << endl;
- s = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement