_Scaley @ 2021-07-19 20:59:30
评测记录
蒟蒻死活调不出来,求 dalao 帮忙 QAQ
让窝康康我又双叒叕犯了什么 sb 错误
#include <bits/stdc++.h>
#define MAXN 1000010
#define INF 2147483647
#define int long long
using namespace std;
//--------------定义结构体--------------
struct Node {
int vul, dat, size, cnt, sum;
} e[MAXN];
//---------------定义变量---------------
int n, m, root, cnt = 0, Rank, Sum, pre;
int ch[MAXN][2], A[MAXN];
//---------------定义函数---------------
inline int read() {
int f = 0, x = 0; char ch = getchar();
while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
void pushup(int id) {
e[id].size = e[ch[id][0]].size + e[ch[id][1]].size + e[id].cnt;
e[id].sum = e[id].vul * e[id].cnt + e[ch[id][0]].sum + e[ch[id][1]].sum;
if (id == 1 || id == 2) e[id].sum = 0;
}
int New(int vul) {
e[++cnt].vul = vul; e[cnt].dat = rand();
e[cnt].size = e[cnt].cnt = 1;
pushup(cnt);
return cnt;
}
void BuildTree() {
root = New(-INF);
ch[root][1] = New(INF);
pushup(root);
}
void Rotate(int &id, int dir) {
int now = ch[id][dir ^ 1];
ch[id][dir ^ 1] = ch[now][dir];
ch[now][dir] = id;
id = now;
pushup(ch[id][dir]), pushup(id);
}
void insert(int &id, int vul) {
if (id == 0) {
id = New(vul);
return ;
}
if (vul == e[id].vul) ++e[id].cnt;
else {
int dir = vul < e[id].vul ? 0 : 1;
insert(ch[id][dir], vul);
if (e[id].dat < e[ch[id][dir]].dat) Rotate(id, dir ^ 1);
}
pushup(id);
}
void Remove(int &id, int vul) {
if (id == 0) return ;
if (vul == e[id].vul) {
if (e[id].cnt > 1) {
--e[id].cnt;
pushup(id);
return ;
}
if (ch[id][0] || ch[id][1]) {
if (!ch[id][1] || e[ch[id][1]].dat < e[ch[id][0]].dat)
Rotate(id, 1), Remove(ch[id][1], vul);
else Rotate(id, 0), Remove(ch[id][0], vul);
pushup(id);
}
else id = 0;
return ;
}
vul < e[id].vul ? Remove(ch[id][0], vul) : Remove(ch[id][1], vul);
pushup(id);
}
int GetRank(int id, int vul) {
if (id == 0) return -2;
if (vul == e[id].vul) return e[ch[id][0]].size + e[id].cnt;
else if (vul < e[id].vul) return GetRank(ch[id][0], vul);
else return e[ch[id][0]].size + e[id].cnt + GetRank(ch[id][1], vul);
}
int GetPreSum(int vul) {
int id = root, Pre;
while (id != 0) {
if (e[id].vul < vul) {
Pre = e[id].vul;
Sum += (e[ch[id][0]].sum + e[id].cnt * ((id == 1 || id == 2) ? 0 : e[id].vul));
id = ch[id][1];
}
else id = ch[id][0];
}
return Pre;
}
//----------------主函数----------------
signed main() {
char opt;
n = read(); m = read();
BuildTree();
for (int i = 1; i <= n; ++i) A[i] = 0, insert(root, 0);
for (int i = 1, k, a, c, s; i <= m; ++i) {
cin >> opt;
if (opt == 'U') {
k = read(); a = read();
Remove(root, A[k]);
insert(root, a);
A[k] = a;
}
else {
c = read(); s = read(); Sum = 0;
pre = GetPreSum(s);
Rank = GetRank(root, pre) - 1;
// cout << pre << " " << Rank << " " << Sum << endl;
if (Sum >= (c - (n - Rank)) * s) printf("TAK\n");
else printf("NIE\n");
}
}
return 0;
}
求不要在意码风(逃)
其实我已经预见到这个帖子会沉,但我还是义无反顾地挂了上来(万一有 dalao 闲得慌呢)
by _Scaley @ 2021-07-20 19:50:12
帖子果然沉了……不过问题已经解决了
我把 GetSum 重写了一遍过了