zoukankan      html  css  js  c++  java
  • Codeforces 915E Physical Education Lessons

    题意简述

    维护序列,支持以下操作:

    • 区间赋1/0
    • 求整个区间之和

    题解思路

    珂朵莉树暴力赋值,查询

    代码

    #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
    ",sum);
    	}
    }
    
  • 相关阅读:
    HBase 负载均衡
    HBase的写事务,MVCC及新的写线程模型
    HBase RegionServer宕机处理恢复
    分布式事务实现-Percolator
    MVC框架
    06-JS中li移动第二种形式
    05-JS中li移动第一种形式
    04-JS中文档碎片
    03-JS中添加节点
    02-JS中父节点
  • 原文地址:https://www.cnblogs.com/xuyixuan/p/11360829.html
Copyright © 2011-2022 走看看