# Educational Codeforces Round 95 (Rated for Div. 2)

Code
// Author : heyuhhh
// Created Time : 2020/09/14 22:39:56
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
void run() {
ll x, y, k;
cin >> x >> y >> k;
ll a = (k * (1 + y) - 1 + x - 2) / (x - 1);
ll ans = a + k;
cout << ans << '\n';
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while (T--)
run();
return 0;
}


### C. Mortal Kombat Tower

Code
// Author : heyuhhh
// Created Time : 2020/09/14 23:00:27
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
void chkmin(int& x, int y) {
if (x > y) x = y;
}
void run() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> dp(n + 1, vector<int>(2, INF));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) if (dp[i][j] != INF) {
if (j == 0) {
chkmin(dp[i + 1][1], dp[i][j] + a[i]);
if (i + 2 <= n) {
chkmin(dp[i + 2][1], dp[i][j] + a[i] + a[i + 1]);
}
} else {
chkmin(dp[i + 1][0], dp[i][j]);
if (i + 2 <= n) {
chkmin(dp[i + 2][0], dp[i][j]);
}
}
}
}
int ans = min(dp[n][0], dp[n][1]);
cout << ans << '\n';
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}


### D. Trash Problem

Code
// Author : heyuhhh
// Created Time : 2020/09/14 23:29:47
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
void run() {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(all(a));
set<int> s;
multiset<int> t;
int last = -1;
ll ans = 0;
for (int i = 0; i < n; i++) {
int p = a[i];
s.insert(p);
if (last != -1) {
t.insert(p - last);
ans += p - last;
}
last = p;
}
cout << ans - (sz(t) > 0 ? *t.rbegin() : 0) << '\n';
while (q--) {
int op, x;
cin >> op >> x;
if (op) {
auto it = s.lower_bound(x);
int prev = -1, succ = -1;
if (it != s.end()) {
succ = *it;
t.insert(succ - x);
ans += succ - x;
}
if (it != s.begin()) {
--it;
prev = *it;
t.insert(x - prev);
ans += x - prev;
}
s.insert(x);
if (prev != -1 && succ != -1) {
t.erase(t.lower_bound(succ - prev));
ans -= succ - prev;
}
} else {
auto it = s.upper_bound(x);
int prev = -1, succ = -1;
if (it != s.end()) {
succ = *it;
t.erase(t.lower_bound(succ - x));
ans -= succ - x;
}
--it;
if (it != s.begin()) {
--it;
prev = *it;
t.erase(t.lower_bound(x - prev));
ans -= x - prev;
}
s.erase(x);
if (prev != -1 && succ != -1) {
t.insert(succ - prev);
ans += succ - prev;
}
}
cout << ans - (sz(t) > 0 ? *t.rbegin() : 0) << '\n';
}
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}


### E. Expected Damage

$$n$$ 只怪物，每只的攻击力为 $$d_i$$

• 如果 $$a=0$$，那么直接造成伤害；
• 如果 $$a>0$$ 并且 $$d_i\geq b$$，那么耐久度减一；
• 否则什么都没发生。

Code
// Author : heyuhhh
// Created Time : 2020/09/15 00:14:40
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 5, MOD = 998244353;

int qpow(ll a, ll b) {
ll res = 1;
while(b) {
if(b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}

void run() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(all(a));
vector<ll> pre(n), suf(n);
pre[0] = a[0];
for (int i = 1; i < n; i++)
pre[i] = (pre[i - 1] + a[i]) % MOD;
suf[n - 1] = a[n - 1];
for (int i = n - 2; i >= 0; i--)
suf[i] = (suf[i + 1] + a[i]) % MOD;

for (int i = 0; i < m; i++) {
int A, B;
cin >> A >> B;
int t = lower_bound(all(a), B) - a.begin();
int tot = n - t;
if (tot < A) {
cout << 0 << '\n';
continue;
}
int ans = 1ll * (1 - 1ll * A * qpow(tot, MOD - 2) % MOD + MOD) % MOD * suf[t] % MOD;
if (t) {
ans = (ans + 1ll * pre[t - 1] * (1 - 1ll * A * qpow(tot + 1, MOD - 2) % MOD + MOD) % MOD) % MOD;
}
cout << ans << '\n';
}
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}


### G. Three Occurrences

Code
// Author : heyuhhh
// Created Time : 2020/09/15 19:23:18
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 5e5 + 5;

int n;
int a[N];
int minv[N << 2], cntv[N << 2], lz[N << 2];
void tag(int o, int l, int r, int v) {
minv[o] += v;
lz[o] += v;
}

void push_up(int o) {
minv[o] = min(minv[o << 1], minv[o << 1|1]);
cntv[o] = 0;
if (minv[o << 1] == minv[o]) cntv[o] = cntv[o << 1];
if (minv[o << 1|1] == minv[o]) cntv[o] += cntv[o << 1|1];
}

void push_down(int o, int l, int r) {
if(lz[o] != 0) {
int mid = (l + r) >> 1;
tag(o << 1, l, mid, lz[o]);
tag(o << 1|1, mid + 1, r, lz[o]);
lz[o] = 0;
}
}

void build(int o, int l, int r) {
lz[o] = 0;
if(l == r) {
minv[o] = 0;
cntv[o] = 1;
return;
}
int mid = (l + r) >> 1;
build(o << 1, l, mid), build(o << 1|1, mid + 1, r);
push_up(o);
}

void update(int o, int l, int r, int L, int R, ll v) {
if(L <= l && r <= R) {
tag(o, l, r, v);
return;
}
push_down(o, l, r);
int mid = (l + r) >> 1;
if(L <= mid) update(o << 1, l, mid, L, R, v);
if(R > mid) update(o << 1|1, mid + 1, r, L, R, v);
push_up(o);
}

int query(int o, int l, int r, int L, int R) {
if(L <= l && r <= R) {
if (minv[o] == 0) return cntv[o];
return 0;
}
push_down(o, l, r);
int mid = (l + r) >> 1;
int res = 0;
if(L <= mid) res = query(o << 1, l, mid, L, R);
if(R > mid) res += query(o << 1|1, mid + 1, r, L, R);
return res;
}

void run() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<vector<int>> pos(n + 1);
build(1, 1, n);

for (int i = 1; i <= n; i++) {
pos[i].emplace_back(n + 1);
}
auto Add = [&] (int x, int v) {
int third = pos[a[x]][sz(pos[a[x]]) - 3];
int fourth = pos[a[x]][sz(pos[a[x]]) - 4];
update(1, 1, n, third, fourth - 1, v);
};
ll ans = 0;
for (int l = n; l >= 1; l--) {
if (sz(pos[a[l]]) >= 4) {
}
pos[a[l]].emplace_back(l);
if (sz(pos[a[l]]) >= 4) {
}
int second = pos[a[l]][sz(pos[a[l]]) - 2];
update(1, 1, n, l, second - 1, 1);
ans += query(1, 1, n, l, n);
}
cout << ans << '\n';
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}

posted @ 2020-09-15 22:34  heyuhhh  阅读(357)  评论(0编辑  收藏  举报