当前位置:网站首页>CF780G Andryusha and Nervous Barriers
CF780G Andryusha and Nervous Barriers
2022-07-30 13:17:00 【心怀凉月】
CF780G Andryusha and Nervous Barriers
考虑树套树。
一维维护区间列,另一维维护列上的球的高度,保证点数正确。
维护单点加,区间查。
扫描线高度从大到小维护到每一个板时的情况。
优化:区间查是判区间球高度最小都只能穿过挡板就结束掉。
时间复杂度 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;
}
边栏推荐
- There is no one of the strongest kings in the surveillance world!
- 12、 学习MySQL 排序
- 元宇宙的六大支撑技术
- DeFi 巨头进军 NFT 领域 用户怎么看?
- CV-Model【2】:MobileNet v1
- matlab画图,仅显示部分图例
- 干货分享:小技巧大用处之Bean管理类工厂多种实现方式
- Current and voltage acquisition module DAM-6160
- Anaconda\Scripts\pip-script.py is not present ? 解决方案
- EasyNVS云管理平台功能重构:支持新增用户、修改信息等
猜你喜欢
【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求
【语音识别】基于GMM-HMM的语音识别系统
Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
PyQt5快速开发与实战 8.6 设置样式
jsArray数组复制方法性能测试2207300823
Greenplum 6.0有哪些不可错过的硬核升级与应用?
当下,产业园区发展面临的十大问题
DeFi 巨头进军 NFT 领域 用户怎么看?
ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略
Why is Prometheus a monitoring artifact sufficient to replace Zabbix?
随机推荐
datax开启hana支持以及dolphinscheduler开启datax任务
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
no matching host key type found. Their offer: ssh-rsa
Eleven BUUCTF questions (06)
【自校正控制】自校正PID
qq udp tcp机制
权威推荐!腾讯安全DDoS边缘安全产品获国际研究机构Omdia认可
R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?
R语言向前或者向后移动时间序列数据(自定义滞后或者超前的期数):使用dplyr包中的lag函数将时间序列数据向后移动一天(设置参数n为负值)
监控界的最强王者,没有之一!
一本通循环结构的程序设计题解(2)
for循环的3个表达式执行顺序
matlab画图,仅显示部分图例
leetcode207.课程表(判断有向图是否有环)
EasyNVS云管理平台功能重构:支持新增用户、修改信息等
树形dp小总结(换根,基环树,杂七杂八的dp)
每天学一点Scala之 伴生类和伴生对象
忆联:激活数据要素价值潜能,释放SAS SSD创新红利
阿里 P7 到底是怎样的水平?