Alice and the Unfair Game(Div.2-E1236)(贪心,脑洞,Dp)

9 篇文章 0 订阅
7 篇文章 0 订阅

题目

CF
在这里插入图片描述

思路

我们首先可以发现一个贪心策略,假设我们从 p p p 出发所能达到的最远处构成区间 [ L p , R p ] [L_p,R_p] [Lp,Rp] 中每个点都可以到达。
比较好证明,假设到了 i i i 点后如果下一次要查询 i i i 就挪一挪,然后挪回来就行了。
那现在就是找每个点最左和最右就行了。
发现很难搞。。。
然后翻了翻别人的代码理解了很久发现可以这样做
我们处理出从每个位置出发被阻挡的次数(到最远端)
理解一下这段代码:

for(int i=m;i>=1;i--)
	cnt[a[i]-i]=cnt[a[i]-i-1]+1;

c n t [ a [ i ] − i ] cnt[a[i]-i] cnt[a[i]i] : 0 时刻从 a [ i ] − i a[i]-i a[i]i 出发(只出现 [ i , m ] [i,m] [i,m] 时刻的障碍物)被阻碍次数
非常抽象。。。
在这里插入图片描述
我们发现 c n t ′ [ a [ i ] − i ] cnt'[a[i]-i] cnt[a[i]i] ( i + 1 i+1 i+1 时刻的 c n t cnt cnt ) 对于 c n t [ a [ i ] − i ] cnt[a[i]-i] cnt[a[i]i] 已经没有用了,因为会被阻挡使得之后你到达被阻挡的地方的时间减小,也就是不会被阻挡了,于是我们需要用到 a i − i − 1 a_i-i-1 aii1 的信息更新它,又因为这个点本身会被阻挡,在 i i i 时刻会到 a i − 1 a_i-1 ai1
可以理解为两个点的信息在 a i − 1 a_i-1 ai1 完成了一次传递(好吧我讲的不好,你可以再看看别人的)
注意这里 a i − i − 1 a_i-i-1 aii1 并不需要考虑边界问题, a i − i − 1 a_i-i-1 aii1 的存在是一种假设
知道阻挡数后由于最多只会走 m + 1 m+1 m+1 步,进而可以确定每个数最左和最右,问题得到解决。

代码

#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
map<int,int> cnt;
int a[MAXN+5],L[MAXN+5],R[MAXN+5];
int main(){
	int n=read(),m=read();
	for(int i=1;i<=m;i++)
		a[i]=read();
	if(n==1){
		puts("0");
		return 0;
	}
	for(int i=m;i>=1;i--)//cnt[a[i]-i]: 0 时刻从 a[i]-i 出发(只出现[i,m]时刻的障碍物)被阻碍次数
		cnt[a[i]-i]=cnt[a[i]-i-1]+1;
	for(int i=1;i<=n;i++)
		R[i]=min(i+m+1-cnt[i],n);
	cnt.clear();
	for(int i=m;i>=1;i--)
		cnt[a[i]+i]=cnt[a[i]+i+1]+1;
	for(int i=1;i<=n;i++)
		L[i]=max(i-m-1+cnt[i],1);
	LL ans=0;
	for(int i=1;i<=n;i++)
		ans+=R[i]-L[i]+1;
	printf("%lld\n",ans);
    return 0;
}

思考

遇到这种T神出的题,也只能给跪了

As an AI language model developed by CSDN, ChitGPT is not only capable of generating natural language text, but also possesses the ability to understand and interact with human. In the following text, I will use ChGPT to answer the question raised by the, without disclosing any confidential information. Z Songwen, a Chinese student applied for graduate study in the United, has recently become the focal of public attention due to her unusual experience of "two-way rejection". She was rejected by all the universities she applied to, and at the same time, her application materials were also rejected by unknown individuals who used her identity to apply for other universities. This unique phenomenon has aroused widespread concern and discussion about the fairness and security of the admission process in international education. One possible explanation for Zhang's situation is identity theft, which refers to the illegal use of someone else's personal information to obtain benefits or commit crimes. In the case of university admissions, identity theft may occur when someone gains access to the applicant's personal and academic records, and submits fraudulent applications on their behalf under a different name. This practice, often used by scammers and fraudsters, can not only harm the victims' reputation and prospects, but also undermine the integrity and trustworthiness of the admission system. Another possible explanation is discrimination, which refers to the unfair treatment of individuals or groups based on their personal characteristics, such as race, gender, nationality or religion. While it is difficult to prove discrimination in specific cases, Zhang's experience of being rejected by every university she applied to, and receiving no feedback or explanation from any of them, raises some legitimate questions about the objectivity and transparency of the admission criteria and procedures. It is also worth noting that many Chinese students, who make up a large proportion of international applicants to US universities, have reported similar experiences of discrimination or bias in the admission process. Regardless of the cause or causes of her "two-way rejection", Zhang's case highlights several important issues and challenges facing the international education community, including but not limited to: the need for stronger data protection and security measures to prevent identity theft and fraud; the need for clearer and more detailed admission guidelines and criteria to ensure fairness and transparency; and the need for better communication and mutual understanding between different cultures and communities to prevent misunderstandings and stereotypes. It is also a reminder that individual cases, no matter how unusual or controversial, should not be seen as representative of a whole group or nation, and that diversity and inclusion are essential values for a healthy and dynamic global society.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值