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

    This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson!

    Since Alex doesn't want to get expelled, he wants to know the number of working days left until the end of the term, so he can attend physical education lessons during these days. But in BSU calculating the number of working days is a complicated matter:

    There are n days left before the end of the term (numbered from 1 to n), and initially all of them are working days. Then the university staff sequentially publishes q orders, one after another. Each order is characterised by three numbers l, r and k:

    • If k = 1, then all days from l to r (inclusive) become non-working days. If some of these days are made working days by some previous order, then these days still become non-working days;
    • If k = 2, then all days from l to r (inclusive) become working days. If some of these days are made non-working days by some previous order, then these days still become working days.

    Help Alex to determine the number of working days left after each order!

    Input

    The first line contains one integer n, and the second line — one integer q (1 ≤ n ≤ 109, 1 ≤ q ≤ 3·105) — the number of days left before the end of the term, and the number of orders, respectively.

    Then q lines follow, i-th line containing three integers li, ri and ki representing i-th order (1 ≤ li ≤ ri ≤ n, 1 ≤ ki ≤ 2).

    Output

    Print q integers. i-th of them must be equal to the number of working days left until the end of the term after the first i orders are published.

    Example
    Input
    Copy
    4
    6
    1 2 1
    3 4 1
    2 3 2
    1 3 2
    2 4 1
    1 4 2
    Output
    2
    0
    2
    3
    1
    4
    线段树动态开点,区间修改查询
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<queue>
     7 using namespace std;
     8 queue<int>Q;
     9 int pos,ch[15000001][2],c[15000001],n,q,lazy[15000001],root;
    10 void pushdown(int rt,int l,int mid,int r)
    11 {
    12   if (lazy[rt])
    13     {
    14       if (!ch[rt][0]&&lazy[rt]==2)
    15     ch[rt][0]=++pos;
    16       if (!ch[rt][1]&&lazy[rt]==2)
    17     ch[rt][1]=++pos;
    18       lazy[ch[rt][0]]=lazy[rt];
    19       lazy[ch[rt][1]]=lazy[rt];
    20       c[ch[rt][0]]=(lazy[rt]-1)*(mid-l+1);
    21       c[ch[rt][1]]=(lazy[rt]-1)*(r-mid);
    22       lazy[rt]=0;
    23     }
    24 }
    25 void update(int &rt,int l,int r,int L,int R,int d)
    26 {
    27   if (!rt)
    28     {
    29       if (Q.empty()==0) rt=Q.front();
    30       else rt=++pos;
    31     }
    32   if (l>=L&&r<=R)
    33     {
    34       c[rt]=d*(r-l+1);
    35       lazy[rt]=d+1;
    36       return;
    37     }
    38   int mid=(l+r)/2;
    39   pushdown(rt,l,mid,r);
    40   if (L<=mid) update(ch[rt][0],l,mid,L,R,d);
    41   if (R>mid) update(ch[rt][1],mid+1,r,L,R,d);
    42   c[rt]=c[ch[rt][0]]+c[ch[rt][1]];
    43 }
    44 int main()
    45 {int l,r,k;
    46   cin>>n>>q;
    47   while (q--)
    48     {
    49       scanf("%d%d%d",&l,&r,&k);
    50       if (k==1)
    51     {
    52       update(root,1,n,l,r,1);
    53     }
    54       else
    55     {
    56       update(root,1,n,l,r,0);
    57     }
    58       printf("%d
    ",n-c[root]);
    59     }
    60 }
  • 相关阅读:
    mybatis date类型比较
    搭建 c 语言环境 1_centos6 minimal 配置 c/c++ 编译环境
    2_eclipse配置c/c++环境
    1_eclipse导入hibernate 的DTD 文件
    1_eclipse配置c/c++开发环境
    2_修改Eclipse里面的快捷键
    1_修改注释内容
    8_对象创建、static 关键字、静态变量和成员变量的区别、文档
    7_匿名对象、封装(private)、this 关键字、构造方法
    6_面向对象基础、成员变量和局部变量的区别
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/8682148.html
Copyright © 2011-2022 走看看