HDU 6521 Party
思路:
线段树玄学剪枝, 俗称吉司机线段树。
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
//#define mp make_pair
#define pb push_back
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdi pair<double, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head const int N = 5e5 + ;
LL sum[N<<];
int mn[N<<];
int n, m, l, r;
void push_up(int rt) {
mn[rt] = min(mn[rt<<], mn[rt<<|]);
sum[rt] = sum[rt<<] + sum[rt<<|];
}
void build(int rt, int l, int r) {
if(l == r) {
sum[rt] = ;
mn[rt] = l;
return ;
}
int m = l+r >> ;
build(ls);
build(rs);
push_up(rt);
}
LL query(int L, int R, int rt, int l, int r) {
LL ans = ;
if(mn[rt] >= R) return ;
if(l == r) {
ans = R-mn[rt];
mn[rt] = R;
return ans;
}
int m = l+r >> ;
if(L <= m) ans += query(L, R, ls);
if(R > m) ans += query(L, R, rs);
push_up(rt);
return ans;
}
int main() {
while(~scanf("%d %d", &n, &m)) {
build(, , n);
for (int i = ; i <= m; ++i) {
scanf("%d %d", &l, &r);
printf("%lld\n", query(l, r, , , n));
}
}
return ;
}
HDU 6521 Party的更多相关文章
- HDU - 6521 Party (SYSU校赛K题)(线段树)
题目链接 题意:n个人排成一列,一开始他们互不认识,每次选[l,r]上的人开party,使他们互相认识,求出每次party之后新互相认识的人的对数. 思路:把“互相认识”变成单向连边,只考虑左边的人对 ...
- HDU 6521 K-th Closest Distance (主席树+二分)
题意: 给你一个数组,q次询问,每次问你[l,r]范围内与p距离第k大的元素的与p的距离,强制在线 思路: 主席树提取出[l,r]内的权值线段树,然后二分与p的距离mid ask该权值线段树里[p-m ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- sping Bean 的生命周期是如何被管理
1. 实例化一个Bean,也就是我们通常说的new 2. 按照Spring上下文对实例化的Bean进行配置,也就是IOC注入 3. 如果这个Bean实现了BeanNameAware接口,会调用它实现的 ...
- linux----------fedora 27 如何启用输入法
1.安装完成以后是自带了输入法的,但是需要启用. 一定要放到第一个位置,然后注销或者重启.
- 关于使用CodeFirst,修改类或上下文时操作数据库报错解决方法
在操作已经创建好的数据库时,若是添加新的实体类或者修改原有数据库上下文,会报如下错误: The model backing the 'StudentDbContext' context has cha ...
- CentOS 7 MySQL HA之DRBD
一.DRBD简介 DRBD的全称为:Distributed ReplicatedBlock Device(DRBD)分布式块设备复制,DRBD是由内核模块和相关脚本而构成,用以构建高可用性的集群.其实 ...
- 使用python连接mysql/oracle
最近python比较火,我本身觉得python这种语言速度也不快,做项目也一般,学他干啥?但是了解到python把其他语言的函数封装成了自己的包,用python就可以直接调用,感觉python还是值得 ...
- 宏开发:excel中添加拼接行
Sub 万途标签()Dim iFor i = 1 To Sheets.Count If Sheets(i).Name = "数据表" Then If MsgBo ...
- Pytrhon结束死循环的子线程
Python在子线程无线循环的过程中,如果直接ctrl+c结束程序的话,虽然程序可以结束,但是会导致子线程资源无法回收,一般情况不会有太大影响,但是使用TCP通信的时候,子线程是占用特定的端口的,在资 ...
- js字母/字符与ASCII码转换
var tempStr="A"; console.log(tempStr.charCodeAt());// 65 ,转ASCII码 console.log(String.fromC ...
- ELK学习笔记之logstash安装logstash-filter-multiline(在线离线安装)
0x00 概述 ELK-logstash在搬运日志的时候会出现多行日志,普通的搬运会造成保存到ES中单条单条,很丑,而且不方便读取,logstash-filter-multiline可以解决该问题 g ...
- springboot+mybatis环境的坑和sql语句简化技巧
1.springfox-swagger实体类无限递归 https://hacpai.com/article/1525674135818 里面有不完美的解决方案 不用动源码的解决方案也有,在swagge ...