首页 > 其他分享 >Codeforces Round 894 G

Codeforces Round 894 G

时间:2023-12-07 21:11:08浏览次数:44  
标签:pre 894 int 间隔 Codeforces cin st1 st Round

玩一下样例就能知道 这个是和 每个seg的最大间隔相关
为了好写我们可以直接写成元素间隔
这样我们用两个multiset维护元素间隔以及元素即可
注意删除的时候我们只删一个值 需要删指针
还有考虑长度为1的情况

multiset<int>st,st1;
void Erase(int x){
    auto it=st1.lower_bound(x);
    st1.erase(it);
}
void solve(){
    st.clear();st1.clear();
    int n;cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        st.insert(a[i]);
    }
    int pre=-1;
    for(auto i:st){
        if(pre!=-1)st1.insert(i-pre);
        pre=i;
    }
    int q;cin>>q;
    while(q--){
        int pos,x;cin>>pos>>x;
        if(n==1){
            a[1]=x;
            cout<<a[1]<<' ';
            continue;
        }
        auto it=st.lower_bound(a[pos]);
        if(it!=st.begin()&&it!=prev(st.end())){
            auto itl=prev(it);
            auto itr=next(it);
            Erase(*it-*itl);
            Erase(*itr-*it);
            st1.insert(*itr-*itl);
        }else if(it!=st.begin()){
            auto itl=prev(it);
            Erase(*it-*itl);
        }else if(it!=prev(st.end())){
            auto itr=next(it);
            Erase(*itr-*it);
        }
        auto ii=st.lower_bound(a[pos]);
        st.erase(ii);
        a[pos]=x;
        st.insert(a[pos]);
        it=st.lower_bound(a[pos]);
        if(it!=st.begin()&&it!=prev(st.end())){
            auto itl=prev(it);
            auto itr=next(it);
            st1.insert(*it-*itl);
            st1.insert(*itr-*it);
            Erase(*itr-*itl);
        }else if(it!=st.begin()){
            auto itl=prev(it);
            st1.insert(*it-*itl);
        }else if(it!=prev(st.end())){
            auto itr=next(it);
            st1.insert(*itr-*it);
        }
        cout<<*st1.rbegin()+*st.rbegin()<<' ';
    }cout<<endl;
}

标签:pre,894,int,间隔,Codeforces,cin,st1,st,Round
From: https://www.cnblogs.com/ycllz/p/17883956.html

相关文章

  • Codeforces Round 913 (Div. 3)
    CodeforcesRound913(Div.3)比赛链接ROOK题目思路:我没有下过国际象棋,但这个题跟国际象棋真是没有一点关系,就是一个简单的输出代码:#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){//intn;strings;cin>>s;in......
  • CodeForces 1901F Landscaping
    洛谷传送门CF传送门还是很有趣的一道题。场上直接暴拆式子,要维护动态凸包,本来以为是\(\log^2\)的,写着写着发现是\(\log^3\),遂弃。显然梯形面积最小等价于\(y_0+y_1\)最小,而\(y_0+y_1\)最小等价于梯形在\(m=\frac{n}{2}\)处最小。把上凸包建出来,发现过\(x=m......
  • KubeSphere Marketpalce 上新!Databend Playground 助力快速启动数据分析环境
    12月5日,DatabendLabs旗下DatabendPlayground(社区尝鲜版)成功上架青云科技旗下KubeSphereMarketplace云原生应用扩展市场,为用户提供一个快速学习和验证Databend解决方案的实验环境。关于DatabendPlaygroundDatabend是使用Rust研发、完全⾯向云架构、基于对象存......
  • Codeforces Round 913 (Div. 3)
    CodeforcesRound913(Div.3)div3两题新纪录..我再也不喝完酒打cf了A.Rook#include<bits/stdc++.h>//#defineintlonglong#defineendl'\n'usingnamespacestd;intboard[10][10];voidsolve(){strings;cin>>s;intx=s[0]-&#......
  • 【题解】CodeForces 1902F Trees and XOR Queries Again
    传送门:https://codeforces.com/contest/1902/problem/F数据结构题,这里讲两种思路。$ST$表思路:判定“从若干个数中能否取出其中一些,使得异或和为$x$”的问题,第一时间想到线性基,本题要做的显然就是快速求出询问路径上所有数的线性基。两组数的线性基可以合并,方法为“暴力将......
  • Educational Codeforces Round 158 (Rated for Div. 2)
    Preface补题,妈的现在EduE都做不来这搞毛啊A.LineTrip签到#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<queue&......
  • Codeforces Round 913 (Div. 3)(A~F)
    A.Rook题意:在一个国际象棋棋盘中,横坐标为a-h,纵坐标为1-8,字母在前,数字在后,输入一个棋子的位置,输出该棋子所在的行与列中非棋子本身位置的所有位置。分析:模拟。代码:#include<iostream>#include<algorithm>usingnamespacestd;typedeflonglongll;constintN=2e5......
  • 【题解】CodeForces 686E Optimal Point
    传送门:https://codeforces.com/contest/686/problem/E前言:本题解来源于作者某天晚上和一位朋友的发电内容(没错,这个作者直接把自己和朋友发电时发的话用markdown排了一下,传上来了),当时本来就比较口语化,加上作者的做法又实在太过离谱,因此可能语言表述不够清晰,对此深感抱歉qwq;离......
  • 【论文阅读笔记】【多模态-Referring & Grounding】 Grounded Language-Image Pre-tra
    GLIPCVPR2022(Oral,BestPaperFinalist)读论文思考的问题论文试图解决什么问题?写作背景是什么?问题:如何将视觉-语言预训练技术应用在以目标检测为代表的fine-grainedimageunderstanding上面?如何在增加训练数据的同时,使目标检测模型具有良好的语义理解能力,能......
  • Codeforces Round 912 (Div. 2)
    Preface这场题莫名很对我胃口,因为F是个究极套路题,还是我最拿手的2-SAT,想+写不到半小时就搞定了然后E的核心思想和上周末VP的一场省赛的题一样,因此看一眼就会了唯一抽象的是D2要用对超集的sosdp,由于之前没写过就不知道还能这么搞A.HalloumiBoxes当\(k\ge2\)时,我们总可以通......