一、比赛基本情况
过于惨烈,难以描述。🔞🔞🔞
二、比赛整体回顾
过于唐诗。
T1 比较简单,我半个多小时就写完了。
于是我就磕了 T2 三个小时,啥我😍❤💥🔞都没咳出来。然后我依次写完 T5 T4 T3 的暴力,时间很匆忙,都只打了最基础的分数,我 T4 代码还交错了。
这期间我脑子还在想 T2,终于想出 T2 性质,马上写完了,只不过没清空,100pts 10pts。
三、题目复盘
T1
- 100pts。
思路
-
异或多次是没用的,而且我们可以首先异或。
-
观察小样例,成功得到异或影响的规律(即以值为下标,交换相邻两块),我们就可以一位一位地做🔞。
本题总结
先想清楚再写。
code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5;
int n, b[N], a[N], ans, s[N], cnt;
void add(int x){
x = n - x;
for(; x <= n; x += x & -x) ++s[x];
}
int sum(int x){
x = n - x;
int cnt = 0;
for(; x; x ^= x & -x) cnt += s[x];
return cnt;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) a[b[i] + 1] = i - 1;
for(int i = n / 2; i >= 1; i /= 2){
int zrr = 0, tyk = 0;
for(int l = i + 1, r = 2 * i; r <= n; l += 2 * i, r += 2 * i){
vector<int> p, q;
for(int j = l - i; j <= r - i; j++) p.push_back(a[j]);
for(int j = l; j <= r; j++) q.push_back(a[j]);
sort(p.begin(), p.end());
sort(q.begin(), q.end());
for(int k = 0, j = -1; k < q.size(); k++){
while(j + 1 < p.size() && p[j + 1] < q[k]) ++j;
zrr += j + 1, tyk += p.size() - j - 1;
}
}
if(zrr < tyk) ans ^= i;
}
for(int i = 1; i <= n; i++) b[i] ^= ans;
for(int i = 1; i <= n; i++){
cnt += sum(b[i]); add(b[i]);
}
cout << cnt + bool(ans) << '\n';
return 0;
}T2
- 10pts (100pts)
思路
-
如果合法,邻接矩阵一定和原矩阵相同。
- 为什么?因为很容易瞪出来,而且我们找不到 hack。
-
现在问题是如何判断无解。
-
性质:若距离为偶数,则距离为 。
- 为什么?距离为奇数会连边。
-
于是就可以用 bitset 做啦🔞。
本题总结
-
大胆猜结论。
-
遇到瓶颈时,要优先思考性质。
-
不应死磕,应优先打完70分暴力跑路。🔞🔞🔞🔞🔞
-
bitset 一定要清空!!!🔞
code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2007;
int T, n;
bitset<N> f[N];
void S(){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
f[i][j] = 0;
}
}
cin >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
char zrr; cin >> zrr;
f[i][j] = zrr - '0';
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(!f[i][j]){
bitset<N> zrr = f[i] & f[j];
if(!zrr.count()){
cout << "NO\n"; return;
}
}
}
}
cout << "YES\n";
int cnt = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j < i; j++){
cnt += f[i][j];
}
}
cout << cnt << '\n';
for(int i = 1; i <= n; i++){
for(int j = 1; j < i; j++){
if(f[i][j]) cout << i << ' ' << j << '\n';
}
}
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> T; while(T--) S();
return 0;
}T3
- 20pts
思路
- 转化:考虑如何分组:一开始的答案为 ,一次划分带来的贡献是 。考虑差分,则如果 时选 ,即答案为 。
设 为大间隙,否则为小间隙。
我们可以去枚举大间隙的数量。答案乘上在哪里选大间隙。显然小区间的长度总和为答案剩下的值,因为小间隙有长度上限,利用容斥计算即可。最后还可以把剩余的长度(长度一共是 )分配给大间隙和两端,都是用经典可空插板法。
本题总结
最关键的地方在于最开始的转化。当然,我把大量时间都投给了T2死磕,所以确实不可能做出这道题。🔞🔞🔞
code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e6, mod = 998244353;
int T, n, m, d, k;
int f[N], c[N], fc[N];
int C(int x, int y){
if(y > x || x < 0 || y < 0) return 0;
return f[x] * fc[x - y] % mod * fc[y] % mod;
}
int A(int x, int y){
if(!y) return !x;
int ans = 0;
for(int i = 0, j = 1; i <= y; i++, j *= -1){
if(i * d > x) break;
(ans += j * C(x + y - 1 - i * d, y - 1) * C(y, i)) %= mod;
}
return ans;
}
void S(){
cin >> n >> m >> d >> k;
int ans = 0;
for(int i = 0; i < n; i++){
int zrr = C(n - 1, i);
zrr = zrr * A(k - i * d - d, n - 1 - i) % mod;
zrr = zrr * C(m - k + d + i, i + 1) % mod;
(ans += zrr + mod) %= mod;
}
cout << ans << '\n';
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
f[0] = f[1] = c[1] = fc[0] = fc[1] = 1;
for(int i = 2; i < N; i++){
f[i] = f[i - 1] * i % mod;
c[i] = c[mod % i] * (mod - mod / i) % mod;
fc[i] = fc[i - 1] * c[i] % mod;
}
cin >> T; while(T--) S();
return 0;
}T4
- 0pts
思路
我也不知道。🔞
总结
说到底还是死磕 的问题,暴力都打错了,最后还交错代码了。如果有时间的话,还可以多打一些暴力提升分数。
code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e6, mod = 998244353;
int T, n, m, d, k;
int f[N], c[N], fc[N];
int C(int x, int y){
if(y > x || x < 0 || y < 0) return 0;
return f[x] * fc[x - y] % mod * fc[y] % mod;
}
int A(int x, int y){
if(!y) return !x;
int ans = 0;
for(int i = 0, j = 1; i <= y; i++, j *= -1){
if(i * d > x) break;
(ans += j * C(x + y - 1 - i * d, y - 1) * C(y, i)) %= mod;
}
return ans;
}
void S(){
cin >> n >> m >> d >> k;
int ans = 0;
for(int i = 0; i < n; i++){
int zrr = C(n - 1, i);
zrr = zrr * A(k - i * d - d, n - 1 - i) % mod;
zrr = zrr * C(m - k + d + i, i + 1) % mod;
(ans += zrr + mod) %= mod;
}
cout << ans << '\n';
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
f[0] = f[1] = c[1] = fc[0] = fc[1] = 1;
for(int i = 2; i < N; i++){
f[i] = f[i - 1] * i % mod;
c[i] = c[mod % i] * (mod - mod / i) % mod;
fc[i] = fc[i - 1] * c[i] % mod;
}
cin >> T; while(T--) S();
return 0;
}T5
- 25pts
思路
我也不知道。🔞
总结
剪枝不彻底,以后看到有这种数据小且跨度较小且有【随机】等特殊性质的点,一定要思考一下剪枝,可以多拿 分。
code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 60;
int n, a[N], I, ans[N], cnt[N];
vector<int> v;
void dfs(int x, int l, int sum){
if(sum > ans[I]) return;
if(l + n - x + 1 < I || l > I) return;
if(x > n){
if(sum < ans[l]) ans[l] = sum, cnt[l] = 0;
cnt[l] += sum == ans[l];
return;
}
dfs(x + 1, l, sum);
for(int i : v) sum += i > a[x];
v.push_back(a[x]);
dfs(x + 1, l + 1, sum);
v.pop_back();
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) ans[i] = 1e18;
for(I = 1; I <= n; I++){
dfs(1, 0, 0);
cout << ans[I] << ' ' << cnt[I] << '\n';
}
return 0;
}本场总结
我是奶龙。🍭🍭🍭
最大的问题在于死磕㊗,以后遇到不太可做题,要优先打完所有题的暴力再看,这样心态也会好一些。(分数就更不用说了,我今天的分数还没有暴力分数高💥)。
还有问题是我脑子太蠢了,估计马上就要退役了、、、✅
做的较好的地方
忍住了没有跳楼。👋