Codeforces Round 993 (Div. 4)
2024.12.15 rank289 +123:1381->1504
A
Cube is given an integer n n n. She wants to know how many ordered pairs of positive integers ( a , b ) (a,b) (a,b) there are such that a = n − b a=n-b a=n−b. Since Cube is not very good at math, please help her!
B
A string consisting of only characters ‘p’, ‘q’, and ‘w’ is painted on a glass window of a store. Ship walks past the store, standing directly in front of the glass window, and observes string a a a. Ship then heads inside the store, looks directly at the same glass window, and observes string b b b.
Ship gives you string a a a. Your job is to find and output b b b.
C
Ball is the teacher in Paperfold University. The seats of his classroom are arranged in 2 2 2 rows with m m m seats each.
Ball is teaching a + b + c a + b + c a+b+c monkeys, and he wants to assign as many monkeys to a seat as possible. Ball knows that a a a of them only want to sit in row 1 1 1, b b b of them only want to sit in row 2 2 2, and c c c of them have no preference. Only one monkey may sit in each seat, and each monkey’s preference must be followed if it is seated.
What is the maximum number of monkeys that Ball can seat?
D
Given a sequence of positive integers, a positive integer is called a mode of the sequence if it occurs the maximum number of times that any positive integer occurs. For example, the mode of [ 2 , 2 , 3 ] [2,2,3] [2,2,3] is 2 2 2. Any of 9 9 9, 8 8 8, or 7 7 7 can be considered to be a mode of the sequence [ 9 , 9 , 8 , 8 , 7 , 7 ] [9,9,8,8,7,7] [9,9,8,8,7,7].
You gave UFO an array a a a of length n n n. To thank you, UFO decides to construct another array b b b of length n n n such that a i a_i ai is a mode of the sequence [ b 1 , b 2 , … , b i ] [b_1, b_2, \ldots, b_i] [b1,b2,…,bi] for all 1 ≤ i ≤ n 1 \leq i \leq n 1≤i≤n.
However, UFO doesn’t know how to construct array b b b, so you must help her. Note that 1 ≤ b i ≤ n 1 \leq b_i \leq n 1≤bi≤n must hold for your array for all 1 ≤ i ≤ n 1 \leq i \leq n 1≤i≤n.
E
Wave is given five integers k k k, l 1 l_1 l1, r 1 r_1 r1, l 2 l_2 l2, and r 2 r_2 r2. Wave wants you to help her count the number of ordered pairs ( x , y ) (x, y) (x,y) such that all of the following are satisfied:
- l 1 ≤ x ≤ r 1 l_1 \leq x \leq r_1 l1≤x≤r1.
- l 2 ≤ y ≤ r 2 l_2 \leq y \leq r_2 l2≤y≤r2.
- There exists a non-negative integer n n n such that y x = k n \frac{y}{x} = k^n xy=kn.
G1
This is the easy version of the problem. The key difference between the two versions is highlighted in bold.
A group of n n n spiders has come together to exchange plushies. Initially, each spider has 1 1 1 plushie. Every year, if spider i i i has at least one plushie, he will give exactly one plushie to spider r i r_i ri. Otherwise, he will do nothing. Note that all plushie transfers happen at the same time. In this version, if any spider has more than 1 1 1 plushie at any point in time, they will throw all but 1 1 1 away.
The process is stable in the current year if each spider has the same number of plushies (before the current year’s exchange) as he did the previous year (before the previous year’s exchange). Note that year 1 1 1 can never be stable.
Find the first year in which the process becomes stable.
------------------------独自思考分割线------------------------
A
- 发现答案为n-1。
B
- 首先字符反转,p/q再反转。
C
- 贪心a,b,再贪心c。
D
- 比较有意思的构造。
E
- 暴力思路肯定会T,考虑优化:发现合法的对于每个k,合法区间 l 1 ≤ l ≤ r ≤ r 1 l_1 \leq l \leq r \leq r_1 l1≤l≤r≤r1。
- 同时k的取值很小。考虑两次二分找合法范围。
G1
- 模拟过程找到循环。
------------------------代码分割线------------------------
A
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;cout << n - 1 << endl;
}
B
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{string s;cin >> s;reverse(s.begin(), s.end());for (auto &v : s)if (v - 'w')v = v == 'p' ? 'q' : 'p';cout << s << endl;
}
C
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int m, a, b, c;cin >> m >> a >> b >> c;int res = 0, n1 = m, n2 = m;res += min(n1, a);n1 -= min(n1, a);res += min(n2, b);n2 -= min(n2, b);res += min(n1 + n2, c);cout << res << endl;
}
D
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<int> a(n);map<int, int> has, in;for (int &v : a)cin >> v, has[v] = 1;queue<int> no_has;for (int i = 1; i <= n; i++)if (!has[i])no_has.push(i);for (int i = 0; i < n; i++)if (i){if (a[i] == a[i - 1] || in[a[i]]){cout << no_has.front() << ' ';in[no_has.front()] = 1;no_has.pop();}elsecout << a[i] << ' ', in[a[i]] = 1;}elsecout << a[i] << " ", in[a[i]] = 1;cout << endl;
}
E
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int k, l1, r1, l2, r2;cin >> k >> l1 >> r1 >> l2 >> r2;int base = 1;int res = 0;for (; l1 * base <= r2; base *= k){int l = l1 - 1, r = r1 + 1;while (r - l - 1){int mid = l + r >> 1;if (mid * base <= r2)l = mid;elser = mid;}// bug2(l, l * base);int u = l;if (u < l1)continue;l = l1 - 1, r = u + 1;while (r - l - 1){int mid = l + r >> 1;if (mid * base >= l2)r = mid;elsel = mid;}if (r > u)continue;res += u - r + 1;}cout << res << endl;
}
G1
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<int> a(n + 1);map<int, int> has;for (int i = 1; i <= n; i++){cin >> a[i];has[a[i]]++;}vector<int> no_has;for (int i = 1; i <= n; i++)if (!has[i])no_has.push_back(i);for (int i = 2;; i++){if (no_has.size() == 0){cout << i << endl;return;}vector<int> vec;for (auto v : no_has){has[a[v]]--;if (has[a[v]] == 0)vec.push_back(a[v]);}no_has = vec;}
}