C. k-Amazing Numbers(思维前缀最小值+枚举相同数距离)

40 篇文章 0 订阅
15 篇文章 0 订阅

https://codeforces.com/contest/1417/problem/C


大晚上的想岔了..

a1,a2,…,an (1≤ai≤n)这个范围其实就在暗示要枚举出现的数。但是我不知道怎么恍惚看成1e9..

对于每个数,实际上就是考虑相同数之间最少需要多长的k才能都包含到。枚举一个数和序列开头,中间数之间的差,最后一个数和序列结尾。用一个ans[k]记录最少需要长度的k中最小的数字是哪个。ans[k]=min(ans[k],i);

最后注意还要维护一下ans[k]的前缀最小。因为长度为2能覆盖到最小值长度>2的必然能覆盖到。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+100;
typedef long long LL;
const LL inf=1e18;
LL ans[maxn]; 
vector<LL>v[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--)
  {
  	LL n;cin>>n;
  	for(LL i=0;i<=n+10;i++) ans[i]=inf,v[i].clear();
  	for(LL i=1;i<=n;i++){
  		LL x;cin>>x;v[x].push_back(i);	
	}
	for(LL i=1;i<=n;i++)
	{
		if(!v[i].empty())
		{
			LL mx=0;
			for(LL j=1;j<v[i].size();j++)
			{
				mx=max(mx,v[i][j]-v[i][j-1]);
			}
			mx=max(mx,v[i].front());
			mx=max(mx,n-v[i].back()+1);
			ans[mx]=min(ans[mx],i);
		}
	}
	for(LL i=2;i<=n;i++) ans[i]=min(ans[i],ans[i-1]);
	for(LL i=1;i<=n;i++){
		if(ans[i]<inf) cout<<ans[i]<<" ";
		else cout<<"-1"<<" ";
	} 
	cout<<endl;
  }
return 0;
}

 

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,以下是每个功能的输出结果: 情感分析: ```scala +--------------------+-----+--------------------+--------------------+--------------------+----------+ | text|label| words| filtered| features|prediction| +--------------------+-----+--------------------+--------------------+--------------------+----------+ |I loved this movi...| 1.0|[i, loved, this, ...|[loved, movie, gr...|(262144,[0,12,20,...| 1.0| |The acting was te...| 0.0|[the, acting, was...|[acting, terrible...|(262144,[0,4,7,8,...| 0.0| |This is the worst...| 0.0|[this, is, the, w...|[worst, movie, ev...|(262144,[0,1,2,3,...| 0.0| +--------------------+-----+--------------------+--------------------+--------------------+----------+ ``` 主题提取: ```scala +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ | text| words| filtered| features| topicDistribution| topicDescription| +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ |I loved this movi...|[i, loved, this, ...|[loved, movie, gr...|(262144,[0,12,20,...|[0.00367566411885...|[topic0 -> 0.0241...| |The acting was te...|[the, acting, was...|[acting, terrible...|(262144,[0,4,7,8,...|[0.00382668782116...|[topic0 -> 0.0241...| |This is the worst...|[this, is, the, w...|[worst, movie, ev...|(262144,[0,1,2,3,...|[0.00470716494738...|[topic0 -> 0.0241...| +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ ``` 关键词提取: ```scala Array[String] = Array(great, love, amazing, excellent, best, wonderful, fantastic, perfect, favorite, superb) ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值