# 2020 Multi-University Training Contest 1

## Contest Info

Solved A B C D E F G H I J K L
5 / 12 - - - O Ø Ø - - Ø - Ø -
• O 在比赛中通过
• Ø 赛后通过
• ! 尝试了但是失败了
• - 没有尝试

## Solutions

### D. Distinct Sub-palindromes

Code
// Author : heyuhhh
// Created Time : 2020/07/22 16:16:09
#include<bits/stdc++.h>
using namespace std;
void run() {
int n;
cin >> n;
if (n == 1) {
cout << 26 << '\n';
} else if (n == 2) {
cout << 26 * 26 << '\n';
} else if (n == 3) {
cout << 26 * 26 * 26 << '\n';
} else {
cout << 26 * 25 * 24 << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T; while(T--)
run();
return 0;
}


### E. Fibonacci Sum

Code
// Author : heyuhhh
// Created Time : 2020/07/21 13:25:57
#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, MOD = 1e9 + 9;
const int A = 691504013, B = 308495997, sqrt5 = 383008016, inv5 = 276601605;
template <class T>
inline void rd(T& x) {
x = 0;
char k = getchar();
while (k > '9' || k < '0') k = getchar();
while (k <= '9' && k >= '0') x = x * 10 + k - 48, k = getchar();
}
inline int qpow(ll a, ll b) {
ll res = 1;
if (a >= MOD) a %= MOD;
// if (a > 0) {
//     b %= (MOD - 1);
// } else if (b >= MOD - 1) {
//     b = b % (MOD - 1) + MOD - 1;
// }

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

int fac[N], inv[N], tmp[N];
inline void init() {
fac[0] = 1;
for(int i = 1; i < N; i++) fac[i] = 1ll * fac[i - 1] * i % MOD;
tmp[0] = tmp[1] = inv[0] = inv[1] = 1;
for (int i = 2; i < N; i++) {
tmp[i] = 1ll * (MOD - MOD / i) * tmp[MOD % i] % MOD;
inv[i] = 1ll * inv[i - 1] * tmp[i] % MOD;
}
}

inline int C(int n, int m) {
return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

ll n, c, k;

inline void run() {
rd(n), rd(c), rd(k);
ll ans = 0;
int cv = qpow(inv5, k);
int d = qpow(1ll * A * qpow(B, MOD - 2) % MOD, c);
int b = qpow(qpow(B, k), c);
int dd = qpow(d, n + 1);
int bb = qpow(b, n + 1);
int s1 = 1, s2 = 1;
for (int i = 0; i <= k; ++i) {
int res = C(k, i);
int t = 1ll * b * s1 % MOD;
if (t == 1) {
res = 1ll * ((n + 1) % MOD) * res % MOD;
} else {
int fm = qpow(t - 1, MOD - 2);
int fz = 1ll * bb * s2 % MOD - 1 + MOD;
res = 1ll * res * fz % MOD * fm % MOD;
}
if ((k - i) & 1) ans -= res;
else ans += res;
s1 = 1ll * s1 * d % MOD;
s2 = 1ll * s2 * dd % MOD;
}
ans = ans % MOD * cv % MOD;
if (ans < 0) ans += MOD;
printf("%lld\n", ans);
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
init();
int T; rd(T); while(T--)
run();
return 0;
}


### F. Finding a MEX

• $$1\ u\ x$$，将$$f(u)$$改为$$x$$
• $$2\ u$$，计算$$mex\{f(v)\},(u,v)\in edges$$

• 假设按照度数为$$S$$大小分块，那么小度点度数不超过$$S$$，大度点个数不会超过$$\frac{2m}{S}$$

Code
// Author : heyuhhh
// Created Time : 2020/07/22 10:47:45
#pragma GCC optimize(2)
#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;
void err(int x) {cerr << x;}
void err(long long x) {cerr << x;}
void err(double x) {cerr << x;}
void err(char x) {cerr << '"' << x << '"';}
void err(const string &x) {cerr << '"' << x << '"';}
void _print() {cerr << "]\n";}
template<typename T, typename V>
void err(const pair<T, V> &x) {cerr << '{'; err(x.first); cerr << ','; err(x.second); cerr << '}';}
template<typename T>
void err(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), err(i); cerr << "}";}
template <typename T, typename... V>
void _print(T t, V... v) {err(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef Local
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const int N = 1e5 + 5;
#define FO(n) FastIO::write(n)
#define Flush FastIO::Fflush()
namespace FastIO {
const int SIZE = 1 << 16;
char buf[SIZE], obuf[SIZE], str[60];
int bi = SIZE, bn = SIZE, opt;
double D[] = {0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001, 0.00000001, 0.000000001, 0.0000000001};
while (bn) {
for (; bi < bn && buf[bi] <= ' '; bi++);
if (bi < bn) break;
bn = fread(buf, 1, SIZE, stdin);
bi = 0;
}
int sn = 0;
while (bn) {
for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
if (bi < bn) break;
bn = fread(buf, 1, SIZE, stdin);
bi = 0;
}
s[sn] = 0;
return sn;
}
int n = read(str), bf = 0;
if (!n) return 0;
int i = 0; if (str[i] == '-') bf = 1, i++; else if (str[i] == '+') i++;
for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
if (bf) x = -x;
return 1;
}
if (!n) return 0;
int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
if (bf < 0) x = -x;
return 1;
}
void write(int x) {
if (x == 0) obuf[opt++] = '0';
else {
if (x < 0) obuf[opt++] = '-', x = -x;
int sn = 0;
while (x) str[sn++] = x % 10 + '0', x /= 10;
for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
}
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void write(long long x) {
if (x == 0) obuf[opt++] = '0';
else {
if (x < 0) obuf[opt++] = '-', x = -x;
int sn = 0;
while (x) str[sn++] = x % 10 + '0', x /= 10;
for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
}
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void write(unsigned long long x) {
if (x == 0) obuf[opt++] = '0';
else {
int sn = 0;
while (x) str[sn++] = x % 10 + '0', x /= 10;
for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
}
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void write(char x) {
obuf[opt++] = x;
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void Fflush() { if (opt) fwrite(obuf, 1, opt, stdout); opt = 0;}
};

int n, m;
int a[N];
vector<int> G[N], bG[N];
int bsz;
struct Block {
int Bnum, E, V;
vector<int> Bcnt;
vector<int> Bbel;
vector<int> Bres;
vector<pii> Bdiv;

void init(int x) {
V = sz(G[x]) + 1;
E = sqrt(V + 0.5);
Bnum = 0;
Bcnt.assign(V + 1, 0);
Bbel.assign(V + 1, -1);
Bdiv.clear();
Bres.clear();
for (int i = 0; i <= V; i += E, ++Bnum) {
for (int j = i; j <= min(V, i + E - 1); j++) {
Bbel[j] = Bnum;
}
Bdiv.emplace_back(i, min(i + E - 1, V));
Bres.push_back(0);
}
}

if (x > V) return;
++Bcnt[x];
if (Bcnt[x] == 1) {
++Bres[Bbel[x]];
}
}

void del(int x) {
if (x > V) return;
--Bcnt[x];
if (Bcnt[x] == 0) {
--Bres[Bbel[x]];
}
}

int query() {
for (int i = 0; i < Bnum; i++) {
if (Bdiv[i].se - Bdiv[i].fi + 1 != Bres[i]) {
for (int j = Bdiv[i].fi; j <= Bdiv[i].se; j++) {
if (!Bcnt[j]) {
return j;
}
}
}
}
}
}blk[N];

void run() {
FI(n), FI(m);
bsz = sqrt(m + 0.5);
for (int i = 1; i <= n; i++) {
FI(a[i]);
G[i].clear();
bG[i].clear();
}
for (int i = 1; i <= m; i++) {
int u, v;
FI(u), FI(v);
G[u].push_back(v);
G[v].push_back(u);
}

for (int i = 1; i <= n; i++) {
blk[i].init(i);
}

for (int i = 1; i <= n; i++) {
for (auto j : G[i]) {
if (sz(G[j]) > bsz) {
bG[i].push_back(j);
}
if (sz(G[i]) <= bsz) {
}
}
}

int q;
FI(q);
while (q--) {
int op;
FI(op);
if (op == 1) {
int u, x;
FI(u), FI(x);
if (sz(G[u]) <= bsz) {
for (auto v : G[u]) {
blk[v].del(a[u]);
}
}
a[u] = x;
} else {
int u;
FI(u);
for (auto v : bG[u]) {
}
int ans = blk[u].query();
FO(ans), FO('\n');
for (auto v : bG[u]) {
blk[u].del(a[v]);
}
}
}
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
int T; FI(T); while(T--)
run();
Flush;
return 0;
}


Code
// Author : heyuhhh
// Created Time : 2020/07/22 15:31:28
#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 = 50000 + 5;

int n;
pii a[N];
int q[N], top;
#define FO(n) FastIO::write(n)
#define Flush FastIO::Fflush()
namespace FastIO {
const int SIZE = 1 << 16;
char buf[SIZE], obuf[SIZE], str[60];
int bi = SIZE, bn = SIZE, opt;
double D[] = {0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001, 0.00000001, 0.000000001, 0.0000000001};
while (bn) {
for (; bi < bn && buf[bi] <= ' '; bi++);
if (bi < bn) break;
bn = fread(buf, 1, SIZE, stdin);
bi = 0;
}
int sn = 0;
while (bn) {
for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
if (bi < bn) break;
bn = fread(buf, 1, SIZE, stdin);
bi = 0;
}
s[sn] = 0;
return sn;
}
int n = read(str), bf = 0;
if (!n) return 0;
int i = 0; if (str[i] == '-') bf = 1, i++; else if (str[i] == '+') i++;
for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
if (bf) x = -x;
return 1;
}
if (!n) return 0;
int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
if (bf < 0) x = -x;
return 1;
}
void write(int x) {
if (x == 0) obuf[opt++] = '0';
else {
if (x < 0) obuf[opt++] = '-', x = -x;
int sn = 0;
while (x) str[sn++] = x % 10 + '0', x /= 10;
for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
}
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void write(long long x) {
if (x == 0) obuf[opt++] = '0';
else {
if (x < 0) obuf[opt++] = '-', x = -x;
int sn = 0;
while (x) str[sn++] = x % 10 + '0', x /= 10;
for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
}
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void write(unsigned long long x) {
if (x == 0) obuf[opt++] = '0';
else {
int sn = 0;
while (x) str[sn++] = x % 10 + '0', x /= 10;
for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];
}
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void write(char x) {
obuf[opt++] = x;
if (opt >= (SIZE >> 1)) {
fwrite(obuf, 1, opt, stdout);
opt = 0;
}
}
void Fflush() { if (opt) fwrite(obuf, 1, opt, stdout); opt = 0;}
};
void run() {
FI(n);
for (int i = 1; i <= n; i++) {
FI(a[i].fi), FI(a[i].se);
}
a[n + 1] = MP(0, 0);
sort(a + 1, a + n + 1, [&](pii A, pii B) {
if (A.fi == B.fi) return A.se > B.se;
return A.fi > B.fi;
});
top = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == a[i - 1]) continue;
if (top && a[i].fi <= a[q[top]].fi && a[i].se <= a[q[top]].se) continue;
while (top >= 2 && 1ll * (a[q[top - 1]].fi - a[q[top]].fi) * (a[q[top]].se - a[i].se)
<= 1ll * (a[q[top]].fi - a[i].fi) * (a[q[top - 1]].se - a[q[top]].se)) --top;
q[++top] = i;
}
int ans = top;
// 点重合的情况都不会计算入答案
for (int i = 1; i <= top; i++) {
int x = q[i];
if (a[x] == a[x - 1] || a[x] == a[x + 1]) {
--ans;
}
}
FO(ans), FO('\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; FI(T); while(T--)
run();
Flush;
return 0;
}


### K. Minimum Index

Code
// Author : heyuhhh
// Created Time : 2020/07/22 18:51:06
#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;
void err(int x) {cerr << x;}
void err(long long x) {cerr << x;}
void err(double x) {cerr << x;}
void err(char x) {cerr << '"' << x << '"';}
void err(const string &x) {cerr << '"' << x << '"';}
void _print() {cerr << "]\n";}
template<typename T, typename V>
void err(const pair<T, V> &x) {cerr << '{'; err(x.first); cerr << ','; err(x.second); cerr << '}';}
template<typename T>
void err(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), err(i); cerr << "}";}
template <typename T, typename... V>
void _print(T t, V... v) {err(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef Local
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const int N = 1e5 + 5, MOD = 1e9 + 7;

void run() {
string s;
cin >> s;
int n = s.length();
vector<bool> chk(n);
vector<int> d(n);
d[0] = 1;
int i = 0;
while (i < n) {
int j = i + 1, k = i;
int p = 0;
while (j < n && s[k] <= s[j]) {
if (s[k] < s[j]) {
if (!chk[j]) {
d[j] = i + 1;
}
k = i;
p = 0;
} else {
if (!chk[j]) {
d[j] = d[k] + j - k;
}
++k;
}
chk[j] = true;
++j;
++p;
}
while (i <= k) {
i += j - k;
}
if (i == j && j < n && !chk[j]) {
chk[j] = true;
d[j] = d[k] + j - k;
}
}
int ans = 0;
for (int i = n - 1; i >= 0; i--) {
ans = (1ll * ans * 1112 % MOD + d[i]) % MOD;
}
cout << ans << '\n';
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(falsqe);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}

posted @ 2020-07-25 10:18  heyuhhh  阅读(304)  评论(0编辑  收藏  举报