链接

分析:

  每次操作把以前没有出现这个数的设为1,有这个数的设为0。首先将当前区间设为1,考虑有set维护这个颜色出现的区间,然后把所有与当前区间相交的拿出来,修改为0。

  复杂度?每次操作的线段只会加入到一次set中,从set中取出一次,只会修改一次,然后就合并成大的了,每次操作也只会加入一条线段。

代码:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
#define pa pair<int,int>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
set< pa > s[N];
int n; struct SegmentTree{
int sum[N << ], tag[N << ], n;
SegmentTree() { memset(tag, -, sizeof(tag)); }
void pushdown(int rt,int len) {
tag[rt << ] = tag[rt], tag[rt << | ] = tag[rt];
sum[rt << ] = tag[rt] * (len - len / );
sum[rt << | ] = tag[rt] * (len / );
tag[rt] = -;
}
void update(int l,int r,int rt,int L,int R,int v) {
if (L > R) return ;
if (L <= l && r <= R) { tag[rt] = v, sum[rt] = v * (r - l + ); return ; }
if (~tag[rt]) pushdown(rt, r - l + );
int mid = (l + r) >> ;
if (L <= mid) update(l, mid, rt << , L, R, v);
if (R > mid) update(mid + , r, rt << | , L, R, v);
sum[rt] = sum[rt << ] + sum[rt << | ];
}
int query(int l,int r,int rt,int L,int R) {
if (L <= l && r <= R) return sum[rt];
if (~tag[rt]) pushdown(rt, r - l + );
int mid = (l + r) >> , res = ;
if (L <= mid) res = query(l, mid, rt << , L, R);
if (R > mid) res += query(mid + , r, rt << | , L, R);
return res;
}
}T;
void Insert() {
int x = read(), y = read(), k = read(), l = max(, x - k), r = min(n, x + k), nowl = l, nowr = r;
if (s[y].empty()) {
T.update(, n, , l, r, );
s[y].insert(pa(l, r)); return ;
}
set< pa > :: iterator it = s[y].lower_bound(pa(l, ));
set< pa > :: iterator pre = it; if (it != s[y].begin()) {
pre --;
if (pre->second >= l) it = pre;
}
if (it == s[y].end() || (it->first) > r) {
T.update(, n, , l, r, );
s[y].insert(pa(l, r)); return ;
}
nowl = min(nowl, it->first);
T.update(, n, , l, r, );
while (it != s[y].end() && (it->first) <= r) {
T.update(, n, , max(l, it->first), min(r, it->second), );
nowr = max(nowr, it->second);
pre = it; it ++; s[y].erase(pre);
}
s[y].insert(pa(nowl, nowr));
}
void query() {
int l = read(), r = read();
printf("%d\n", T.query(, n, , l, r));
}
int main() {
n = read();int m = read();
for (int i = ; i <= m; ++i) {
if (read() == ) Insert();
else query();
}
return ;
}

51nod 小朋友的笑话的更多相关文章

  1. 51nod“省选”模测第二场 C 小朋友的笑话(线段树 set)

    题意 题目链接 Sol 直接拿set维护\(li\)连续段.因为set内的区间互不相交,而且每个线段会被至多加入删除一次,所以复杂度是对的. #include<bits/stdc++.h> ...

  2. 51nod 省选联测 R2

    51nod 省选联测 R2 上场的题我到现在一道都没A,等哪天改完了再写题解吧,现在直接写第二场的. 第二场比第一场简单很多(然而这并不妨碍我不会做). A.抽卡大赛:http://www.51nod ...

  3. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  4. 51Nod 1268 和为K的组合

    51Nod  1268  和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...

  5. 51Nod 1428 活动安排问题

    51Nod   1428  活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...

  6. 51Nod 1278 相离的圆

    51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...

  7. 【51Nod 1501】【算法马拉松 19D】石头剪刀布威力加强版

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1501 dp求出环状不连续的前缀和,剩下东西都可以算出来,比较繁琐. 时间 ...

  8. 【51Nod 1622】【算法马拉松 19C】集合对

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1622 简单题..直接暴力快速幂 #include<cstdio&g ...

  9. 【51Nod 1616】【算法马拉松 19B】最小集合

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1616 这道题主要是查询一个数是不是原有集合的一个子集的所有数的gcd. ...

随机推荐

  1. Python+Selenium笔记(十八):持续集成jenkins

    (一)安装xmlrunner 使用Jenkins执行测试时,测试代码中会用到这个模块. pip install xmlrunner (二)安装jenkins (1)   下载jekins https: ...

  2. Python+Selenium笔记(十七):操作cookie

    (一)方法 方法 简单说明 add_cookie(cookie_dict) 在当前会话中添加cookie信息 cookie_dict:字典,name和value是必须的 delete_all_cook ...

  3. python中pip

    经常在安装软件过程中用pip 安装,当时的我总觉得pip是给linux还有mac用的,所以就从没有仔细研究过pip,后来用了python才知道pip这么好用 今天总结一下pip的用法 我的电脑是win ...

  4. PHP的数据加密解密

    本文出至:新太潮流网络博客 /** * [对数据进行加密] * @E-mial wuliqiang_aa@163.com * @TIME 2017-04-07 * @WEB http://blog.i ...

  5. Knockout学习,添加模板,事件,Mouseover,mouseout

    <div class="rtitle">我的收藏</div> <div class="list_ul" data-bind=&qu ...

  6. C#DateTime.ToString 格式化时间字符串和数值类型转换为字符串

    我们经常会遇到对时间进行转换,达到不同的显示效果,默认格式为:2006-6-6 14:33:34,如果要换成200606,06-2006,2006-6-6或更多的格式该怎么办呢?这里将要用到:Date ...

  7. The Downside of MySQL Auto-reconnect

    A few days ago I was doing some cleanup on a passive master database using the MySQL client. I didn’ ...

  8. vcenter server appliance(vcsa) 配置IP的方法

    方法一: vcenter server appliance 5.1 及以后版本包括5.5,在安装完毕后,console界面是没有网络配置项的,如果需要进行IP配置,可以login后,输入命令yast( ...

  9. CSS3的新增选择器

    一.兄弟选择器:选择E元素所有兄弟元素F. <style> p~p{ color:#f00;} </style> </head> <body> < ...

  10. docker swarm英文文档学习-5-在swarm模式中运行Docker引擎

    Run Docker Engine in swarm mode在swarm模式中运行Docker引擎 当你第一次安装并开始使用Docker引擎时,默认情况下禁用swarm模式.在启用集群模式时,需要处 ...