首页 > 其他分享 >CSP-S 2022 游记

CSP-S 2022 游记

时间:2022-11-02 18:13:29浏览次数:48  
标签:head val int ll 100005 2022 游记 CSP dis

真就游寄

虽然没能正常参加 CSP,但是还是要做一下。
说实话这成绩七级勾本应该是稳了

T1 假期计划 (\(holiday\))2s 512M

\(1\to A\to B\to C\to D\to 1\)
观察这个结构,发现两边是对称的。
预处理出对于所有 \(B\), \(1\to A \to B\) 的最大的 \(A\) 的值。
枚举一下 \(B,C\),直接算贡献。
考虑到点冲突的问题,要记录次大值和次次大值。

int n, m, k;
struct node {
	int t, n;
}e[100005];
int u, v;
int head[100005], head_size;
void ADD(int f, int t) {
	e[++head_size]=(node){t, head[f]};
	head[f]=head_size;
}
int dis[2505][2505];
ll val[2505], ans;
ll maxx[2505][3];
void Change(int i, int j) {
	if(val[maxx[i][0]]<val[j]) {
		maxx[i][2]=maxx[i][1];
		maxx[i][1]=maxx[i][0];
		maxx[i][0]=j;
	}
	else if(val[maxx[i][1]]<val[j]) {
		maxx[i][2]=maxx[i][1];
		maxx[i][1]=j;
	}
	else if(val[maxx[i][2]]<val[j]) {
		maxx[i][2]=j;
	}
}
void BFS(int S) {
	dis[S][S]=0;
	queue<int>q;
	q.push(S);
	while(!q.empty()) {
		int x=q.front(); q.pop();
		for(int i=head[x]; i; i=e[i].n) {
			if(dis[S][e[i].t]>100000000) {
				dis[S][e[i].t]=dis[S][x]+1;
				q.push(e[i].t);
			}
		}
	}
}
ll slove(int x, int y) {
	ll re=-1;
	ll sum=val[x]+val[y];
	for(int i=0; i<=2; ++i) {
		if(maxx[x][i]==0) continue ;
		if(maxx[x][i]==y) continue ;
		for(int j=0; j<=2; ++j) {
			if(maxx[y][j]==0) continue ;
			if(maxx[y][j]==x) continue ;
			if(maxx[y][j]==maxx[x][i]) continue ;
			re=max(re, sum+val[maxx[x][i]]+val[maxx[y][j]]);
		}
	}
	return re;
}
int main(){
	memset(dis, 0x3f, sizeof(dis));
	n=read(); m=read(); k=read();
	for(int i=2; i<=n; ++i) val[i]=read();
	for(int i=1; i<=m; ++i) {
		u=read(); v=read();
		ADD(u, v); ADD(v, u);
	}
	for(int i=1; i<=n; ++i) BFS(i);
	for(int i=2; i<=n; ++i) {
		for(int j=2; j<=n; ++j) {
			if(i==j) continue ;
			if(dis[1][j]<=k+1&&dis[j][i]<=k+1) Change(i, j);
		}
	}
	for(int i=2; i<=n; ++i) {
		if(!maxx[i][0]) continue ;
		for(int j=2; j<=n; ++j) {
			if(i==j) continue ;
			if(dis[i][j]>k+1) continue ;
			if(!maxx[j][0]) continue ;
			ans=max(ans, slove(i, j));
		}
	}
	cout<<ans;
}

T2 策略游戏 ( \(game\) ) 1s 512M

\(A\) 选一个数,\(B\) 选择使答案最小的那个。
对于所有 \(A\) 选数之后 \(B\) 选出的最小值取个最大值就行。
其实再多再多也就四种情况。
选正数里最大的或最小的,选负数里最大的或最小的。
那么两个序列,一共 \(4\times 4 = 16\) 种情况,枚举一下就行了。
特别的, \(0\) 作为交界点,即算正数,也算负数。
然后 \(8\) 个 ST 表伺候上就行了。

int n, m, q, a;
int sta[100005][20][4];
int stb[100005][20][4];
int lo[100005];
/*
0正数最大
1正数最小
2负数最大
3负数最小 
*/
int main(){
	n=read(); m=read(); q=read();
	for(int i=1; i<=n; ++i) {
		a=read();
		sta[i][0][0]=sta[i][0][2]=-2e9;
		sta[i][0][1]=sta[i][0][3]=2e9;
		if(a>=0) sta[i][0][0]=sta[i][0][1]=a; 
		if(a<=0) sta[i][0][2]=sta[i][0][3]=a;
	}
	for(int i=1; i<=m; ++i) {
		a=read();
		stb[i][0][0]=stb[i][0][2]=-2e9;
		stb[i][0][1]=stb[i][0][3]=2e9;
		if(a>=0) stb[i][0][0]=stb[i][0][1]=a; 
		if(a<=0) stb[i][0][2]=stb[i][0][3]=a;
	}
	for(int i=2; i<=max(n, m); ++i) lo[i]=lo[i>>1]+1;
	for(int cs=1; cs<=lo[n]; ++cs) {
		for(int i=1; i+(1<<cs)-1<=n; ++i) {
			sta[i][cs][0]=max(sta[i][cs-1][0], sta[i+(1<<cs-1)][cs-1][0]);
			sta[i][cs][1]=min(sta[i][cs-1][1], sta[i+(1<<cs-1)][cs-1][1]);
			sta[i][cs][2]=max(sta[i][cs-1][2], sta[i+(1<<cs-1)][cs-1][2]);
			sta[i][cs][3]=min(sta[i][cs-1][3], sta[i+(1<<cs-1)][cs-1][3]);
		}
	}
	for(int cs=1; cs<=lo[m]; ++cs) {
		for(int i=1; i+(1<<cs)-1<=m; ++i) {
			stb[i][cs][0]=max(stb[i][cs-1][0], stb[i+(1<<cs-1)][cs-1][0]);
			stb[i][cs][1]=min(stb[i][cs-1][1], stb[i+(1<<cs-1)][cs-1][1]);
			stb[i][cs][2]=max(stb[i][cs-1][2], stb[i+(1<<cs-1)][cs-1][2]);
			stb[i][cs][3]=min(stb[i][cs-1][3], stb[i+(1<<cs-1)][cs-1][3]);
		}
	}
	while(q--) {
		int A[4], B[4];
		int l, r, cs;
		l=read(); r=read(); cs=lo[r-l+1];
		A[0]=max(sta[l][cs][0], sta[r-(1<<cs)+1][cs][0]); A[1]=min(sta[l][cs][1], sta[r-(1<<cs)+1][cs][1]);
		A[2]=max(sta[l][cs][2], sta[r-(1<<cs)+1][cs][2]); A[3]=min(sta[l][cs][3], sta[r-(1<<cs)+1][cs][3]);
		l=read(); r=read(); cs=lo[r-l+1];
		B[0]=max(stb[l][cs][0], stb[r-(1<<cs)+1][cs][0]); B[1]=min(stb[l][cs][1], stb[r-(1<<cs)+1][cs][1]);
		B[2]=max(stb[l][cs][2], stb[r-(1<<cs)+1][cs][2]); B[3]=min(stb[l][cs][3], stb[r-(1<<cs)+1][cs][3]);
		ll ans=-1e18, sum;
		for(int i=0; i<4; ++i) {
			if(abs(A[i])==2e9) continue ;
			sum=1e18;
			for(int j=0; j<4; ++j) {
				if(abs(B[j])==2e9) continue ;
				sum=min(sum, 1LL*A[i]*B[j]);
			}
			ans=max(ans, sum);
		}
		cout<<ans; putchar('\n');
	}
}

标签:head,val,int,ll,100005,2022,游记,CSP,dis
From: https://www.cnblogs.com/Konnyaku41377/p/16851869.html

相关文章

  • 2022CCPC(桂林)
    我的首站本来想着练练手拿铜牌血赚打铁不亏结果保底铜牌要是G题做出来应该可以冲击一下银牌https://codeforces.com/gym/104008A.Lily签到题:所有不在L旁的字符......
  • [2022.11.2]collection
    collection接口1.单列集合框架结构l----collection接口:单列集合,用来存储一个一个的对象/----List接口:存储序的、可重复的数据。-->“动态”数组/--......
  • CSP2022总结
    拿到题先看T1,发现有点难,没一眼秒,转而看T2,发现是个RMQ板子,赶紧开写,写+调60min。然后回来看T1,发现可以枚举中间两个点,预处理匹配前3大的点,处理一下匹配关系即可,想+写+调60......
  • 2022-11-02每日一题
    Acwing逆序对的个数给定一个长度为n的整数数列,请你计算数列中的逆序对的数量。逆序对的定义如下:对于数列的第i个和第j个元素,如果满足i<j且a[i]>a[j],则其为一个......
  • delphi TscSplitView控件学习笔记
    一.先说效果吧,放置的位置不一样,显示出来的效果也不一样 然后效果是这样的:注意位置标记1按钮的位置.当DisplayMode:=scsvmOverlay时,会遮挡TscSplitView......
  • 《汽车软件全景图(2022年)》来了
    News-----------------------------------------------------------------------------------------------------------------------------------------------------------......
  • 赋能千行百业数字化转型,OpenHarmony生态新成果即将亮相HDC2022
     第四届华为开发者大会2022(Together)将于11月4日-6日在东莞召开,OpenAtomOpenHarmony(以下简称“OpenHarmony”)将携生态新成果亮相HDC2022。带来多场行业论坛及线下展区活......
  • LOG_2022_11_02.log
    Loadingthesystem......DONEConenctingtotheserver......FAILEDTryingtoconnecttothebackupserver......SUCCESSUsername:apjifengcPass......
  • HDC2022 开发者亮点抢先看,线上线下精彩活动等你探索!
      ......
  • NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)
    论文地址:https://arxiv.org/pdf/2205.03521.pdf代码地址:https://github.com/zjunlp/HVPNeT计算机视觉研究院专栏作者:Edison_G多模态命名实体识别和关系提取(MNER和MRE)是......