upd: 码风已改良
赛时暴力代码
BF T4 15pts
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
struct sch {
int id, t, b, flg;
} c[300010];
struct stu {
int id, l, o, lq;
vector<int> a;
} s[300010];
struct node {
int id, o;
bool operator<(const node &x) const {
return o < x.o;
}
};
int cal() {
priority_queue<node> pq;
int ans = 0;
for (int i = 1; i <= n; i++) pq.push({i, s[i].o});
while (!pq.empty()) {
for (int i = 1; i <= m; i++)
c[i].flg = (c[i].b < c[i].t);
int hscore = pq.top().o;
while (!pq.empty() && pq.top().o == hscore) {
int x = pq.top().id, suc = 0;
pq.pop();
for (int to : s[x].a) {
if (c[to].flg == 1) {
ans += (to != s[x].lq);
c[to].b++, s[x].lq = to, suc = 1;
break;
}
}
if (suc == 0 && s[x].lq != 0)
ans++, s[x].lq = 0;
}
}
return ans;
}
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 1, x; i <= m; i++) {
scanf("%d", &x);
c[i] = {i, x, 0, 0};
}
for (int i = 1, x, z; i <= n; i++) {
scanf("%d", &x);
for (int j = 1, y; j <= x; j++) {
scanf("%d", &y);
s[i].a.push_back(y);
}
scanf("%d", &z);
s[i] = {i, x, z, 0, s[i].a};
}
cal();
for (int T = q, x, v; T; T--) {
for (int i = 1; i <= m; i++) c[i].b = 0;
scanf("%d%d", &x, &v);
c[x].t -= v;
printf("%d\n", cal());
}
return 0;
}