DAY5模拟赛总结
模拟赛总结 DAY5
一、比赛基本情况
- 比赛日期:2026/8/8
- 比赛时长:4.5h
- 比赛得分:270pts
- 比赛排名:略
二、比赛整体回顾
花了大概3个小时做T1 T2(有点慢),导致没时间想T3 T4正解,不过后三题的暴力还是都打了的,最后也检查了。
三、题目复盘
T1:我我的魔法排队
- 本题得分:100pts
- 总用时:1.5h
初始思路
直接把从小到大把
考场解题过程
注意到每个数交换最多花费次数
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e4 + 7;
int n, a[N], lg[N];
vector<pair<int, int>> v;
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
freopen("Apocalypse.in", "r", stdin);
freopen("Apocalypse.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++){
int cnt = 0;
for(int j = 1; j <= n; j++){
if(a[j] == i) cnt = j;
}
while(cnt != i){
int p = (cnt - i + 1) / 2;
v.push_back({cnt - p + 1 - p, cnt});
for(int j = cnt - p + 1; j <= cnt; j++){
swap(a[j - p], a[j]);
}
cnt -= p;
}
}
cout << v.size() << '\n';
for(pair<int, int> i : v){
cout << i.first << ' ' << i.second << '\n';
}
return 0;
}
赛后题解
略。
补题代码
略
复杂度
- 时间复杂度:
O(n^2) - 空间复杂度:
O(n)
本题总结
认真分析时间复杂度,就比如
T2:磁力实验
- 本题得分:100pts
- 总用时:1.5h
初始思路
立刻打表验证结论,最优方案一定是每个
考场解题过程
显然要想
伪结论:只用和最近的一项建边即可。证伪:随便构造,比如
直接使用线段树优化建图即可。
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 7;
int n, a[N], b[N], sum, p[4 * N], Q[N], t[4 * N];
vector<int> s[4 * N];
queue<int> q;
void build(int l, int r, int id){
if(l == r) {p[id] = l, Q[l] = id; return;}
int mid = l + r >> 1;
build(l, mid, id * 2);
build(mid + 1, r, id * 2 + 1);
s[id * 2].push_back(id), ++t[id];
s[id * 2 + 1].push_back(id), ++t[id];
}
void add(int l, int r, int x, int y, int z, int id){
if(x <= l && r <= y){
s[id].push_back(z), ++t[z]; return;
}
int mid = l + r >> 1;
if(x <= mid) add(l, mid, x, y, z, id * 2);
if(y > mid) add(mid + 1, r, x, y, z, id * 2 + 1);
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
freopen("Bonfire.in", "r", stdin);
freopen("Bonfire.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) sum += abs(a[i] - b[i]);
cout << sum << '\n'; build(1, n, 1);
for(int i = 1; i <= n; i++){
int l = 1, r = i, ans = i;
while(l <= r){
int mid = l + r >> 1;
if(abs(a[mid] - b[i]) <= abs(a[i] - b[i])){
ans = mid, r = mid - 1;
}else l = mid + 1;
}
if(ans < i) add(1, n, ans, i - 1, Q[i], 1);
}
for(int i = 1; i <= n; i++){
int l = i + 1, r = n, ans = i;
while(l <= r){
int mid = l + r >> 1;
if(abs(a[mid] - b[i]) < abs(a[i] - b[i])){
ans = mid, l = mid + 1;
}else r = mid - 1;
}
if(ans > i) add(1, n, i + 1, ans, Q[i], 1);
}
for(int i = 1; i < 4 * N; i++) if(!t[i]) q.push(i);
while(!q.empty()){
int x = q.front(); q.pop();
if(p[x]) cout << p[x] << ' ';
for(int i : s[x]) {--t[i]; if(!t[i]) q.push(i);}
}
return 0;
}
赛后题解
略。
补题代码
略。
复杂度
- 时间复杂度:
O(nlogn) - 空间复杂度:
O(n)
本题总结
大胆猜测结论,不过一定不能盲目相信结论。可以使用打表验证,也可以通过构造反例证伪。
T3:符文奥秘
- 本题得分:20pts
- 总用时:暴力
初始思路
补题代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int T, n, k;
int mi(int x, int y){
if(!y) return 1;
int g = mi(x, y / 2);
g = g * g % mod;
return y % 2 ? g * x % mod : g;
}
void S(){
cin >> n >> k;
int g = __gcd(n, k);
int L = n / g;
int p = (mi(2, L) - 1 + mod) % mod;
cout << (mi(p, g) + g * mi(p, g - 1)) % mod << '\n';
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
freopen("Crazy.in", "r", stdin);
freopen("Crazy.out", "w", stdout);
cin >> T; while(T--) S();
return 0;
}
本题总结
略。
T4:蜗蜗的符文树
- 本题得分:25pts
- 总用时:暴力
初始思路
枚举根节点,
考场解题过程
同。
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 7;
int n, mx, f[N];
string t;
vector<int> s[N];
void _dfs(int x, int fa){
f[x] = fa;
for(int i : s[x]) if(i != fa) _dfs(i, x);
}
int dfs(int x, int fa, int zrr){
if(t[x - 1] == ')'){
if(!zrr) return 0;
--zrr;
}else ++zrr;
int ans = 0;
for(int i : s[x]){
if(i == fa) continue;
ans += dfs(i, x, zrr);
}
if(!zrr && !ans) ans = 1;
else if(ans) ++ans;
return ans;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
freopen("Declaration.in", "r", stdin);
freopen("Declaration.out", "w", stdout);
cin >> n >> t;
for(int i = 1; i < n; i++){
int u, v; cin >> u >> v;
s[u].push_back(v), s[v].push_back(u);
}
_dfs(1, 0);
for(int i = 1; i <= n; i++){
mx = max(mx, dfs(i, f[i], 0));
}
cout << mx;
return 0;
}
赛后题解
令
补题代码
// 在此粘贴考场代码
复杂度
- 时间复杂度:
O(n \log^2n)
本题总结
略。
T5考场做法即为暴力3进制状压DP,
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 16, X = 2e7, mod = 998244353;
int n, m, a[N], dp[X], p[N], f[N], ans;
string s;
bool check(){
int tot = 0;
for(int i = 1; i <= n; i++){
if(f[i] == 2){
if(a[++tot] != i) return 0;
}
}
return 1;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
freopen("Expose.in", "r", stdin);
freopen("Expose.out", "w", stdout);
cin >> n >> m >> s;
for(int i = 1; i <= m; i++) cin >> a[i];
sort(a + 1, a + 1 + m);
p[0] = 1;
for(int i = 1; i <= n; i++) p[i] = p[i - 1] * 3;
dp[0] = 1;
for(int i = 0; i < p[n]; i++){
int I = i, cnt = 0, _cnt = 0;
for(int j = 1; j <= n; j++){
f[j] = I % 3, I /= 3;
cnt += f[j] == 2;
_cnt += bool(f[j]) + (f[j] == 2);
}
int zrr = 0;
for(int i = 0; i < _cnt; i++) zrr += s[i] == '-';
if(cnt != zrr) continue;
if(cnt == m && _cnt == m + n) {if(check()) (ans += dp[i]) %= mod; continue;}
if(s[_cnt] == '+'){
for(int j = 1; j <= n; j++){
if(!f[j]) (dp[i + p[j - 1]] += dp[i]) %= mod;
}
}else{
for(int j = 1; j <= n; j++){
if(f[j] == 1){
(dp[i + p[j - 1]] += dp[i]) %= mod;
break;
}
}
}
}
cout << ans << '\n';
return 0;
}
四、整体反思
做得较好的地方
写出了T1T2,打了后三题暴力,检查。
需要改进的地方
没想T3T4正解。
时间安排总结
不要再前面的题过于拖沓,浪费时间想难题正解。
真·总结
我真是太菜了,估计马上就要被优化了。