intmain(){ int T; scanf("%d", &T); while (T --> 0) { scanf("%d", &n); int ans = 0; for (int i = 1; i <= n; ++i) scanf("%d", aa + i); ans += aa[1]; for (int i = 2; i <= n; ++i) { if (aa[i] == 0) continue; // 总是存在一个方法能跳过所有 0 // 而且可以让“我”来打第一个 boss int j = i; for (; j <= n && aa[j] == 1; ++j); --j; ans += (j - i + 1) / 3; i = j; // “我”打两个 boss,我朋友打一个 boss // 三个 boss 对答案的贡献是 1 } printf("%d\n", ans); } return0; }
inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
intmain(){ n = read(); q = read(); for (int i = 1; i <= n; ++i) { trash.insert(read()); } int _last = 0; for (auto v : trash) { if (_last) dist.insert(v - _last); _last = v; } totalCleanUp(); while (q --> 0) { int t = read(); int x = read(); if (t) { // add if (trash.size() == 0) { trash.insert(x); totalCleanUp(); continue; } int premin = minset(trash); int premax = maxset(trash); if (x < premin) { // +x+ a b c d e f ... dist.insert(premin - x); trash.insert(x); } elseif (premax < x) { // ... c d e f +x+ dist.insert(x - premax); trash.insert(x); } else { // ... c d +x+ e f ... auto it = trash.upper_bound(x); auto tit = it; it--; // it -> &d, tit -> &e dist.erase(dist.find((*tit) - (*it))); dist.insert(x - (*it)); dist.insert((*tit) - x); trash.insert(x); } } else { // remove if (trash.size() == 1) { trash.erase(x); totalCleanUp(); continue; } int premin = minset(trash); int premax = maxset(trash); if (x == premin) { // -x- a b c d ... auto it = trash.begin(); it++; // &a erasedist((*it) - x); trash.erase(x); } elseif (premax == x) { // ... c d e f -x-; auto it = trash.rbegin(); it++; // &f erasedist(x - (*it)); trash.erase(x); } else { // ... c d -x- e f ... auto it = trash.find(x); // &x auto previt = it; --previt; auto nextit = it; ++nextit; erasedist((*nextit) - x); erasedist(x - (*previt)); dist.insert((*nextit) - (*previt)); trash.erase(x); } } totalCleanUp(); } return0; }
E. Expected Damage
题意简述
又要打怪了。现在有 n + m 个怪物,每个怪物有能力值,仍然按能力值分为大怪和小怪。不同的是,这次没有队友陪你,只有一把耐久为 的剑。对于当前遇到的怪物,有三种可能的情况:
constint MAXN = 200000 + 10; constint ha = 998244353;
int n, m; int d[MAXN]; longlongint pref[MAXN];
longlongintfastpow(int a, int b = ha - 2, int p = ha){ int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % p; a = 1ll * a * a % p; b >>= 1; } return ret; }
intmain(){ scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", d + i); std::sort(d + 1, d + 1 + n); for (int i = 1; i <= n; ++i) pref[i] = (pref[i - 1] + d[i]); while (m --> 0) { longlongint dura, rat; scanf("%lld %lld", &dura, &rat); longlongint possmall = 0; // for (; possmall <= n && rat > d[possmall]; ++possmall); --possmall; possmall = (std::lower_bound(d + 1, d + 1 + n, rat) - d - 1); // debug(possmall); longlongint sumsmall = pref[possmall], sumbig = pref[n] - pref[possmall]; if (dura > n - possmall) puts("0"); elseprintf("%lld\n", (1ll * ( sumbig + sumsmall - 1ll * sumbig * dura % ha * fastpow(n - possmall) % ha - 1ll * sumsmall * dura % ha * fastpow(n - possmall + 1) % ha + ha + ha) % ha) % ha); } return0; }