# 「考前日志」11.10

## 上午

### 洛谷 P4291 [HAOI2008]排名系统

#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lson rt << 1
#define rson rt << 1 | 1
using namespace std;

const int A = 3e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

char c = getchar();
int x = 0, f = 1;
for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return x * f;
}

int n;
struct dat {
int soc, tim;
string nam;
char opt;
inline bool operator < (const dat &tmp) const {
return soc != tmp.soc ? soc<tmp.soc : tim>tmp.tim;
}
} c[A], d[A];
map <string, int> pre;
int t[A << 2], pos, val, res;

void update(int rt, int l, int r) {
t[rt] += val;
if (l == r) return;
int mid = l + r >> 1;
if (pos <= mid) update(lson, l, mid);
else update(rson, mid + 1, r);
}

void query_rnk(int rt, int l, int r) {
if (l == r) return;
int mid = l + r >> 1;
if (pos <= mid) query_rnk(lson, l, mid), res += t[rson];
else query_rnk(rson, mid + 1, r);
}

void query(int rt, int l, int r) {
if (l == r) {
res = l;
return;
}
int mid = l + r >> 1;
if (val > t[rson]) val -= t[rson], query(lson, l, mid);
else query(rson, mid + 1, r);
}

inline int calc(string s) {
int m = s.size(), res = 0;
for (int i = 0; i < m; i++)
res = res * 10 + s[i] - '0';
return res;
}

int main() {
for (int i = 1; i <= n; i++) {
cin >> d[i].opt >> d[i].nam;
if (d[i].opt == '+') d[i].soc = read();
d[i].tim = i, c[i] = d[i];
}
sort(d + 1, d + n + 1);
int tot = 0;
for (int i = 1; i <= n; i++) {
if (c[i].opt == '+') {
pos = pre[c[i].nam];
if (pos) val = -1, update(1, 1, n);
else tot++;
pos = lower_bound(d + 1, d + n + 1, c[i]) - d;
val = 1;
update(1, 1, n);
pre[c[i].nam] = pos;
continue;
}
if (c[i].nam[0] > '9' || c[i].nam[0] < '0') {
res = 0;
pos = pre[c[i].nam];
query_rnk(1, 1, n);
cout << res + 1 << '\n';
continue;
}
for (int k = 1, j = calc(c[i].nam); k <= 10 && j <= tot; k++, j++) {
val = j, res = 0;
query(1, 1, n);
cout << d[res].nam << " ";
}
puts("");
}
return 0;
}

/*

*/
/*
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int A = 3e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

char c = getchar();
int x = 0, f = 1;
for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return x * f;
}

int n, cnt;
string nam;
struct node {
int tim, sco;
string name;
} a[A];

bool cmp(node x, node y) {
return x.sco != y.sco ? x.sco > y.sco : x.tim < y.tim;
}

int main() {
for (int i = 1; i <= n; i++) {
sort(a + 1, a + 1 + cnt, cmp);
char c;
cin >> c;
if (c == '+') {
cin >> nam;
int scor = read(), flag = 0;
for (int j = 1; j <= cnt; j++) {
if (a[j].name == nam) {
a[j] = (node) {i, scor, nam};
flag = 1;
break;
}
}
if (!flag) a[++cnt] = (node){i, scor, nam};
}
else {
nam = "";
char c = getchar();
if (isdigit(c)) {
int x = 0;
for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
for (int j = x; j <= min(cnt, x + 9); j++) {
cout << a[j].name << " ";
}
puts("");
}
else {
cin >> nam;
nam = c + nam;
for (int j = 1; j <= cnt; j++) {
if (a[j].name == nam) {
cout << j << '\n';
break;
}
}
}
}
}
return 0;
}
*/


## 下午

### 洛谷 P4903 心碎

#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

const int A = 1e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

char c = getchar();
int x = 0, f = 1;
for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return x * f;
}

signed main() {