Codeforces 915E体育授業

問題の意味の説明

メンテナンスシーケンスは、次の操作をサポートします。

  • インターバルフー1/0
  • 要件の全範囲と

問題の解決策のアイデア

Keduo李ツリー暴力割り当て問い合わせ

コード

#include <set>
#include <cstdio>
#include <cctype>
#define IT std::set<Node>::iterator
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char ch,buf[1<<21],*p1=buf,*p2=buf;
inline void read(int& x) {
    for (ch=getc();!isdigit(ch);ch=getc());
    for (x=ch-'0';isdigit(ch=getc());x=x*10+ch-'0');
}
int q,l,r,opt,sum;
struct Node 
{
    int l,r; bool v;
    Node(const int& L,const int& R,const bool& V):l(L),r(R),v(V) {}
    bool operator <(const Node& x) const { return l<x.l; }
};
std::set<Node> s; 
inline IT split(const int& x) {
    IT it=s.lower_bound(Node(x,0,0));
    if (it!=s.end()&&it->l==x) return it;
    --it; int L=it->l,R=it->r; bool V=it->v; s.erase(it);
    s.insert(Node(L,x-1,V)); return s.insert(Node(x,R,V)).first;
}
int main() {
    read(sum);read(q);
    s.insert((Node){1,sum,1});
    for (;q;--q) {
        read(l);read(r);read(opt);
        IT itr=split(r+1),itl=split(l);
        for (register IT it=itl;it!=itr;++it) if (it->v) sum-=it->r-it->l+1;
        s.erase(itl,itr); s.insert(Node(l,r,--opt)); if (opt) sum+=r-l+1;
        printf("%d\n",sum);
    }
}

おすすめ

転載: www.cnblogs.com/xuyixuan/p/11360829.html