首页 > 编程知识 正文

多个单调区间合并,欧赔核心思维区间骨架

时间:2023-05-06 18:43:24 阅读:261668 作者:4847

https://codeforces.com/problemset/problem/1102/E

思路:模拟发现肯定是单调不减的序列。且相同颜色的一块最后要合成一整块相同的算其贡献。开始自己map+差分搞有地方理解错误,而且自己的处理对于1个长度的区间不好处理。

所以处理时转化成对0的位置++,对于一个区间的位置我们不必给他记录差分,对于一个区间我们记录[l+1]++,[r+1]--就好。

#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=2e5+1000;typedef long long LL;const LL mod=998244353;inline LL read(){LL x=0,f=1;char ch=getchar();while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}return x*f;}LL a[maxn],cnt[maxn];map<LL,LL>map1;LL ksm(LL a,LL k){ LL res=1; while(k>0){ if(k&1) res=res*a%mod; k>>=1; a=a*a%mod; }return res%mod;}int main(void){ cin.tie(0);std::ios::sync_with_stdio(false); LL n;cin>>n; for(LL i=1;i<=n;i++) cin>>a[i]; for(LL i=1;i<=n;i++){ if(!map1.count(a[i])){ map1[a[i]]=i; } else{ cnt[map1[a[i]]+1]++;///这么处理方便一个长度区间的处理 cnt[i+1]--; map1[a[i]]=i;///更新与否无所谓 } } LL sum=0; for(LL i=2;i<=n;i++){ cnt[i]+=cnt[i-1]; if(cnt[i]==0) sum++; } cout<<ksm(2,sum%mod)%mod<<"n";return 0;}

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。