链接

分析:

  每次操作把以前没有出现这个数的设为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. [WPF 基础知识系列] —— 绑定中的数据校验Vaildation

    前言: 只要是有表单存在,那么就有可能有对数据的校验需求.如:判断是否为整数.判断电子邮件格式等等. WPF采用一种全新的方式 - Binding,来实现前台显示与后台数据进行交互,当然数据校验方式也 ...

  2. Prometheus Node_exporter 之 System Detail

    System Detail 1. Context Switches / Interrupts type: GraphUnit: shortLabel: CounterContext switches ...

  3. 在IE中,JS方法名和input的name重名时,调用该方法无效

    在IE中,JS方法名和input的name重名时,调用该方法无效.提示:网页错误详细信息 用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1 ...

  4. vscode 折叠所有区域代码的快捷键

    折叠:ctrl + L    ctrl + 0(主键盘区的0,不是小键盘区的0) 展开:ctrl + K    ctrl + J 老是忘记,在此记录

  5. sqlite 字符串拼接

    select path || '%'  from t_category where depth = 0 and type = 0 用'||'拼接字符串 比如path是/1001/的话 那结果就是/10 ...

  6. 利用percona-toolkit定位数据库性能问题

    当你的性能瓶颈卡在数据库这块的时候,可以通过percona-toolkit来进行问题定位. 那么,首先,介绍下percona-toolkit.percona-toolkit是一组高级命令行工具的集合, ...

  7. MySQL锁系列之锁的种类和概念

    转自:http://keithlan.github.io/2017/06/05/innodb_locks_1/ 锁是MySQL里面最难理解的知识,但是又无处不在. 一开始接触锁的时候,感觉被各种锁类型 ...

  8. 转:Newtonsoft.Json高级用法

    原文地址:http://www.cnblogs.com/yanweidie/p/4605212.html 手机端应用讲究速度快,体验好.刚好手头上的一个项目服务端接口有性能问题,需要进行优化.在接口多 ...

  9. 虚拟机克隆linux centos 6.5 系统网卡配置

    作为一个刚刚接触linux系统的小白来说,VMware虚拟机安装好CentOS6.5系统后,纯净的系统多克隆几份出来方便后期做试验.克隆步骤很简单,克隆后出现的问题是克隆后的网卡MAC地址和原系统MA ...

  10. Scala学习之路 (二)使用IDEA开发Scala

    目前Scala的开发工具主要有两种:Eclipse和IDEA,这两个开发工具都有相应的Scala插件,如果使用Eclipse,直接到Scala官网下载即可http://scala-ide.org/do ...