Parking Lot

线段树区间合并一下, 求当前要占的位置, 不包括两端点的写起来方便一点。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m, tot, pos[];
PII gg[]; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
struct info {
PII mx;
int cnt, L, R;
} a[N << ];
info operator + (const info& a, const info& b) {
info c;
c.cnt = a.cnt + b.cnt;
c.mx = max(a.mx, b.mx);
c.L = min(a.L, b.L); c.R = max(a.R, b.R);
if(a.cnt && b.cnt && a.R + < b.L) {
int p = (b.L + a.R) / ;
c.mx = max(c.mx, mk(min(b.L - p, p - a.R), -p));
}
return c;
} void build(int l, int r, int rt) {
if(l == r) {
a[rt].cnt = ;
a[rt].L = inf;
a[rt].R = -inf;
a[rt].mx = mk(, );
return;
}
int mid = l + r >> ;
build(lson); build(rson);
a[rt] = a[rt << ] + a[rt << | ];
} void update(int p, int op, int l, int r, int rt) {
if(l == r) {
if(op == ) {
a[rt].cnt = ;
a[rt].L = a[rt].R = p;
a[rt].mx = mk(, );
} else {
a[rt].cnt = ;
a[rt].L = inf;
a[rt].R = -inf;
a[rt].mx = mk(, );
}
return;
}
int mid = l + r >> ;
if(p <= mid) update(p, op, lson);
else update(p, op, rson);
a[rt] = a[rt << ] + a[rt << | ];
} int main() {
scanf("%d%d", &n, &m);
build(, n, );
while(m--) {
int op, x;
scanf("%d%d", &op, &x);
if(op == ) {
tot = ;
if(a[].mx.se) gg[tot++] = a[].mx;
if(a[].L != && a[].cnt) gg[tot++] = mk(a[].L - , -);
if(a[].R != n && a[].cnt) gg[tot++] = mk(n - a[].R, -n);
if(!tot) gg[tot++] = mk(inf, -);
sort(gg, gg + tot);
reverse(gg, gg + tot);
pos[x] = -gg[].se;
update(-gg[].se, , , n, );
printf("%d\n", -gg[].se); } else {
update(pos[x], -, , n, );
}
}
return ;
} /*
*/

Codeforces 219E Parking Lot 线段树的更多相关文章

  1. Buses and People CodeForces 160E 三维偏序+线段树

    Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...

  2. CodeForces 877E DFS序+线段树

    CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身 ...

  3. [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)

    [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...

  4. [Codeforces 1199D]Welfare State(线段树)

    [Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...

  5. [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)

    [Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...

  6. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  7. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  8. codeforces 383C Propagating tree 线段树

    http://codeforces.com/problemset/problem/383/C 题目就是说,  给一棵树,将一个节点的值+val, 那么它的子节点都会-val, 子节点的子节点+val. ...

  9. CodeForces 228D. Zigzag(线段树暴力)

    D. Zigzag time limit per test 3 seconds memory limit per test 256 megabytes input standard input out ...

随机推荐

  1. python-模块入门

    一.模块介绍 模块:模块就是一系列功能的集合体 模块有三种来源: 1.内置模块   2.第三方的模块   3.自定义模块 模块的格式: 1使用python编写的.py文件   2.已被编译为共享库或D ...

  2. f11 全屏

    function fullScreen() { var el = document.documentElement; var rfs = el.requestFullScreen || el.webk ...

  3. django模板 内建标签

    autoescape 控制当前自动转义的行为,有on和off两个选项 {% autoescape on %} {{ body }} {% endautoescape %} block 定义一个子模板可 ...

  4. xilinx_all_version.lic

    INCREMENT ISE_Vivado_Seth xilinxd -dec- uncounted \ C25FB036D304 VENDOR_STRING=License_Type:Bought H ...

  5. day06 数字类型,字符串类型,列表类型

    一:整型int# ======================================基本使用======================================# 1.用途:记录年龄 ...

  6. JPA环境配置

    JPA概述 JPA(Java Persistence API)的简称,用于持久化的API. JAVAEE5.0平台标准的ORM的规范使得应用程序以统一的方式访问持久层. JPA和Hibernate的关 ...

  7. LeetCode(71):简化路径

    Medium! 题目描述: 给定一个文档 (Unix-style) 的完全路径,请进行路径简化. 例如,path = "/home/", => "/home&quo ...

  8. js 判断输入的内容是否是整数

    需求简介:列表有一列排序,其值只能是整数,不能是小数,在js中判断,并给出提示 解决思路:在js中先获取表单的值,然后用isNaN,然后查一下怎么把小数排除在外.我靠( ‵o′)凸,这只能算是半路把! ...

  9. PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /usr/local/php/CreateDB.php on line 5

    原因:php还不支持mysql8.0最新的密码加密方式 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ' ...

  10. Client-Side Attacks

    1.之前看到中间人攻击方式,要使用ssl服务构架一个劫持会话,使得攻击者和被攻击者客户端连接.ssl 服务(secure Socket Layer安全套接) ,以及后续出现的TSL(Transport ...