当前位置:网站首页>CF780G Andryusha and Nervous Barriers
CF780G Andryusha and Nervous Barriers
2022-07-30 13:40:00 【With a cool moon】
CF780G Andryusha and Nervous Barriers
考虑树套树.
One-dimensional maintenance interval column,Another dimension maintains the height of the ball on the column,Make sure the points are correct.
maintenance single point,区间查.
The situation when the scan line height is maintained to each board from large to small.
优化:The interval check is to judge that the minimum height of the interval ball can only pass through the baffle and end.
时间复杂度 O ( n log 2 n ) \mathcal O(n\log^2n) O(nlog2n).
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define ha putchar(' ')
#define he putchar('\n')
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
const int _ = 1e5 + 10, mod = 1e9 + 7;
int h, w, n, N;
ll ans[_ << 2];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q[_];
struct abc {
int u, l, r, s;
bool operator < (const abc &t) const {
return u > t.u;
}
} k[_];
void build(int o, int l, int r) {
if (l == r) {
q[l].push({
h + 1, 1});
ans[o] = h + 1;
return;
}
int mid = (l + r) >> 1;
build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
ans[o] = min(ans[o << 1], ans[o << 1 | 1]);
}
void upd(int o, int l, int r, int pos, int p, int h) {
if (l == r) {
q[l].push({
h, p});
ans[o] = min(ans[o], (ll)h);
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) upd(o << 1, l, mid, pos, p, h);
else upd(o << 1 | 1, mid + 1, r, pos, p, h);
ans[o] = min(ans[o << 1], ans[o << 1 | 1]);
}
int qry(int o, int l, int r, int L, int R, int h, int s) {
if (ans[o] > h + s) return 0;
if (l == r) {
int res = 0;
while (!q[l].empty() && q[l].top().first <= h + s) {
res = (res + q[l].top().second) % mod;
q[l].pop();
}
ans[o] = q[l].empty() ? 1e10 + 7 : q[l].top().first;
return res;
}
int mid = (l + r) >> 1, res = 0;
if (L <= mid) res = qry(o << 1, l, mid, L, R, h, s);
if (R > mid) res = (res + qry(o << 1 | 1, mid + 1, r, L, R, h, s)) % mod;
ans[o] = min(ans[o << 1], ans[o << 1 | 1]);
return res;
}
signed main() {
h = read(), w = read(), n = read();
for (int i = 1; i <= n; ++i) k[i].u = read(), k[i].l = read(), k[i].r = read(), k[i].s = read();
N = w;
build(1, 1, w);
sort(k + 1, k + n + 1);
for (int i = 1; i <= n; ++i) {
int t = qry(1, 1, w, k[i].l, k[i].r, k[i].u, k[i].s);
N = (N + t) % mod;
if (k[i].l == 1) upd(1, 1, w, k[i].r + 1, (t << 1) % mod, k[i].u);
else if (k[i].r == w) upd(1, 1, w, k[i].l - 1, (t << 1) % mod, k[i].u);
else {
upd(1, 1, w, k[i].l - 1, t, k[i].u);
upd(1, 1, w, k[i].r + 1, t, k[i].u);
}
}
write(N), he;
return 0;
}
边栏推荐
- “12306” 的架构到底有多牛逼
- SQL 26 calculation under 25 years of age or older and the number of users
- 元宇宙的六大支撑技术
- 二手手机销量突破3亿部,与降价的iPhone夹击国产手机
- (HR面试)最常见的面试问题和技巧性答复
- What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?
- ES6 Set与Map是什么,如何使用
- R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
- Hand tearing read-write lock performance test
- Analysis of AI recognition technology and application scenarios of TSINGSEE intelligent video analysis gateway
猜你喜欢

Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线

The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism

第十三天笔记

【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求

js人均寿命和GDP散点图统计样式

svg波浪动画js特效代码

一本通循环结构的程序设计题解(2)

戴墨镜的卡通太阳SVG动画js特效

There is a risk of water ingress in the battery pack tray and there is a potential safety hazard. 52,928 Tang DMs are urgently recalled

shell 编程规范与变量
随机推荐
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
No-code development platform all application settings introductory tutorial
shell脚本流程控制语句
grep时排除指定的文件和目录
EasyNVS cloud management platform function reconstruction: support for adding users, modifying information, etc.
js男女身高体重关系图
当下,产业园区发展面临的十大问题
Logic Vulnerability----Permission Vulnerability
libudev manual
CF338E Optimize!
shell script flow control statement
CF780G Andryusha and Nervous Barriers
SyntaxError: EOL while scanning string literal
永州动力电池实验室建设合理布局方案
How to solve the problem that the page does not display the channel configuration after the EasyNVR is updated to (V5.3.0)?
创意loadingjs特效小点跳跃动画
jsArray数组复制方法性能测试2207292307
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
学习笔记——七周成为数据分析师《第二周:业务》:业务分析指标
for循环的3个表达式执行顺序