zoukankan      html  css  js  c++  java
  • 【题解】Luogu CF915E Physical Education Lessons

    原题传送门:CF915E Physical Education Lessons

    前置芝士:珂朵莉树

    窝博客里对珂朵莉树的介绍

    没什么好说的自己看看吧

    这道题很简单啊

    每个操作就是区间赋值,顺带把总和修改一下,这样会快多了,所以我又成了洛咕最优解第二(好像比23forever dalao快,玄学???)

    #pragma GCC optimize("O3")
    #include <bits/stdc++.h>
    #define IT set<node>::iterator
    using namespace std;
    inline int read()
    {
        register int x=0,f=1;register char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    struct node
    {
        int l,r;
        mutable bool v;
        node(int L, int R=-1, bool V=0):l(L), r(R), v(V) {}
        bool operator<(const node& o) const
        {
            return l < o.l;
        }
    };
    set<node> s;
    int sum=0;
    IT split(int pos)
    {
        IT it = s.lower_bound(node(pos));
        if (it != s.end() && it->l == pos) 
            return it;
        --it;
        int L = it->l, R = it->r;
        bool V = it->v;
        s.erase(it);
        s.insert(node(L, pos-1, V));
        return s.insert(node(pos, R, V)).first;
    }
    void assign_val(int l,int r,bool val)
    {
        IT itr = split(r+1), itl = split(l), it = itl;
        for( ;itl != itr; ++itl)
            sum-=itl->v*(itl->r-itl->l+1);
        s.erase(it,itr);
        s.insert(node(l,r,val));
        sum+=val*(r-l+1);
    }
    int main()
    {
    	int n=read(),m=read();
    	s.insert(node(1,n,1));
    	sum=n;
    	while(m--)
    	{
    		int l=read(),r=read(),op=read();
    		if(op==1)
    			assign_val(l,r,0);
    		else
    			assign_val(l,r,1);
    		printf("%d
    ",sum);
    	}
    	return 0;
    }
    
  • 相关阅读:
    程序数据集算地数据库
    使用属性升级mybank
    第一个C#程序
    CSS3动画
    定位网页元素的解析
    CSS3中的浮动
    CSS中的盒子模型
    (十三)mybatis 整合 ehcache
    (十二)mybatis 查询缓存
    (十一)延迟加载
  • 原文地址:https://www.cnblogs.com/yzhang-rp-inf/p/9775249.html
Copyright © 2011-2022 走看看