12赛总结
keep_eating · · 个人记录
比赛总结
T1
题意是预估出
AC代码
#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
有
我们可以同时维护两个桶。在回答的时候,我们只需维护两个指针 p和q,设
AC代码:
#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
这是一个环形染色问题,推导它的公式再用快速幂就是即可,
对于一个有
首位颜色相同,那么把首位两个区域叠成一个区域,那么组成了一个
综合两种情况,得到方程
#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';
}
}
}