跳到正文

个人记录

2024/9/3比赛

1c666约 19 分钟
原文
文章信息与版本

文章信息

发布
2024年9月3日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 19 分钟

版本

  1. v1当前

分数:151 / 400


A.\mathbb{A}. 果老师的不等式

输入输出:deng

赛时代码:

C++
#include<cstdio>
#include<queue>
using namespace std;
typedef bool B;
typedef long long int L;
typedef void V;
const B F = false,T = true;
const L inf = 0x3fffffffffffffLL,N = 150005LL;
int main(){
	freopen("deng.in","r",stdin);
	freopen("deng.out","w",stdout);
	putchar('0');
	return 0;
}

赛时得分: 0 / 100

赛时思路:

暴力骗分。(“比起暴力,我更像是在侮辱暴力。”)

正解代码:

C++
#include<cstdio>
#include<queue>
using namespace std;
typedef bool B;
typedef int L;
typedef void V;
const B F = false,T = true;
const L inf = 0x3fffffLL,A = 50050005LL;
L a[A],n,k,cnt_ans = 0LL,JCLTY,AKIOI;
int main(){
	a[1] = 2LL,a[7] = 3LL,a[4] = 4LL,a[2] = a[3] = a[5] = 5LL,a[6] = a[9] = a[0] = 6LL,a[8] = 7LL;
	scanf("%d %d",&n,&k);
	for(L i = 10LL;i <= n;i++)AKIOI = i / 10LL,a[i] = a[AKIOI] + a[i - ((AKIOI) * 10LL)];
	JCLTY = ((n / k) - (2LL * 2LL)) - a[n];
	for(L i = 0LL,j = n;i <= j;i++,j--)if(((a[i]) + (a[j])) == JCLTY)cnt_ans++;
	printf("%d",cnt_ans);
	return 0;
}

正解思路:

枚举,然后计算。(注意时间与空间限制!!!)


B.\mathbb{B}. 小鸟

输入输出:bird

赛时代码:

C++
#include<cstdio>
#include<queue>
using namespace std;
typedef bool B;
typedef long long int L;
typedef void V;
const B F = false,T = true;
const L inf = 0x3fffffffffffffLL,N = 150005LL;
L n,q,d[N],k,t[N];
deque<L> que;
L bird_fly(L _ki,L _n){
	que.clear();
	t[1] = 0LL,que.push_back(1LL);
	for(L i = 2LL;i <= _n;i++){
		t[i] = t[que.front()] + (d[que.front()] <= d[i]);
		if(que.front() < i - _ki)que.pop_front();
		while((!(que.empty())) && ((t[que.back()] > t[i]) || ((t[que.back()] == t[i]) && (d[que.back()] >= t[i]))))que.pop_back();
		que.push_back(i);
	}
	return (t[n]);
}
int main(){
	freopen("bird.in","r",stdin);
	freopen("bird.out","w",stdout);
	scanf("%lld",&n);
	for(L i = 1LL;i <= n;i++)scanf("%lld",(&(d[i])));
	scanf("%lld",&q);
	while(q--)scanf("%lld",&k),printf("%lld",bird_fly(k,n)),putchar('\n');
	return 0;
}

赛时得分: 11 / 100

赛时思路:

几乎与正解思路相同。但是写错了一些细节。

正解代码:

C++
#include<cstdio>
#include<queue>
using namespace std;
typedef bool B;
typedef long long int L;
typedef void V;
const B F = false,T = true;
const L inf = 0x3fffffffffffffLL,N = 150005LL;
L n,q,d[N],k,t[N];
deque<L> que;
L bird_fly(L _ki,L _n){
	que.clear();
	t[1] = 0LL,que.push_back(1LL);
	for(L i = 2LL;i <= _n;i++){
		if(que.front() < i - _ki)que.pop_front();
		if(que.empty())t[i] = inf;
		else t[i] = t[que.front()] + (d[que.front()] <= d[i]);
		while((!(que.empty())) && ((t[que.back()] > t[i]) || ((t[que.back()] == t[i]) && (d[que.back()] <= d[i]))))que.pop_back();
		que.push_back(i);
	}
	return (t[_n]);
}
int main(){
	scanf("%lld",&n);
	for(L i = 1LL;i <= n;i++)scanf("%lld",(&(d[i])));
	scanf("%lld",&q);
	while(q--)scanf("%lld",&k),printf("%lld",bird_fly(k,n)),putchar('\n');
	return 0;
}

正解思路:

n2n^2 暴力不难想,but……

对于每一只小鸟:

用单调队列对当前位置的前 kik_i 个进行移动至此的最小值的维护。

计算出最终 nn 处的结果。

(注:请一定一定一定务必务必务必注意细节细节细节!!!!!重要的事情说三遍!)


C.\mathbb{C}. A < AP

输入输出:ap

赛时代码:

C++
#include<cstdio>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef bool B;
typedef long long int L;
typedef void V;
const B F = false,T = true;
const L inf = 0x3fffffffffffffLL,N = 250005LL,Mod_P = 998244353LL;
L n,m,p[N],is_number[N],ans = 0LL,h,num[N];
L abss(L u){return (u < 0LL)?(-u):u;}
L maxx(L u,L v){return (u > v)?u:v;}
L minn(L u,L v){return (u < v)?u:v;}
L quickly_power(L u,L v){
	if(v < 0LL)return 0LL;
	L w = 1LL,r = u;
	while(v){
		if(v & 1LL)w *= r,w %= Mod_P;
		v >>= 1LL;
		r *= r,r %= Mod_P;
	}
	return w;
}
class Tree_Arr{
	L ta_sz;
	vector<L> ta;
	L lowbit(L u){return u & (-u);}
	public:
		V Setting(L new__ta_sz){
			ta_sz = new__ta_sz;
			ta.clear();
			for(L i = 0LL;i <= ta_sz;i++)ta.push_back(0LL);
			return ;
		}
		L Get_Sum(L id){
			L _sum = 0LL;
			while(id){
				_sum += ta[id];
				id -= lowbit(id);
			}
			return _sum;
		}
		V Query(L id,L adding_merge_number){
			while(id <= ta_sz){
				ta[id] += adding_merge_number;
				id += lowbit(id);
			}
			return ;
		}
};
int main(){
	freopen("ap.in","r",stdin);
	freopen("ap.out","w",stdout);
	scanf("%lld %lld",&n,&m);
	for(L i = 1LL;i <= n;i++)scanf("%lld",(&(p[(i)])));
	for(L i = 1LL;i <= n;i++)is_number[i] = i,num[i] = 1LL;
	h = n;
	for(L i = 1LL;i <= n && h >= 0LL;i++){
		if(is_number[i] == is_number[p[i]]){h--;continue;}
//		putchar('*');//try.
		ans += (((((((m) - 1LL) * (m)) >> 1LL) % Mod_P) * quickly_power(m,/*h - num[is_number[i]] - num[is_number[p[i]]]*/h - 2LL)) % Mod_P),ans %= Mod_P;
		num[is_number[i]] += num[is_number[p[i]]],is_number[p[i]] = is_number[i],h--;
//		for(L i = 1LL;i <= n;i++)printf("%lld ",((is_number[(i)])));//try.
	}
	printf("%lld",ans);
	return 0;
}

赛时得分: 40 / 100

赛时思路:

讨论某些离谱问题即可。思路与正解的思路相同。(这____的细节!)

正解代码:

C++
#include<cstdio>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef bool B;
typedef long long int L;
typedef void V;
const B F = false,T = true;
const L inf = 0x3fffffffffffffLL,N = 250005LL,Mod_P = 998244353LL;
L n,m,p[N],is_number[N],ans = 0LL,h;
L abss(L u){return (u < 0LL)?(-u):u;}
L maxx(L u,L v){return (u > v)?u:v;}
L minn(L u,L v){return (u < v)?u:v;}
L quickly_power(L u,L v){
	if(v < 0LL)return 0LL;
	L w = 1LL,r = u;
	while(v){
		if(v & 1LL)w *= r,w %= Mod_P;
		v >>= 1LL;
		r *= r,r %= Mod_P;
	}
	return w;
}
L f2(L u){return ((u == is_number[u])?(u):(is_number[u] = (f2(is_number[u]))));}
B f1(L u,L v){
	if(f2(u) - f2(v)){is_number[is_number[u]] = is_number[v];return T;}
	else return F;
}
class Tree_Arr{
	L ta_sz;
	vector<L> ta;
	L lowbit(L u){return u & (-u);}
	public:
		V Setting(L new__ta_sz){
			ta_sz = new__ta_sz;
			ta.clear();
			for(L i = 0LL;i <= ta_sz;i++)ta.push_back(0LL);
			return ;
		}
		L Get_Sum(L id){
			L _sum = 0LL;
			while(id){
				_sum += ta[id];
				id -= lowbit(id);
			}
			return _sum;
		}
		V Query(L id,L adding_merge_number){
			while(id <= ta_sz){
				ta[id] += adding_merge_number;
				id += lowbit(id);
			}
			return ;
		}
};
int main(){
	scanf("%lld %lld",&n,&m);
	for(L i = 1LL;i <= n;i++)scanf("%lld",(&(p[(i)])));
	for(L i = 1LL;i <= n;i++)is_number[i] = i;
	h = n;
	for(L i = 1LL;i <= n && h >= 0LL;i++){
		if(f2(i) == f2(p[i])){continue;}
		ans += (((((((m) - 1LL) * (m)) >> 1LL) % Mod_P) * quickly_power(m,h - 2LL)) % Mod_P),ans %= Mod_P;
		f1(p[i],i),h--;
	}
	printf("%lld",ans);
	return 0;
}

正解思路:

对于字典序的比较,必然满足如下条件之一:

  \; · A1<AP1A_1 < A_{P_1} ;

  \; · A1=AP1A_1 = A_{P_1} 且 A2<AP2A_2 < A_{P_2} ;

  \; · A1=AP1A_1 = A_{P_1} 、 A2=AP2A_2 = A_{P_2} 且 A3<AP3A_3 < A_{P_3} ;

                                                            \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; ……

  \; · Ai=APi(1≤i<n,i∈Z)A_i = A_{P_i} (1 \le i < n,i \in \large{\mathbb{Z}}) 且 An<APnA_n < A_{P_n} 。

不难发现,当条件中的等式可以连接 ii 和 PiP_i 时,该条件不可能成立。

否则,该条件一共有 (n−1)n2×m原(即上一个i时)可随意取值变量数量−2\frac{(n - 1)n}{2} \times m^{原(即上一个 i 时)可随意取值变量数量 - 2} 种取值方法。

套入并查集得:

循环 i(1≤i≤n,i∈Z)i(1 \le i \le n,i \in \large{\mathbb{Z}}) 。对于每个 ii ,判断 ii 是否与 PiP_i 在同一并查集内。如果是,则跳过本次循环;如果不是,则统计答案(用变量 ansans 进行记录。),并将 ii 所在的并查集和 PiP_i 所在的并查集合并,自由取值变量(即随意取值变量数量,记作 hh ,初始化为 nn 。)数量减一,即:

ans    +=    n(n−1)2×mh−2ans\;\;+=\;\;\frac{n(n - 1)}{2} \times m^{h - 2}

。

细节:请使用快速墓幂!!!


D.\mathbb{D}. 平均身高

输入输出:height

赛时代码:

C++
#include<cstdio>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef bool B;
typedef long long int L;
typedef void V;
const B F = false,T = true;
const L inf = 0x3fffffffffffffLL,N = 250005LL;
L n,k,a[N],cnt_ans = 0LL/*,l,r,mid,two_fen_ans,*/,cnt,AKIOI = 0LL,gn,kn;
map<L,L> mp;
set<L> st;
L abss(L u){return (u < 0LL)?(-u):u;}
L maxx(L u,L v){return (u > v)?u:v;}
L minn(L u,L v){return (u < v)?u:v;}
class Tree_Arr{
	L ta_sz;
	vector<L> ta;
	L lowbit(L u){return u & (-u);}
	public:
		V Setting(L new__ta_sz){
			ta_sz = new__ta_sz;
			ta.clear();
			for(L i = 0LL;i <= ta_sz;i++)ta.push_back(0LL);
			return ;
		}
		L Get_Sum(L id){
//			L _sum;
			L _sum = 0LL;
			while(id){
				_sum += ta[id];
				id -= lowbit(id);
			}
			return _sum;
		}
		V Query(L id,L adding_merge_number){
			while(id <= ta_sz){
				ta[id] += adding_merge_number;
				id += lowbit(id);
			}
			return ;
		}
};
Tree_Arr s;
int main(){
	freopen("height.in","r",stdin);
	freopen("height.out","w",stdout);
	scanf("%lld %lld",&n,&k),gn = ((n << 1LL) + 1005LL),kn = ((n << 2LL) + 5005LL);
	s.Setting(kn);
	for(L i = 1LL;i <= n;i++)scanf("%lld",(&(a[i]))),(a[i]) -= k,(a[i]) += (a[(i - 1LL)]),st.insert(abss(a[i]));
	mp[0LL] = 0LL;
	for(set<L>::iterator it = st.begin();it != st.end();it++)if((*(it)))mp[(*(it))] = (++(AKIOI)),mp[(-(*(it)))] = (-(AKIOI));
	for(L i = 1LL;i <= n;i++)a[i] = mp[a[i]];
	s.Query(gn,1LL);
	for(L i = 1LL;i <= n;i++){
		/*
		cnt_ans += s.Get_Sum(kn) - s.Get_Sum(gn - a[i] - 1LL);
		s.Query(gn + a[i],1LL);
		*/
		/*
		cnt_ans += s.Get_Sum(kn) - s.Get_Sum(gn - a[i] - 1LL);
		s.Query(gn + a[i],1LL);
		*/
		cnt_ans += s.Get_Sum(kn) - s.Get_Sum(gn - a[i] - 1LL);
		s.Query(gn - a[i],1LL);
	}
	printf("%lld",cnt_ans);
	return 0;
}

赛时得分: 0 / 100

赛时思路:

呃啊!真是令人眼前一黑呢……

由于某些特殊原因,在此只好只讲做法了……

Step 1: aia_i 集体 −k-k ;

Step 2:定义: si=∑j=1    iajs_i = \sum_{j = 1}^{\;\;i}a_j (就是做了个前缀和而已。);

Step 3:利用树状数组求一些奇奇怪怪的东西。

正解代码:

把赛事代码去掉freopen()所占的两行(及注释)即可。

正解思路:

逆……序……对…………

去掉…………

剩下的……非逆序对…………

(吐血而亡QAQ……)\color{white}{(吐血而亡\mathbb{QAQ}……)}

原文