跳到正文

生活·游记

2024 省选游记

Pig_py约 26 分钟
原文
文章信息与版本

文章信息

收录
2026年7月4日
更新
2026年7月4日
篇幅
约 26 分钟

版本

  1. v1当前

2.29 (Day−−1)2.29\ (Day--1)

没上初中课程,在家备考。

上午补了 ABC243FABC243F 和 ABC243GABC243G,下午翻看了寒假学习记录。

pFsCBge.png

当初决定写学习记录是明智的。

谁曾料,备考省选不仅要补课,还要补作业;不仅要补作业,还要补政治作业。缺乏同情心是当今社会很严重的问题。不过,如果你遇到的是一个自以为是到缺乏同情心的人,最好还是敬而远之。

3.1 (Day−0)3.1\ (Day-0)

在路上。

高铁站遇到了两个外国人,顿时间想到了食堂的地标 Export.Export. 三线小城也很国际化。

翻看了 NoipNoip 考前十天停课总结。东校的老师真好,后来还关怀我能不能跟上。现在恐怕只有怀念的份了,尤其是怀念语文李老师和物理王老师。甚至备考动机都来源于李老师:

pFyGirj.png

pFsPhIx.png

晚上去山师附中试机。SpfaSpfa 第一遍写成优先队列了,pushpush 之前还没判 vis.vis. 好在 1h1h 完成了线段树和朴素暴力区间修改区间查的对拍、DijkstraDijkstra 和 SpfaSpfa 的对拍。

怎么 SpfaSpfa 在 10510^5 的随机数据下还那么慢啊?估计当时 SpfaSpfa 单点都要跑 100 ms.100\ ms.

3.2 (Day−1)3.2\ (Day-1)

正式赛第一天。

步行去山师附中考试。路上有微风,许是春风吧?

8:008:00 入场,8:308:30 开考,考到 1:30.1:30.

怕看完后面题分散了注意力,还是按照老规矩,一道一道地看。

T1. n=1T1.\ n=1 的特殊性质 BB 比较好做。后来看了一下,发现 n=1n=1 的特殊性质 CC 具有单调性,可以二分。CC 性质没有扩展,BB 的扩展可以按照 mmod  nm\mod n 的性质分类做。B 30 pts+C 10 pts=40 pts,ok.B\ 30\ pts+C\ 10\ pts=40\ pts,ok. 写了两个小时,从 8:308:30 写到 10:30.10:30. 大量事实表明,正式比赛赛时调不出的代码再给一个小时也调不出,时间够用,不要怕写不完。

T2.T2. 原来看到文件名是 xor,xor, 猜测可能是边权题,后来发现不是。有形式化题面!还有 int128int128 输入输出模板!好耶!只会 12 pts12\ pts 的暴力,敲完走人。

T3T3 不会。12:0012:00 开始,T1T1 三段代码轮流对拍,以防感到无聊。

40/40+12/12+0/0=52/52,40/40+12/12+0/0=52/52, 没有挂分。

山师附中男厕所的门两侧都能推,好高级。

3.3 (Day−2)3.3\ (Day-2)

早晨吃了红烧肉,脸上油腻腻的,甚至还有些犯困,后悔了。

T1T1 很像之前梦熊的 T2,T2, 然而由于时运不济等复杂因素未能有幸看到题解,着实有些慌。不过后来发现,那道题学会了的人这道题并没有多拿多少分,呵呵。子集枚举 + Dfs+\ Dfs 可以得到 25 pts,25\ pts, 结合贪心能得到 15 pts15\ pts 的特殊性质 A.A. 25 pts+A 15 pts=40 pts,ok.25\ pts+A\ 15\ pts=40\ pts,ok. 想出的正解做法过不去 BB 性质的样例,也没打算能过。亏得另测了 A,A, 差点被 n≤4n\le4 的分段坑了。刚开始 tagtag 没清空。

T2.T2. 题目名称很有诗意,但我只会暴力,对不起良苦用心的出题人。10 pts+5 pts=15 pts,ok. 10 pts10\ pts+5\ pts=15\ pts,ok.\ 10\ pts 来源于暴力,5 pts5\ pts 来源于 m=0.m=0. 知识点是阶乘及逆元、TopoTopo 和 Dfs.Dfs.

T3T3 不会。

11:3011:30 开始拍 T1T1 的 AA 和暴力。亏得还能写出两个解法,否则连时间都消磨不了。

40/40+15/15+0/0=55/55.40/40+15/15+0/0=55/55.

52/52+55/55=107/107.52/52+55/55=107/107. 一分没挂。

写在最后

人面不知何处去,桃花依旧笑春风。

遗憾自然有,惋惜自然有,每年都有近万应届考生无缘省队,抱憾告别 OI OI\ 。一年年省选送走了一代代 Oier,Oier, 却也正有一代代 OierOier 成长起来。

也许,我未来不会冲省队,甚至今年下半年正式作为高中生拿到省一就退役了。

但我仍希望,信竞带给我的经历能保存下来,历历在目,历久弥新。(自学、补课、体能、总结、平衡、思维、兴趣)

如是,足矣。

CodeCode

Day1−T1Day1-T1

C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int Q;
int n;
ll k,X,Y,x[100005],y[100005],inf=100000000000000000;
ll sx[100005],sy[100005];
int main(){
	freopen("wind.in","r",stdin);
	freopen("wind.out","w",stdout);
//	freopen("in.txt","r",stdin);
	scanf("%d",&Q);
	while(Q--){
//		pre();
		scanf("%d%lld%lld%lld",&n,&k,&X,&Y);
		for(int i=0;i<n;i++){
			scanf("%lld%lld",&x[i],&y[i]);
		}
		sx[0]=x[0];
		sy[0]=y[0];
		for(int i=1;i<n;i++){
			sx[i]=sx[i-1]+x[i];
			sy[i]=sy[i-1]+y[i];
		}
//		printf("%lld\n",-12279435%-12279435);
		if(!X&&!Y){
			printf("0\n");
			continue;
		}
		if(n==1&&k==0){
			if(!x[0]&&X){
				printf("-1\n");
				continue;
			}
			if(!y[0]&&Y){
				printf("-1\n");
				continue;
			}
			if(!x[0]&&!y[0]){
				printf("0\n");
				continue;
			}
			if(x[0]&&(X%x[0]!=0||X/x[0]<0)){
				printf("-1\n");
				continue;
			}
			if(y[0]&&(Y%y[0]!=0||Y/y[0]<0)){
				printf("-1\n");
				continue;
			}
			if(!x[0]){
				printf("%lld\n",Y/y[0]);
			}
			else if(!y[0]){
				printf("%lld\n",X/x[0]);
			}
			else{
				if(X/x[0]!=Y/y[0]){
					printf("-1\n");
				}
				else{
					printf("%lld\n",X/x[0]);
				}
			}
		}
		else if(n==1&&!x[0]&&!y[0]){
			ll l=1,r=max(abs(4*X),abs(4*Y));
			ll res=max(abs(4*X),abs(4*Y));
			while(l<r){
				ll mid=(l+r)/2;
				if(abs((double)X/mid)+abs((double)Y/mid)<=k){
					res=min(res,mid);
					r=mid-1;
				}
				else l=mid+1;
			}
			if(abs((double)X/l)+abs((double)Y/l)<=k){
				res=min(res,l);
			}
//			if(abs((double)X/581)+abs((double)Y/581)<=k){
//				puts("Yes");
//			}
			if(res==max(abs(4*X),abs(4*Y))){
				printf("-1\n");
			}
			else{
				printf("%lld\n",res);
			}
		}
		else if(k==0){
			ll ans=inf;
			for(int b=0;b<n;b++){
				if(!sx[n-1]&&(X-sx[b]))continue;
				if(!sy[n-1]&&(Y-sy[b]))continue;
				if(sx[n-1]&&(X-sx[b])%sx[n-1]!=0)continue;
				if(sy[n-1]&&(Y-sy[b])%sy[n-1]!=0)continue;
				if(sx[n-1]&&(X-sx[b])/sx[n-1]<0)continue;
				if(sy[n-1]&&(Y-sy[b])/sy[n-1]<0)continue;
				ll res=inf;
				if(sx[n-1]){
					res=(X-sx[b])/sx[n-1];
				}
				if(sy[n-1]){
					if(res!=inf&&res!=(Y-sy[b])/
					sy[n-1]){
						res=inf;
					}
					else{
						res=(Y-sy[b])/sy[n-1];
					}
				}
				if(res==inf)continue;
				ans=min(ans,res*n+b);
			}
			if(ans>=inf)ans=-2;
			printf("%lld\n",ans+1);
		}
	}
	return 0;
}
/*
有绝对值的限制,需要让 x' y' 分配得尽可能平均

先看样例:
 
1 2 -2 -2
1 1 

m=1:
x[0]+x'[0]=-2
y[0]+y'[0]=-2
-3 -3
6>2

m=2:
x[0]*2+x'[0]*2=-2
y[0]*2+y'[0]*2=-2
x'[0]=-2
y'[0]=-2
4>2

m=3:
x[0]*3+x'[0]*3=-2
y[0]*3+y'[0]*3=-2
x'[0]=-5/3
y'[0]=-5/3

当 n=1 时,m 一定时 x'[0] 可以直接被算出。
但是也不好做,至少要枚举 m.

考虑特殊性质 B: x'[0]=y'[0]=0

n=1 的 B 过样例了,10 pts. 

考虑特殊性质 C: kx'[0]=x,ky'[0]=y
x'[0] y'[0] 似乎有可能不为整数,考虑 x,y 为质数的情况 
分类讨论 x,y 为正数/负数的情况,发现 k 越大 |x'[0]| |y'[0]| 越小 

n=1 的 C 过样例了,20 pts.

考虑特殊性质 B 的拓展。

先将 m 按照 mod n 的余数分类,设 m=c*n+b
c*sx[n-1]+sx[b]=x
c*sy[n-1]+sy[b]=y 
由于 b 是定值,c 可以直接被求出 
*/
/*
注意事项:
1. 记得文件输入输出
2. 记得删除调试
3. 记得多写函数
4. 记得开 long long
5. 想好思路再写代码,写前先算一遍样例
6. 分段 
7. 不要用 puts
8. 记得计算空间 
pdf 密码:ae1e402553c463f4 
*/ 

Day1−T2Day1-T2

C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void read(__int128 &x){
	// read a __int128 variable
	char c; bool f = 0;
	while(((c = getchar()) < '0' || c > '9') && c != '-');
	if(c == '-'){f = 1; c = getchar();}
	x = c - '0';
	while((c = getchar()) >= '0' && c <= '9')x = x * 10 + c - '0';
	if(f) x = -x;
}
void write(__int128 x){
	// print a __int128 variable
	if(x < 0){putchar('-'); x = -x;}
	if(x > 9)write(x / 10);
	putchar(x % 10 + '0');
}
int c,Q,n,k;
ll m,b[100005];
__int128 a[100005];
void Subtask1(){
	int mj=(1<<n)-1;
//	printf("mj:%d\n",mj);
	__int128 ans=0;
	__int128 x_end=1;
	for(int i=1;i<=k;i++){
		x_end=x_end*2;
	}
	x_end--;
	for(int i=0;i<=mj;i++){
//		printf("1i:%d\n",i);
		ll sum=0;
		for(int j=1;j<=n;j++){
			if(i&(1<<(j-1))){
				sum+=b[j];
			}
		}
//		printf("i:%d\n",i);
		if(sum>m)continue;
		for(__int128 x=0;x<=x_end;x++){
			__int128 res=x_end*5;
			for(int j=1;j<=n;j++){
				if(i&(1<<(j-1))){
					res=min(res,a[j]+x);
				}
				else{
					res=min(res,a[j]^x);
				}
			}
			ans=max(ans,res);
		}
	}
	write(ans);
	printf("\n");
}
int main(){
	freopen("xor.in","r",stdin);
	freopen("xor.out","w",stdout);
//	freopen("in.txt","r",stdin);
//	puts("Yes");
	scanf("%d%d",&c,&Q);
//	printf("c:%d Q:%d\n",c,Q);
//	puts("G");
	while(Q--){
//		puts("F");
		scanf("%d%lld%d",&n,&m,&k);
		for(int i=1;i<=n;i++){
			read(a[i]);
		}
		for(int i=1;i<=n;i++){
			scanf("%lld",&b[i]);
		}
		if(c>=1&&c<=3){
			Subtask1();
		}
	}
	return 0;
}
/*
此题可能可以二分。
 
首先去除 m 的限制,发现将 x 取最大值然后 S 取全集最优。 

然后发现 x 取 2^k-1 时并不一定能构造出最优情况。

先考虑已知 x 应当怎么做 

二分答案,check(bound) 表示答案能否 >=bound

设 dp[i][j] 表示考虑到前 i 个位置,b 的贡献是 j 能得到的最小贡献最大值

直接进行 dp, 时间复杂度为 O(nm), 加上外层 x 和 bound, 时间复杂度为
O(nm2^klogS), 期望得分 0 pts. 
*/
/*
1<=c<=3: 直接暴力即可,时间复杂度 O(n2^(k+n))
 
*/
/*
注意事项:
1. 记得文件输入输出
2. 记得删除调试
3. 记得多写函数
4. 记得开 long long
5. 想好思路再写代码,写前先算一遍样例
6. 分段 
7. 不要用 puts
8. 记得计算空间 
pdf 密码:ae1e402553c463f4 

*/ 

Day2−T1Day2-T1

C++
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int n,Q,p;
ll k,w[100005],q[200005],dp[200005],ans[200005],a[200005],cnt;
int tag[200005];
int fastpow(int x,int y){
	if(!y)return 1;
	int temp=fastpow(x,y/2);
	temp=temp*temp;
	if(y%2)temp=temp*x;
	return temp;
} 
int Dfs1(int x){
	if(x>=p){
		dp[x]=q[x];
		return dp[x];
	}
	if(tag[x]){
//		puts("?");
		dp[x]=Dfs1(x*2);
		Dfs1(x*2+1);
		return dp[x];
	}
	else{
		dp[x]=min(Dfs1(x*2),Dfs1(x*2+1));
		return dp[x];
	}
}
void Dfs2(int x){
//	printf("x:%d\n",x);
	if(x>=p){
		cnt++;
//		printf("tot:%d q[x]:%d\n",cnt,q[x]);
		a[cnt]=q[x];
		return;
	}
	if(dp[x]==dp[x*2]){
		Dfs2(x*2);
		Dfs2(x*2+1);
	}
	else{
		Dfs2(x*2+1);
		Dfs2(x*2);
	}
}
void Dfs3(int x){
	if(x>=p)return;
	if(k>=w[x]){
		k-=w[x];
		tag[x]=1;
		Dfs3(x*2);
		Dfs3(x*2+1);
	}
	else{
		Dfs3(x*2+1);
		Dfs3(x*2); 
	}
}
void Subtask1(){
	int mj=(1<<(p-1))-1;
	for(int j=p;j<=p*2-1;j++){
		ans[j]=1;
	}
	for(int i=0;i<=mj;i++){
		ll tot=0;
		for(int j=1;j<=p-1;j++){
			if((i>>(j-1))&1){
				tag[j]=1;
				tot+=w[j];
			}
			else{
				tag[j]=0;
			}
		}
		if(tot>k)continue;
		Dfs1(1);
//		printf("i:%d %d %d %d\n",i,dp[1],dp[2],dp[3]);
		cnt=p-1;
		Dfs2(1);
		int update=0;
//		for(int j=)
//		printf("i:%d\n",i);
//		if(cnt!=p*2-1)puts("?");
//		for(int j=p;j<=cnt;j++){
//			printf("%d ",a[j]);
//		}
//		printf("\n");
		for(int j=p;j<=p*2-1;j++){
			if(a[j]!=ans[j]&&!update)
			{
				if(a[j]>ans[j])update=1;
				else break;
			}
			if(update)ans[j]=a[j];
		}
	}
	for(int j=p;j<=p*2-1;j++){
		printf("%lld ",ans[j]);
	}
	printf("\n");
}
void Subtask2(){
	for(int i=1;i<=2*p-1;i++){
		tag[i]=0;
	}
	Dfs3(1);
	Dfs1(1);
//	printf("i:%d %d %d %d\n",i,dp[1],dp[2],dp[3]);
	cnt=p-1;
	Dfs2(1);
	for(int j=p;j<=p*2-1;j++){
		printf("%lld ",a[j]);
	}
	printf("\n");	
}
void Dfs4(int x){
	if(x>=p)return;
	if(dp[2*x]<=dp[2*x+1]){
		Dfs4(2*x);
		Dfs4(2*x+1);
	}
	else{
		if(k>=w[x]){
			k-=w[x];
			tag[x]=1;
			Dfs4(2*x);
			Dfs4(2*x+1);
		}
		else{
			Dfs4(2*x+1);
			Dfs4(2*x);
		}
	}
}
void Subtask3(){
	for(int i=1;i<=2*p-1;i++){
		tag[i]=0;
	}
	Dfs1(1);
	Dfs4(1);
	Dfs1(1);
//	printf("i:%d %d %d %d\n",i,dp[1],dp[2],dp[3]);
	cnt=p-1;
	Dfs2(1);
	for(int j=p;j<=p*2-1;j++){
		printf("%lld ",a[j]);
	}
	printf("\n");		
}
bool check1(){
	for(int i=p;i<=p*2-1;i++){
		if(q[i]!=p*2-i)return false;
	}
	return true;
}
int main(){
	freopen("maze.in","r",stdin);
	freopen("maze.out","w",stdout);
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	scanf("%d",&Q);
	while(Q--){
//		pre();
		scanf("%d%lld",&n,&k);
		p=fastpow(2,n);
		int i_end=p-1;
		for(int i=1;i<=i_end;i++){
			scanf("%lld",&w[i]);
		}
		for(int i=i_end+1;i<=(i_end+1)*2-1;i++){
			scanf("%lld",&q[i]);
		}
		if(n<=4){
			Subtask1();
		}
		else if(check1()){
			Subtask2();
		}
		else{
			Subtask3();
		}
	}
	return 0;
}
/*
题面是博弈论形式。

假设 Alice 的神像一定,则:
	由于是一个排列,Bob 每次选首项最优的即可,且首项最优仅存一个
	因此我们需要知道每棵子树内第一次能遍历到的叶节点的最小值
	时间复杂度 O(nlogn)?
	但是 Alice 的神像?
	O(nlogn*2^n),期望得分 25 pts. 
	9:29 过样例了 

特殊性质 A:
	贪心。如果 Alice 能唤醒该点的石像守卫,唤醒后先递归左子树再递归
	右子树。否则,先递归右子树再递归左子树。
	Bob 做法与朴素暴力相同。
	期望得分 15 pts.
	9:52 过样例了
	假了,样例 1~4 全部 <=4. 
	多测没清空,10:19 过样例了。 

一种思路:
	Bob 的任务完成了。
	考虑 Alice. 唯一的区别在于性质 A 没了。
	先在没有 tag 的情况下求一遍 dp.
	然后考虑:
		若左子树更优:无能为力
		若右子树更优:看一下能否 tag,能 tag 就 tag,否则先考虑右子树
						情况 
	 
*/
/*
注意事项:
1. 文件输入输出
2. 不要使用 puts
3. 多分析性质,如果你不会:
	有单调性吗?
	可以二分吗?
	可以 dp 吗?
	可以建图吗?
	有能做的经典套路吗? 
4. 分段,写函数
5. 记得开 long long
6. 50+! 50+! 50+!

pdf 密码:419fe3f260adb910
*/

Day2−T2Day2-T2

C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,k,a[45],tag[25],fa[45],in[25],tot,b[25];
const int mod=1000000007;
ll sta,ans,fac[45];
ll fastpow(ll x,ll y){
	if(!y)return 1ll;
	ll temp=fastpow(x,y/2);
	temp=temp*temp%mod;
	if(y%2)temp=temp*(x%mod)%mod;
	return temp;
}
ll Inverse(ll x){
	return fastpow(x,mod-2);
}
struct Edge{
	int u,v;
}e[1005];
vector<int>G[25];
queue<int>q;
bool topo(){
	for(int i=1;i<=tot;i++){
		if(!in[i]){
			q.push(i);
		}
	}
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(auto i:G[x]){
			in[i]--;
			if(!in[i]){
				q.push(i);
			}
		}
	}
	for(int i=1;i<=tot;i++){
		if(in[i])return false;
	}
	return true;
}
void Dfs1(int x){
	if(x==k+1){
//		for(int i=1;i<=n+1;i++){
//			printf("%d ",tag[i]);
//		}
//		puts("");
		for(int i=1;i<=n;i++){
			b[a[i]]=i;
		}
		tot=0;
		tot++;
		in[1]=0;
		fa[a[1]]=tot;
		for(int i=2;i<=n;i++){
			if(tag[i]){
				tot++;
				in[tot]=0;
			}
			fa[a[i]]=tot;
		}
		for(int i=1;i<=tot;i++){
			G[i].clear();
		}
		for(int i=1;i<=m;i++){
			if(fa[e[i].u]!=fa[e[i].v]||b[e[i].u]>=b[e[i].v]){
				G[fa[e[i].u]].push_back(fa[e[i].v]);
				in[fa[e[i].v]]++;				
			}
		}
		if(topo()){
			ans+=sta;
			ans%=mod;
//			puts("Can:");
//			for(int i=1;i<=n;i++)printf("%d ",a[i]);
//			puts("");
//			for(int i=1;i<=n+1;i++){
//				printf("%d ",tag[i]);
//			}
//			puts("");
//			puts("Can");
		}
		return;
	}
	for(int i=1;i<=n+1;i++){
		int p=tag[i];
		tag[i]++;
		for(int j=1;j<=tag[i];j++){
			Dfs1(x+1);
		}
		tag[i]=p;
	}
}
void Subtask1(){
	fac[0]=1;
	for(int i=1;i<=n;i++){
		a[i]=i;
	}
	for(int i=1;i<=2*n;i++){
		fac[i]=1ll*fac[i-1]*i%mod;
	}
	sta=fac[n+k]%mod;
//	printf("sta:%lld\n",sta);
	sta=Inverse(sta);
//	printf("sta:%lld\n",sta);
	do{
		Dfs1(1);
	}while(next_permutation(a+1,a+n+1));
	printf("%lld",ans);
}
int main(){
	freopen("timeline.in","r",stdin);
	freopen("timeline.out","w",stdout);
//	freopen("in.txt","r",stdin);
//	printf("I6:%lld\n",Inverse(6));
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&e[i].u,&e[i].v);
	}
	if(n+k<=10){
		Subtask1();
	}
	else{
		printf("1");
	}
	return 0;
}
/*
如果我们知道了 k+1 段分别是什么,之后直接建边 topo 即可,时间复杂度
O(n).

爆搜还好,10 pts

m=0 也好写,5 pts 
*
/*
注意事项:
1. 文件输入输出
2. 不要使用 puts
3. 多分析性质,如果你不会:
	有单调性吗?
	可以二分吗?
	可以 dp 吗?
	可以建图吗?
	有能做的经典套路吗? 
4. 分段,写函数
5. 记得开 long long
6. 50+! 50+! 50+!
 
pdf 密码:419fe3f260adb910
*/
原文