首页 > 其他 > 详细

CF915E Physical Education Lessons

时间:2019-12-12 21:38:24      阅读:97      评论:0      收藏:0      [点我收藏+]

CF915E Physical Education Lessons

题目

连接

题解

动态开点线段树裸题

#include<bits/stdc++.h>

using namespace std;
 
#define ll long long
#define re register
 
inline ll read()
{
    ll f = 1,x = 0;
    char ch;
    do
    {
        ch = getchar();
        if(ch == -) f = -1;
    }while(ch<0||ch>9);
    do
    {
        x = (x<<3) + (x<<1) + ch - 0;
        ch = getchar();
    }while(ch>=0&&ch<=9);
    return f*x;
}

const int MAXN = 3e5 + 10;

int n,q;
int lc[MAXN*50],rc[MAXN*50],sum[MAXN*50],add[MAXN*50],tot;
int root;

inline void pushdown(int o,int l,int r)
{
    if(!add[o]) return;
    int mid = (r+l)>>1;
    if(!lc[o]) lc[o] = ++tot;
    sum[lc[o]] = (add[o]-1)*(mid-l+1);
    add[lc[o]] = add[o];
    if(!rc[o]) rc[o] = ++tot;
    sum[rc[o]] = (add[o]-1)*(r-mid);
    add[rc[o]] = add[o];
    add[o]=0;
    return;
}

inline void update(int &rt,int l,int r,int x,int y,int v)
{
    if(!rt) rt = ++tot;
    if(x<=l&&y>=r)
    {
        sum[rt] = v * (r - l + 1);
        add[rt] = v+1;
        return;
    }
    int mid = (l+r)>>1;
    if(x>r||l>y) return;
    pushdown(rt,l,r);
    update(lc[rt],l,mid,x,y,v);
    update(rc[rt],mid+1,r,x,y,v);
    sum[rt]=sum[lc[rt]]+sum[rc[rt]];
    return;
}

int main()
{
    n = read(),q = read();
    for(int i=1;i<=q;i++)
    {
        int l = read(),r = read(),k = read();
        if(k==1)
        {
            update(root,1,n,l,r,1);
        }
        if(k==2)
        {
            update(root,1,n,l,r,0);
        }
        printf("%d\n",n-sum[root]);
    }
}

 

CF915E Physical Education Lessons

原文:https://www.cnblogs.com/wlzs1432/p/12031304.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!