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 }
  • 相关阅读:
    Sitecore安全:访问权限
    Sitecore 8.2 防火墙规则的权威指南
    Sitecore 8.2 安全性第2部分:安全性编辑器和Access Viewer
    Sitecore安全性第1部分:自定义角色和权限
    Sitecore 8.2 Admin用户帐户解锁
    Sitecore 8.2 数据库权限设置
    cesium 结合 geoserver 实现地图属性查询(附源码下载)
    Vue&Cesium&Ribbon界面: 将桌面GIS搬进浏览器
    leaflet图斑历史时空播放(附源码下载)
    openlayers6结合geoserver实现地图属性查询(附源码下载)
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/8682148.html
Copyright © 2011-2022 走看看