跳到正文

个人记录

12赛总结

keep_eating约 6 分钟
原文
文章信息与版本

文章信息

发布
2025年10月7日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 6 分钟

版本

  1. v2当前
  2. v1

比赛总结

T1

题意是预估出 lukeluke 的最大排名和最小排名。 我们可以统计有多少人至少一场比赛比 lukeluke 高,多少人至少一场比赛比 lukeluke 低即可。

AC代码

C++
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE and cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long
#define re register
#define inl inline
const int P = 998244353;
const int Base = 322225477;
const int INF = 0x3f3f3f3f3f3f3f3f;

const int N = 1e6 + 10, M = 2e3 + 10;
int n,m;
int a[N];
int ma,mi;
signed main(){
	fst
	cin>>n>>m;
	ma=m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ma-=m-a[i];
		mi+=a[i]-1;
	}
	cout<<max(1LL,ma)<<endl<<min(mi+1,m);
	return 0;
}
/*
4 5 6 6 5 6

*/

T2

有 nn 次输入和输出,每一轮将2个球分别放入 ,前 ii 轮中放入袋子 AA 和袋子 BB 的所有数字一一配对后,和最大的一对的最小值。

我们可以同时维护两个桶。在回答的时候,我们只需维护两个指针 p和q,设 totAptotA_p 和 totBqtotB_q 的较小者为 TT ,将两者都减去TT ,得到 TT 对 (totAp,totBq)(totA_p,totB_q),然后继续移动两个指针即可。

AC代码:

C++
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long
#define re register
#define inl inline
const int P = 998244353;
const int Base = 322225477;
const int INF = 0x3f3f3f3f3f3f3f3f;

const int N = 1e6 + 10, M = 2e3 + 10;
int n;
int a[N],b[N];
int tot1[N],tot2[N];
int max1,max2;
int tmp[N],tmp2[N]
signed main(){
	fst
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		tot1[x]++;
		tot2[y]++;
		max1=max(max1,x);
		max2=max(max2,y);
		for(int i=1;i<=100;i++){
			tmp[i]=tot1[i],tmp2[i]=tot2[i];
		}
		int l=0,r=max2,ans=0;
		while(true){
			while(tmp[l]==0 and l<=max1){
				l++;
			}
			if(l>max1){
				break;
			}
			while(tmp2[r]==0){
				r--;
			}
			int minv=min(tmp[l],tmp2[r]);
			tmp[l]-=minv;
			tmp2-=minv;
			ans=max(ans,l+r);
		}
		cout<<ans<<endl;
	}
	return 0;
}

T3

这是一个环形染色问题,推导它的公式再用快速幂就是即可, 对于一个有 nn 个区域环,有mm 个颜色可以选择,相邻的石块不能涂一样的颜色,将环从某两个区域分开,展开为一个线性排列,那么相邻元素不同的排列有 m(m−1)n−1m(m-1)^{n-1} 种,设 nn 个区域的环的涂色方案有ana_n 种,那么线性排列首位颜色有两种情况,

首位颜色相同,那么把首位两个区域叠成一个区域,那么组成了一个 n−1n-1 个区域的环,就等于 an−1a_{n-1} 首位颜色不同,那么直接拼接首位成为一个mm 个区域的环,就等于 ana_n

综合两种情况,得到方程 an+an−1=m(m−1)n−1a_n+a_{n-1}=m(m-1)^{n-1} ,所以 an=m(m−1)n−1+(−1)n(m−1)a_n=m(m-1)^{n-1}+(-1)^n(m-1)

C++
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long
#define re register
#define inl inline
const int P = 1e9 + 7;
const int Base = 322225477;
const int INF = 0x3f3f3f3f3f3f3f3f;

const int N = 1e6 + 10, M = 2e3 + 10;
inl int fun(int n, int m){
    int base = m-1, nub = n,ans = 1;
    while(nub){
        if(nub&1) ans = ans%P*base%P;
        nub /= 2;
        base = base%P*base%P;

    }
    return ans + (n&1 ? -(m-1):(m-1));
}
signed main(){
    fst
    int t;
    cin >> t;
    while(t--){
        int n, m;
        cin >> n >> m;
        if(n == 1) cout << m%P << '\n';
        else if(n == 2) cout << m%P*(m-1)%P << '\n';
        else if(n == 3) cout << m%P*(m-1)%P*(m-2) << '\n';
        else {
            cout << fun(n,m) %P<< '\n';
        }
    }
}
原文