首页 > 其他分享 >Codeforces Round #634 (Div. 3) E

Codeforces Round #634 (Div. 3) E

时间:2022-11-02 22:56:58浏览次数:64  
标签:634 int Codeforces st query ans return Div bound

E2. Three Blocks Palindrome (hard version)

我们考虑一种最优构造
对于一个数x 我们肯定要的是他的前几个 再最后几个 中间选最多的一个数
这样显然是最优的
我们枚举x 再枚举前面要的长度
中间选的最多的一个数可以通过logn求解
总的时间复杂度是O(nvlogn)

int n,a[N];
vector<int>st[201];
int find(int i,int x){return lower_bound(all(st[i]),x)-st[i].begin();}
int find1(int i,int x) {return upper_bound(all(st[i]), x) - st[i].begin();}
int query(int l,int r){
    int res=0;
    for(int i=1;i<=201;i++)
        res=max(res,find1(i,r)-find(i,l));
    return res;
}
void solve(){
    cin>>n;
    for(int i=1;i<=200;i++)st[i].clear();
    for(int i=1;i<=n;i++){
        cin>>a[i];
        st[a[i]].push_back(i);
    }
    int ans=1;
    for(int x=1;x<=200;x++){
        for(int len=1;len<=st[x].size();len++){
            int l=st[x][len-1],r=st[x][st[x].size()-len];
            if(l>=r)break;
            ans=max(ans,len*2+query(l+1,r-1));
        }
    }
    cout<<ans<<endl;
}

标签:634,int,Codeforces,st,query,ans,return,Div,bound
From: https://www.cnblogs.com/ycllz/p/16852850.html

相关文章

  • Codeforces Global Round 7 D
    D1.Prefix-SuffixPalindrome(Easyversion)easy版本我们只需要n2dp预处理出快速判断回文串然后我们再通过双指针O(n)求解最大串intdp[5010][5010];voidsolve(){......
  • Codeforces Round #820 (Div. 3) A-G
    比赛链接A题解知识点:模拟时间复杂度\(O(1)\)空间复杂度\(O(1)\)代码#include<bits/stdc++.h>#definelllonglongusingnamespacestd;boolsolve(){......
  • Codeforces Round #611 (Div. 3) E
    E.NewYearParties对于最大值我们显然可以sort之后贪心一下即可正确性显然对于最小值我们发现会有三种情况一种是三个挨在一起一种是两个挨在一起还有一种就是......
  • div'可拖拽宽度
    <template><divclass="x-handle"@mousedown="mouseDown"></div></template><script>exportdefault{name:'HandleEvent',data(){return{lastX:''......
  • J - Just Arrange the Icons CodeForces - 1267J (思维+暴力)
    题意n个软件,每个软件都有种类,而屏幕有容量s(自己决定),有两个限制:一个屏幕只能放s-1或者s个软件一个屏幕上只能防同种的软件求最小的屏幕数。思路枚举s代......
  • 「题解」Codeforces 1322B Present
    看上去异或里面套了层加法不好拆位,但是依然可以对每个二进制位处理。现在考虑第\(k\)位,那么产生贡献的数字对一定满足以下条件之一:第\(k\)位相同且前\((k-1)\)位......
  • 「题解」Codeforces 930E Coins Exhibition
    看到题就先容斥。然后容斥系数太难算了就寄了,大概要分好几种情况讨论,于是就弃了。不容斥也能做。考虑限制将串划分成了若干段,然后一段一段dp.有没有什么好的方法描述这个......
  • Codeforces - 1391C - Cyclic Permutations(思维 + 组合数学 + 数论 + 图论、*1500)
    1391C-CyclicPermutations(⇔源地址)目录1391C-CyclicPermutations(⇔源地址)tag题意思路AC代码错误次数:0tag⇔思维、⇔组合数学、⇔数论、⇔......
  • Codeforces Round #611 (Div. 3) D
    D.ChristmasTrees显然对于一个中间的点要是不能向两边最近的扩展我们直接判定他没有用处了这样我们就有了bfs的做法我们先把原点放进去要是能扩展我们显然可以直接......
  • Codeforces Round #667 (Div. 3) ABCD
    https://codeforces.com/contest/1409A.YetAnotherTwoIntegersProblem题目大意:k∈[1;10]我们每次可以选择a:=a+kora:=a−k问a要经历多少次操作变成b?input......