题目描述

小明家有n个信箱,前前后后来送信和取信的总次数为q,称为q次访问,其中这q次访问分成三种类型。

1:邮递员送来了一封信,放在了x号信箱。

2:小明取走了x号信箱的所有信(x信箱可能已经没有信了)。

3:小明取走了前t封送来的信(前t封表示从送来的第一封到送来的第t封,其中这t封信可能已经通过第二类或者之前的第三类访问取走了)

小明现在想要知道每一次访问之后,有多少封信时没有取走的,由于送来的信太多,小明想请学oi的你来解答。

输入

输入文件B.in

第一行两个整数n,q。

接下来q行,每行最开始一个整数type

若type=1紧接着一个整数x,表示第一类操作。

若type=2紧接着一个整数x,表示第二类操作。

若type=3紧接着一个整数t,表示第三类操作。

输出

输出文件B.out

对于每一次访问,输出访问结束时剩下多少信还没有被取走。

样例输入

3 4
1 3
1 1
1 2
2 3

样例输出

1
2
3
2

提示

【样例输入2】

4 6
1 2
1 4
1 2
3 3
1 3
1 3

【样例输出2】

1
2
3
0
1
2

【数据范围】

对于30%的数据,$ n,q \le 1000 \(
对于另外20%的数据,没有三操作。
对于100%的数据,\) n,q \le 300000 $

这个题说来我挺zz的,完全不知道自己在想什么.....

直接线段树 + 链表就能怼过去的事,结果我非要写线段树 + 时间戳 + 删除线段

这不是给自己找麻烦嘛....于是写了一会儿果断放弃(反正本来也不太会)

于是就开始 \(YY\) 怎么写链表了,写的时候被自己蠢到哭,单点修改非要写成左右端点相同的区间修改

觉得不用自上向下更新,就死活不想写 $ tag $ ,结果就是一直WA.....

改正之后好歹能过了~~

用线段树维护链表,其实是一堆链表...有点邻接表的意思

然后每次操作是对链表的,注意 $ 2 $ 操作别忘了把一整个链表删干净...最后别忘了重置链表

$ 3 $ 操作直接在线段树上区间修改就行了,也不难

$ 1 $ 操作先在插入链表再更新至线段树,注意线段树维护的是链表就行了

代码如下:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#define Noip2018RpINF return 0
#define ls ( rt << 1 )
#define rs ( rt << 1 | 1 )
#define mid ( ( l + r ) >> 1 )
#define pushup(rt) t[rt].data = t[ls].data + t[rs].data
#define LL long long const LL N = 3e5 + 5 ; struct seg{
LL left , right ;
LL data , tag;
}t[ ( N << 2 ) ]; LL n , m , x , tot ;
LL opt , pre[N] , nxt[N] ; inline void build ( LL rt , LL l , LL r ){
t[rt].left = l ; t[rt].right = r ;
if ( l == r ) return ;
build ( ls , l , mid ) ; build ( rs , mid + 1 , r ) ;
pushup(rt) ; return ;
} inline void insert (LL rt , LL pos){
LL l = t[rt].left , r = t[rt].right ;
if ( l == r ) { t[rt].data = 1 ; return ; }
if ( pos <= mid ) insert ( ls , pos ) ;
else if ( pos > mid ) insert ( rs , pos );
pushup (rt) ; return ;
} inline void delet (LL rt , LL ll , LL rr){
if (t[rt].tag) return ;//现在来看,不写tag真是太zz了
LL l = t[rt].left , r = t[rt].right ;
if ( ll <= l && r <= rr ) { t[rt].data = 0 ; t[rt].tag = 1 ; return ; }
if ( ll <= mid ) delet( ls , ll , rr );
if ( rr > mid ) delet( rs , ll , rr );
pushup(rt) ; return ;
} inline void Rinsert (LL x){
nxt[++tot] = pre[x] ; pre[x] = tot ;
insert( 1 , tot ) ; return ; //把修改tot写成修改x真是太zz了
} inline void Rdelete (LL x){
for (int i = pre[x] ; i ; i = nxt[i] )
delet( 1 , i , i );
pre[x] = 0 ;//忘了归零真是太zz了
return ;
} int main(){
scanf ("%lld%lld" , & n , & m );
build( 1 , 1 , m ) ;//忘了建树真是太zz了(太真实了)
while ( m -- ){
scanf ("%lld%lld" , & opt , & x ) ;
if ( opt == 1 ) Rinsert ( x ) ;
if ( opt == 2 ) Rdelete ( x ) ;
if ( opt == 3 ) delet( 1 , 1 , x ) ;
printf ("%lld\n" , t[1].data ) ;
}
Noip2018RpINF ;
}

RDay2-Problem 2 B的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. c++入门之函数指针和函数对象

    函数指针可以方便我们调用函数,但采用函数对象,更能体现c++面向对象的程序特性.函数对象的本质:()运算符的重载.我们通过一段代码来感受函数指针和函数对象的使用: int AddFunc(int a, ...

  2. 解决Jenkins邮件配置问题

    最近要配置Jenkins邮箱,由于一直报如下错误,又没办法解决,所以想到了另外的办法发邮件. 我采用shell脚本执行python命令的方式来发邮件: #!/bin/bash cd /software ...

  3. Python如何将整数转化成二进制字符串

    Python 如何将整数转化成二进制字符串 1.你可以自己写函数采用 %2 的方式来算. >>> binary = lambda n: '' if n==0 else binary( ...

  4. Uint 7.文本和字体属性,background,精灵图和3种定位

    一. 文本属性 CSS 文本属性可定义文本的外观. 通过文本属性,您可以改变文本的颜色.字符间距,对齐文本,装饰文本,对文本进行缩进,等等. <!DOCTYPE html> <htm ...

  5. ReSharper 2017破解详细方法:

    VS里面,打开ReSharper的注册窗口:ReSharper ——> Help ——> License Information... Use License Server,右侧加号,点击 ...

  6. Shell命令-文件压缩解压缩之gzip、zip

    文件及内容处理 - gzip.zip 1.gzip:gzip压缩工具 gzip命令的功能说明 gzip 命令用于压缩文件.gzip 是个使用广泛的压缩程序,文件经它压缩过后,其名称后面会多出 .gz ...

  7. 在CENTOS上源码搭建LNMP环境

    前言 1.操作前提: CentOS Linux release 7.5.1804: sudo用户(需要root权限): 2.需要安装的组件: nginx稳定版:nginx-1.14.0: MariaD ...

  8. HashMap底层实现原理

    HashMap底层实现 HashMap底层数据结构如下图,HashMap由“hash函数+数组+单链表”3个要素构成 通过写一个迷你版的HashMap来深刻理解 MyMap接口,定义一个接口,对外暴露 ...

  9. ZOJ 4097 Rescue the Princess

    在这个物欲横流的社会 oj冷漠无情 只有这xx还有些温度 越界就越界吧  wrong 怎么回事.... 给出一个图 然后给出q次询问 问是否存在v和w分别到u的路径且边不重复 在边双连通分量中 任意两 ...

  10. macOS 上编译 Dynamips

    Dynamips 是一个Cisco 路由器模拟软件. 安装过程: git clone git://github.com/GNS3/dynamips.git cd dynamips mkdir buil ...