QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359836#8230. SubmissionsricofxWA 55ms5752kbC++177.3kb2024-03-20 21:44:462024-03-20 21:44:47

Judging History

你现在查看的是最新测评结果

  • [2024-05-20 23:50:57]
  • hack成功,自动添加数据
  • (/hack/623)
  • [2024-05-20 23:48:44]
  • hack成功,自动添加数据
  • (/hack/622)
  • [2024-03-20 21:44:47]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:5752kb
  • [2024-03-20 21:44:46]
  • 提交

answer

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define rank miku
#define fi first
#define se second
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
//std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

const int mod = 998244353;
const int N = 1e5 + 5;
int m;
struct submission {
    int c;
    char p;
    int t, ac;
} ss[N];


int tot, fa[N], tr[N][2], sz[N], cnt[N], rt;
pii val[N];
void maintain(int x) {
    sz[x] = sz[tr[x][0]] + sz[tr[x][1]] + cnt[x];
}
int getdir(int x) {
    return tr[fa[x]][1] == x;
}
void clear(int x) {
    fa[x] = sz[x] = cnt[x] = tr[x][0] = tr[x][1] = 0;
    val[x] = {0, 0};
}
int create(pii v) {
    ++tot;
    val[tot] = v;
    sz[tot] = cnt[tot] = 1;
    return tot;
}
void rotate(int x) {
    if (x == rt) return;
    int y = fa[x], z = fa[y], d = getdir(x);
    tr[y][d] = tr[x][d ^ 1];
    if (tr[x][d ^ 1]) fa[tr[x][d ^ 1]] = y;
    fa[y] = x;
    tr[x][d ^ 1] = y;
    fa[x] = z;
    if (z) tr[z][y == tr[z][1]] = x;
    maintain(y);
    maintain(x);
}
void splay(int x) {
    for (int f = fa[x]; f = fa[x], f; rotate(x)) {
        if (fa[f]) rotate(getdir(f) == getdir(x) ? f : x);
    }
    rt = x;
}
int cmp(pii x, pii y) { // return x > y
    return x.fi == y.fi ? x.se > y.se : x.fi < y.fi;
}
void insert(pii v) {
    if (!rt) {
        rt = create(v);
        return;
    }
    int u = rt, f = 0;
    while (true) {
        if (val[u] == v) {
            cnt[u]++;
            maintain(u);
            maintain(f);
            splay(u);
            return;
        }
        f = u, u = tr[u][cmp(v, val[u])];
        if (u == 0) {
            int id;
            fa[id = create(v)] = f;
            tr[f][cmp(v, val[f])] = id;
            maintain(f);
            splay(id);
            return;
        }
    }
}

int rank(pii v) {
    int rk = 0;
    int u = rt;
    while (u) {
        if (val[u] == v) {
            rk += sz[tr[u][0]];
            splay(u);
            return rk + 1;
        }
        if (cmp(val[u], v)) {
            u = tr[u][0];
        } else {
            rk += sz[tr[u][0]] + cnt[u];
            u = tr[u][1];
        }
    }
    return -1;
}

pii kth(int x) {
    int u = rt;
    while (u) {
        if (sz[tr[u][0]] + cnt[u] >= x && sz[tr[u][0]] < x) return val[u];
        if (x <= sz[tr[u][0]]) {
            u = tr[u][0];
        } else {
            x -= sz[tr[u][0]] + cnt[u];
            u = tr[u][1];
        }
    }
    return u ? val[u] : (pii){-1, -1};
}
pii pre() {
    int u = tr[rt][0];
    if (!u) return val[rt];
    while (true) {
        if (tr[u][1] == 0) return splay(u), val[u];
        u = tr[u][1];
    }
    return {233, 233};
}
pii suf() {
    int u = tr[rt][1];
    if (!u) return val[rt];
    while (true) {
        if (tr[u][0] == 0) return splay(u), val[u];
        u = tr[u][0];
    }
     return {233, 233};
}
void del(pii v) {
    if (rank(v) == -1) return;
    if (cnt[rt] > 1) {
        cnt[rt]--;
        return;
    }
    if (!tr[rt][1] && !tr[rt][0]) {
        clear(rt), rt = 0;
    } else if (!tr[rt][0]) {
        int x = rt;
        rt = tr[x][1];
        fa[rt] = 0;
        clear(x);
    } else if (!tr[rt][1]) {
        int x = rt;
        rt = tr[x][0];
        fa[rt] = 0;
        clear(x);
    } else {
        int cur = rt, y = tr[cur][1];
        pre();
        tr[rt][1] = y;
        fa[y] = rt;
        clear(cur);
        maintain(rt);
    }
}

void MAIN() {
    cin >> m;
    // 枚举每个提交的状态。维护 有效队伍,对这个队伍快速算出 [题数,罚时],单个题的罚时
    // AC->WA 第一个AC,找第二个。否则没有影响 对每个提交维护,是该题第几次提交,是第几次 AC 提交。再对队伍的某个题维护 ac 的 submitid
    // WA->AC 之前有AC,没有影响。没有AC,需要重新记录题数和罚时
    map<string, int> pid;
    map<char, vector<int>> pac[m + 1], psb[m + 1]; // team, problem
    int n = 0, acc = 0;
    vector<int> count_sub(m + 1, 0), count_ac(m + 1, 0);
    vector<string> dip(m + 1);
    string name, sta;
    for (int i = 1; i <= m; i++) {
        cin >> name >> ss[i].p >> ss[i].t >> sta;
        if (!pid.count(name)) pid[name] = ++n, dip[n] = name;
        ss[i].c = pid[name];
        ss[i].ac = (sta == "accepted");
        if (ss[i].ac == 1) pac[ss[i].c][ss[i].p].push_back(i);
        psb[ss[i].c][ss[i].p].push_back(i);
        count_sub[i] = psb[ss[i].c][ss[i].p].size();
        count_ac[i] = pac[ss[i].c][ss[i].p].size();
    }
    vector<pii> grad(n + 1, {0, 0});
    for (int i = 1; i <= n; i++) {
        for (auto it : psb[i]) {
            int x = 0, y = 0;
            for (int sid : it.se) {
                if (ss[sid].ac == 1) {
                    ++x; y += ss[sid].t; break;
                } else y += 20;
            }
            if (x == 1) grad[i].fi++, grad[i].se += y;
        }
        acc += (grad[i].fi >= 1);
    }
    // 定义一个三元组 [solved, time, tot]
    auto get = [&](int x) {
        auto old = grad[ss[x].c];
        if (ss[x].ac == 0) {
            if (!pac[ss[x].c][ss[x].p].empty() && pac[ss[x].c][ss[x].p][0] < x) return old;
            if (!pac[ss[x].c][ss[x].p].empty()) {
                int y = pac[ss[x].c][ss[x].p][0];
                old.se -= (count_sub[y] - 1) * 20 + ss[y].t;
            }         
            ++old.fi; old.se += (count_sub[x] - 1) * 20 + ss[x].t;
            return old;
        }
        if (!pac[ss[x].c][ss[x].p].empty() && pac[ss[x].c][ss[x].p][0] < x) return old;
        if (pac[ss[x].c][ss[x].p].size() > 1) {
            int y = pac[ss[x].c][ss[x].p][1];
            old.se -= (count_sub[x] - 1) * 20 + ss[x].t;
            old.se += (count_sub[y] - 1) * 20 + ss[y].t;
            return old;
        } 
        old.se -= (count_sub[x] - 1) * 20 + ss[x].t;
        --old.fi;
        return old;
    };
    for (int i = 0; i <= tot; i++) clear(i);
    tot = rt = 0;
    vector<int> ans;
    map<pii, int> ava;
    for (int i = 1; i <= n; i++) insert(grad[i]);
    for (int i = 1; i <= m; i++) {
        //二分 修改 插入 排名
        //快速算出新的状态
        auto now = get(i);
        //cerr << i << ' ' << ss[i].c << ' ' << now.fi << ' ' << now.se << '\n';
        del(grad[ss[i].c]);
        insert(now);
        int tt = acc;
        if (grad[ss[i].c].fi >= 1 && now.fi == 0) tt--;
        if (grad[ss[i].c].fi == 0 && now.fi >= 1) tt++;
        int gold = min(35, (tt + 9) / 10);
        //cerr << "#" << rank(now) << '\n';
        if (rank(now) <= gold) ans.push_back(ss[i].c);
        for (int i = 1; i <= gold; i++) ava[kth(i)] = 1;
        del(now);
        insert(grad[ss[i].c]);
    }
    for (int i = 1; i <= n; i++) if (ava[grad[i]]) ans.push_back(i);
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ans.size() << '\n';
    for (int x : ans) cout << dip[x] << ' ';
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) MAIN();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5664kb

input:

2
5
TSxingxing10 G 0 rejected
TSxingxing10 B 83 accepted
aoliaoligeiliao J 98 accepted
TS1 J 118 accepted
TS1 B 263 accepted
12
AllWayTheNorth A 0 rejected
YaoYaoLingXian Y 10 accepted
XuejunXinyoudui1 X 200 rejected
XuejunXinyoudui1 X 200 accepted
LetItRot L 215 accepted
AllWayTheNorth W 250 accept...

output:

2
TSxingxing10 TS1 
4
AllWayTheNorth XuejunXinyoudui1 LetItRot ImYourFan 

result:

ok 2 test cases ok. (2 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 5720kb

input:

2
2
jiangly_fan A 1 accepted
jiangly B 23 accepted
3
conqueror_of_tourist A 1 accepted
conqueror_of_tourist A 2 accepted
tourist B 23 accepted

output:

2
jiangly_fan jiangly 
1
conqueror_of_tourist 

result:

ok 2 test cases ok. (2 test cases)

Test #3:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

2
13
A A 1 accepted
A X 1 accepted
K K 1 rejected
B B 2 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 accepted
G G 2 accepted
H H 2 accepted
I I 2 accepted
J J 2 accepted
K K 2 rejected
12
A A 1 accepted
A X 1 accepted
B B 2 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 a...

output:

11
A K B C D E F G H I J 
1
A 

result:

ok 2 test cases ok. (2 test cases)

Test #4:

score: 0
Accepted
time: 1ms
memory: 5668kb

input:

2
11
A A 1 accepted
B B 1 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 accepted
G G 2 accepted
H H 2 accepted
I I 2 accepted
J J 2 accepted
K K 2 accepted
12
A A 1 accepted
A X 1 accepted
K K 1 rejected
B B 2 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 accepted
G G 2 a...

output:

2
A B 
2
A K 

result:

ok 2 test cases ok. (2 test cases)

Test #5:

score: -100
Wrong Answer
time: 55ms
memory: 5752kb

input:

100000
1
M3JytWoaEXxkACy_mBAQ R 111 accepted
1
sQ O 151 accepted
1
JinbrcS58gNEE5yTSkT B 140 accepted
1
cklwBY V 243 accepted
1
v_o42YmvEKFwy Q 260 rejected
1
ftQVK8S_um22w K 265 accepted
1
_bQBeFeDpYQhvZcLf9l3 Z 147 accepted
1
KvDcEAIDN A 75 rejected
1
H3MUK6 A 101 rejected
1
gxYo_oCFn2J8aIben U 54...

output:

0

0

0

0

1
v_o42YmvEKFwy 
0

0

1
KvDcEAIDN 
1
H3MUK6 
0

0

0

1
6In2do_50ylch 
1
f0r3SXc6brMjT 
0

1
x 
0

1
aGedzS 
0

1
4Vf5RXaTmySkFcXgHLOh 
1
92LkkbV6chs 
1
hCC2PwSkOh1 
0

1
1scXai5drfDikFlnL6 
1
QzHXSTo2LpxT 
1
9Zy6NRA 
1
VnzIIS4l9Ttr0nf 
0

0

1
HzPwrw 
1
C2wTxTysC5BsIwdJCng 
0

0

0

1
...

result:

wrong answer Integer parameter [name=n] equals to 0, violates the range [1, 100000] (test case 1)