#include<cstdio>#include<iostream>#include<algorithm>#define RI register int#define CI const int&usingnamespace std;
constint N=1e6+5,mod=998244353,INF=1e9;
int n,a[N],c[N],fact[N];
inlinevoidinit(CI n){
fact[0]=1; for (RI i=1;i<=n;++i) fact[i]=1LL*fact[i-1]*i%mod;
}
intmain(){
scanf("%d",&n); init(n);
for (RI i=1;i<=n;++i) scanf("%d",&a[i]),++c[a[i]];
sort(a+1,a+n+1); longlong ans=0;
for (RI i=1;i<=n;++i)
{
int mn=INF,mx=-INF;
for (RI j=i;j<=n;++j)
{
mn=min(mn,a[j]); mx=max(mx,a[j]);
ans+=mx-mn;
}
}
int cnt=1,tp=0;
for (RI i=1;i<=1000000;++i)
if (c[i]!=0) cnt=1LL*cnt*fact[c[i]]%mod,++tp;
if (tp!=1) cnt=2LL*cnt%mod;
returnprintf("%lld %d",ans,cnt),0;
}
#include<cstdio>#include<iostream>#define RI register int#define CI const int&usingnamespace std;
constint N=100005,mod=998244353;
int n,m,f[N][26],fact[N],ifac[N];
inlinevoidinc(int& x,CI y){
if ((x+=y)>=mod) x-=mod;
}
inlineintquick_pow(int x,int p=mod-2,int mul=1){
for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inlinevoidinit(CI n){
fact[0]=1; for (RI i=1;i<=n;++i) fact[i]=1LL*fact[i-1]*i%mod;
ifac[n]=quick_pow(fact[n]); for (RI i=n-1;i>=0;--i) ifac[i]=1LL*ifac[i+1]*(i+1)%mod;
}
inlineintC(CI n,CI m){
if (n<0||m<0||n<m) return0;
return1LL*fact[n]*ifac[m]%mod*ifac[n-m]%mod;
}
intmain(){
scanf("%d%d",&n,&m);
int mx=1,sum=0;
if (m>=1) inc(mx,min(26,n));
if (m>=2) inc(mx,min(26*26,n));
if (m>=3) inc(mx,min(26*26*26,n));
if (m>=4) inc(mx,1LL*n*(m-3)%mod);
for (RI i=0;i<=m;++i)
{
int c=quick_pow(26,i);
inc(sum,1LL*c*(1-quick_pow((1-quick_pow(c)+mod)%mod,n)+mod)%mod);
}
returnprintf("%d %d",mx,sum),0;
}
#include<cstdio>#include<iostream>#include<cstring>#include<queue>#define RI register int#define CI const int&usingnamespace std;
constint N=1005,INF=1e9;
int n,m,a[N],v[N],x,y,w;
namespace Network_Flow
{
constint NN=2005,MM=5e6;
structedge {
int to,nxt,v;
}e[MM<<1]; int cnt=1,head[NN],cur[NN],dep[NN],s,t;
inlinevoidaddedge(CI x,CI y,CI z){
//printf("%d -> %d (%d)\n",x,y,z); e[++cnt]=(edge){y,head[x],z}; head[x]=cnt;
e[++cnt]=(edge){x,head[y],0}; head[y]=cnt;
}
#define to e[i].toinlineboolBFS(void){
memset(dep,0,(s+1)*sizeof(int));
dep[s]=1; queue <int> q; q.push(s);
while (!q.empty())
{
int now=q.front(); q.pop();
for (RI i=head[now];i;i=e[i].nxt)
if (e[i].v&&!dep[to]) dep[to]=dep[now]+1,q.push(to);
}
return dep[t];
}
inlineintDFS(CI now,CI tar,int dis){
if (now==tar) return dis; int ret=0;
for (RI& i=cur[now];i&&dis;i=e[i].nxt)
if (e[i].v&&dep[to]==dep[now]+1)
{
int dist=DFS(to,tar,min(dis,e[i].v));
if (!dist) dep[to]=INF;
dis-=dist; ret+=dist;
e[i].v-=dist; e[i^1].v+=dist;
if (!dis) return ret;
}
if (!ret) dep[now]=INF; return ret;
}
#undef toinlineintDinic(int ret=0){
while (BFS()) memcpy(cur,head,(s+1)*sizeof(int)),ret+=DFS(s,t,INF); return ret;
}
};
usingnamespace Network_Flow;
intmain(){
scanf("%d%d",&n,&m); t=n+m+1;
for (RI i=1;i<=n;++i) scanf("%d%d",&a[i],&v[i]);
for (RI i=1;i<=m;++i)
{
scanf("%d%d%d",&x,&y,&w);
if (x==y) v[x]+=w; else {
addedge(n+i,t,w);
addedge(x,n+i,INF);
addedge(y,n+i,INF);
}
}
for (RI i=1;i<=n;++i) if (v[i]>a[i]) returnputs("NO"),0;
s=n+m+2; addedge(s,1,a[1]-v[1]);
Dinic(); int lim;
for (RI i=head[s];i;i=e[i].nxt) lim=v[1]+e[i^1].v;
s=n+m+3;
for (RI i=2;i<=n;++i)
{
int bd=min(a[i],lim-1);
if (v[i]>bd) returnputs("NO"),0;
addedge(s,i,bd-v[i]);
}
Dinic();
for (RI i=n+1;i<=n+m;++i)
{
for (RI j=head[i];j;j=e[j].nxt)
if (e[j].to==t)
{
if (e[j].v!=0) returnputs("NO"),0;
}
}
returnputs("YES"),0;
}
9|0H. 另一个游戏
防 AK 数据结构题,鉴定为弃疗
10|0I. 找行李
被徐神 solo 了,ORZ
这类问题一眼考虑容斥,令 gx 表示答案至少为 x 的方案数,最后相邻的项作差即可得到答案恰好为 x 的方案数
计算 gx 也很简单,首先将人和行李排序,那么一个人 i 能选的行李一定是一段前缀;且第 i+1 个人能选的行李一定包含了第 i 个人的,因此很好计算方案数
单次 DP 的复杂度为 O(n2),总复杂度 O(n3)
#include<bits/stdc++.h>using llsi = longlongsignedint;
constexprint mod = 998244353;
intksm(int a, int b){
int c = 1;
while(b) {
if(b & 1) c = llsi(c) * a % mod;
a = llsi(a) * a % mod;
b >>= 1;
}
return c;
}
int fac[502], facinv[502];
voidinit(int n){
fac[0] = 1;
for(int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * llsi(i) % mod;
facinv[n] = ksm(fac[n], mod - 2);
for(int i = n; i >= 1; --i) facinv[i - 1] = facinv[i] * llsi(i) % mod;
return;
}
intC(int a, int b){
returnllsi(fac[a]) * facinv[b] % mod * facinv[a - b] % mod;
}
int w[502];
int dp[502][502];
inlinevoidadd(int &a, constint &b){
if((a += b) >= mod) a -= mod;
}
intget_dp(int n){
// for(int i = 1; i <= n; ++i) std::cerr << w[i] << char(i == n ? 10 : 32); dp[0][0] = 1; w[0] = 0;
for(int i = 0; i < n; ++i) {
memset(dp[i + 1], 0, sizeof(dp[i + 1]));
for(int j = 0; j <= w[i]; ++j) {
add(dp[i + 1][j], dp[i][j]);
if(j + 1 <= w[i + 1])
add(dp[i + 1][j + 1], llsi(dp[i][j]) * llsi(w[i + 1] - j) % mod);
}
}
int ans = mod - 1;
for(int i = 0; i <= w[n]; ++i) add(ans, dp[n][i]);
return ans;
}
int n, m, a[502], b[502], hkr[502];
intmain(){
std::ios::sync_with_stdio(false);
int n, m; std::cin >> n >> m;
for(int i = 1; i <= n; ++i) std::cin >> a[i];
for(int j = 1; j <= m; ++j) std::cin >> b[j];
std::sort(a + 1, a + n + 1);
std::sort(b + 1, b + m + 1);
for(int x = 1; x <= 500; ++x) {
for(int i = 1; i <= m; ++i) {
w[i] = 0;
while(w[i] < n && b[i] - x >= a[w[i] + 1]) w[i]++;
}
hkr[x] = get_dp(m);
// if(x <= 5) std::cout << hkr[x] << char(10); }
int ans = 0;
for(int x = 1; x <= 500; ++x) add(ans, llsi(mod + hkr[x] - hkr[x + 1]) * x % mod);
std::cout << ans << char(10);
return0;
}
11|0J. 找最小
唉沟槽的线性基还在追杀我,但无所谓我有队友
考虑先求出两个序列的异或和 A,B,同时令 ci=ai⊕bi,则修改位置 i 相当于让 A,B 同时异或上 ci
考虑将所有 ci 加入线性基中,然后进行一个按位贪心即可;题解的实现较为简单,以下代码是祁神赛时实现的,由于写了对拍可读性较差
#include<bits/stdc++.h>usingnamespace std;
#define int long longconstint R = 35;
structLinebase{
int p[R];
voidinit(){
for (int i=R-1; i>=0; --i) p[i]=0;
}
inlinevoidinsert(int x){
for (int i=R-1; i>=0; --i) if ((x>>i)&1){
if (!p[i]) return (void)(p[i]=x); x^=p[i];
}
}
boolcheck(int x, int pos){
for (int i=R-1; i>=pos; --i) if ((x>>i)&1){
if (0==p[i] && ((x>>i)&1)) returnfalse;
x^=p[i];
}
returntrue;
}
}base;
constint INF = (int)1e18+5;
constint N = 1e6+5;
int n, A[N], B[N], C[N], xorA, xorB;
intbf(){
int ans=INF;
for (int i=0; i<(1LL<<n); ++i){
int resA=0, resB=0;
for (int j=0; j<n; ++j){
if ((i>>j)&1) resA^=A[j+1], resB^=B[j+1];
else resA^=B[j+1], resB^=A[j+1];
}
ans = min(ans, max(resA, resB));
}
return ans;
}
voidmakedata(int n_){
n = n_;
constint AA = 4;
for (int i=1; i<=n; ++i) A[i] = rand()%AA, B[i] = rand()%AA;
}
voidreadd(){
cin >> n;
for (int i=1; i<=n; ++i) cin >> A[i];
for (int i=1; i<=n; ++i) cin >> B[i];
}
boolsolve(){
readd();
// makedata(4);int bfans = bf();
base.init();
xorA = xorB = 0;
for (int i=1; i<=n; ++i) xorA^=A[i], xorB^=B[i];
for (int i=1; i<=n; ++i) C[i] = (A[i]^B[i]), base.insert(C[i]);
// printf("xorA=%lld xorB=%lld\n", xorA, xorB);// printf("base:\n");// for (int i=0; i<4; ++i) {// printf("i=%lld : %lld\n", i, base.p[i]);// }int cur=0, pos=-1;
int xxx = xorA^xorB;
for (int i=R-1; i>=0; --i){
if ((xxx>>i)&1) {pos=i; break;}
bool ok0 = base.check(cur, i);
bool ok1 = base.check(cur|(1LL<<i), i);
if (ok0 && ok1){
if ((xorA>>i)&1) cur |= (1LL<<i);
}elseif (ok1) cur |= (1LL<<i);
}
// printf("cur=%lld pos=%lld\n", cur, pos);int resA = xorA^cur, resB = xorB^cur;
int ans = INF;
// printf("cur=%lld resA=%lld resB=%lld\n", cur, resA, resB);if (pos<0) ans = max(xorA^cur, xorB^cur);
else {
for (int h=0; h<2; ++h){
cur &= (1LL<<R) - (1LL<<pos);
cur ^= (1LL<<pos);
resA = xorA^cur, resB = xorB^cur;
// printf("cur=%lld resA=%lld resB=%lld\n", cur, resA, resB);// printf("base.check(%lld, %lld)=%lld\n", cur, pos, base.check(cur, pos));if (!base.check(cur, pos)) continue;
for (int i=pos-1; i>=0; --i){
bool ok0 = base.check(cur, i);
bool ok1 = base.check(cur|(1LL<<i), i);
// printf("i=%lld ok0=%d ok1=%d\n", i, ok0, ok1);if (ok0 && ok1){
// printf("(%lld %lld)(%lld %lld)\n", resA, resB, resA^(1LL<<i), resB^(1LL<<i) );if (max(resA, resB) > max(resA^(1LL<<i), resB^(1LL<<i))) cur |= (1LL<<i);
}elseif (ok1) cur |= (1LL<<i);
resA = xorA^cur, resB = xorB^cur;
// printf("cur=%lld resA=%lld resB=%lld\n", cur, resA, resB); }
// printf("resA=%lld %lld\n", resA, resB); ans = min(ans, max(resA, resB));
}
}
cout << ans << '\n';
// if (ans!=bfans){// // printf("n=%lld\n", n);// for (int i=1; i<=n; ++i) printf("%lld ", A[i]);// for (int i=1; i<=n; ++i) printf("%lld ", B[i]);// // printf("ans=%lld bfans=%lld\n", ans, bfans);// return false;// }else printf("ans=%lld bfans=%lld\n", ans, bfans);returntrue;
}
signedmain(){
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) solve();
// while (solve()) {break;}return0;
}
12|0K. 取沙子游戏
祁神开场一眼秒了,我题意都不知道
#include<bits/stdc++.h>usingnamespace std;
int n, k;
intlb(int x){return x&(-x);}
voidsolve(){
cin >> n >> k;
if (lb(n) <= k) cout << "Alice\n";
else cout << "Bob\n";
}
signedmain(){
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t; while (t--) solve();
return0;
}
13|0L. 网络预选赛
签到,枚举即可
#include<cstdio>#include<iostream>#define RI register int#define CI const int&usingnamespace std;
constint N=505;
int n,m; char s[N][N];
intmain(){
scanf("%d%d",&n,&m); int ans=0;
for (RI i=1;i<=n;++i) scanf("%s",s[i]+1);
for (RI i=1;i+1<=n;++i) for (RI j=1;j+1<=m;++j)
if (s[i][j]=='c'&&s[i][j+1]=='c'&&s[i+1][j]=='p'&&s[i+1][j+1]=='c') ++ans;
returnprintf("%d",ans),0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2023-09-12 The 2021 ICPC Asia Macau Regional Contest
2022-09-12 COMPFEST 14 - Preliminary Online Mirror