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 ...
随机推荐
- Java面向对象——类,对象和方法
1.类的概念 在生活中,说到类,可以联想到类别,同类,会想到一类人,一类事物等等.而这一类人或事物都是具有相同特征或特点和行为的,我们根据不同的特征或特点和行为将他们归类或分类.同时,当我们认识一个新 ...
- python类与对象-如何派生内置不可变类型并修其改实例化行为
如何派生内置不可变类型并修其改实例化行为 问题举例 自定义一种新类型的元组,对传入的可迭代对象,我们只保留 其中int类型且值大于0的元素,例如 IntTuple([1, -1, 'abc', 6, ...
- turtle模块绘图
import turtle #运动命令 # forward(d) 向前移动d长度 # backward(d) 向后移动d长度 # right(d) 向右转动多少度 #left(d) 向左转动多少度 # ...
- MyEclipse的JPA实现集成EasyJF+Spring
该视频是演示MyEclipse的JPA实现集成EasyJF+Spring的示例视频.演示项目很小,仅实现基本的查询功能. 演示过程中难免有误,请各位朋友热心指导! gh发给梵蒂冈地方fgh
- html5 css练习 定位布局
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- 软件工程实践助教每周小结 < 福州大学 | 傅明建 >
第一周助教小结 1. 助教博客链接: http://www.cnblogs.com/sinceway/ 2. 本周点评的作业数量:约22份,有多次交互 3. 本周点评有困难的作业链接: https:/ ...
- MyBatis探究-----配置数据源的几种方式
1.在核心配置文件mybatis-config.xml中配置数据库连接信息 mysql的j驱动jar包是mysql-connector-java-6.0.6.jar mysql版本5.7 <?x ...
- [NOIP赛前冲刺第一期]初赛基础知识归纳
关于计算机 1.CPU 中央处理器(CPU,Central Processing Unit)是一块超大规模的集成电路,是一台计算机的运算核心(Core)和控制核心(Control Unit).它的功能 ...
- web接口文档apidoc的使用
1.安装 npm install apidoc -g 2.新建src文件夹,里面放2个文件,test.js和apidoc.json 3.test.js /** * @api {get} /query_ ...
- jmeter中文乱码及Unicode转中文
在测试的过程中传入中文测试,乱码问题 1.get请求传入中文参数address:中国云南省 request请求中已经正确显示参数(可能跟我之前配置过有关系),如果没有正确显示,在http取样器后面新建 ...