当前位置:网站首页>CF338E Optimize!
CF338E Optimize!
2022-07-30 13:17:00 【心怀凉月】
CF338E Optimize!
任意匹配,考虑将 B B B 排序, B B B 中最大的与 A A A 中最小的匹配, B B B 中次大的与 A A A 中次小的匹配,依次类推。
若满足条件,等价于 B B B 中最大的至少可以与 A A A 中 l e n len len 个可以匹配, B B B 中次大的至少可以与 A A A 中 l e n − 1 len-1 len−1 个匹配,依次类推。
考虑线段树套扫描线维护,加删数时维护区间加减一,全局询问最小值。
时间复杂度 O ( n log n ) \mathcal O(n\log n) O(nlogn)。
#include<bits/stdc++.h>
using namespace std;
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 _ = 2e5 + 10;
int n, len, h, a[_], b[_], tr[_ << 2], tag[_ << 2];
void pushdown(int o)
{
tr[o << 1] += tag[o];
tr[o << 1 | 1] += tag[o];
tag[o << 1] += tag[o];
tag[o << 1 | 1] += tag[o];
tag[o] = 0;
}
void upd(int o, int l, int r, int L, int R, int v)
{
if(L <= l && r <= R)
{
tr[o] += v, tag[o] += v;
return;
}
pushdown(o);
int mid = (l + r) >> 1;
if(L <= mid) upd(o << 1, l, mid, L, R, v);
if(R > mid) upd(o << 1 | 1, mid + 1, r, L, R, v);
tr[o] = min(tr[o << 1], tr[o << 1 | 1]);
}
signed main() {
n = read(), len = read(), h = read();
for (int i = 1; i <= len; ++i) b[i] = read();
sort(b + 1, b + len + 1);
for (int i = 1; i <= n; ++i) {
a[i] = read();
a[i] = lower_bound(b + 1, b + len + 1, h - a[i]) - b;
}
for (int i = 1; i <= len; i++) upd(1, 1, len, i, i, -i);
for (int i = 1; i < len; i++) upd(1, 1, len, a[i], len, 1);
int ans = 0;
for (int i = len; i <= n; i++) {
upd(1, 1, len, a[i], len, 1);
if (tr[1] >= 0) ans++;
upd(1, 1, len, a[i - len + 1], len, -1);
}
write(ans), he;
return 0;
}
边栏推荐
- 当下,产业园区发展面临的十大问题
- TaskDispatcher source code parsing
- SQL 26 calculation under 25 years of age or older and the number of users
- 展厅全息投影所具备的三大应用特点
- 腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
- BUUCTF刷题十一道(06)
- EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?
- 监控界的最强王者,没有之一!
- Mysql 批量插入事务唯一键重复处理
- 如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
猜你喜欢
随机推荐
学习笔记——七周成为数据分析师《第二周:业务》:业务分析指标
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化(平方、开平方、指数化等函数类似使用)
datax enables hana support and dolphinscheduler enables datax tasks
Markdown 1 - 图文音视频等
当下,产业园区发展面临的十大问题
R语言ggplot2可视化时间序列数据(默认时间中断部分前后自动连接起来)、创建时间分组、使用分面图(faceting)可视化时间序列数据
基于反步积分滑模摩擦补偿的光电伺服转台控制
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
缓存一致性
浅析TSINGSEE智能视频分析网关的AI识别技术及应用场景
[PostgreSQL] - Storage structure and cache shared_buffers
grep时排除指定的文件和目录
EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?
手慢无!阿里亿级流量高并发系统设计核心原理全彩笔记现实开源
dolphinscheduler adds hana support
How to display an Excel table in the body of an email?
群晖系统安装相关文件分享
no matching host key type found. Their offer: ssh-rsa
libudev manual
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)