当前位置:网站首页>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;
}
边栏推荐
- 【软考软件评测师】基于规则说明的测试技术上篇
- 如何把Excel表格显示到邮件正文里?
- R语言使用aov函数进行单因素协方差分析(One-way ANCOVA)、使用effects包中的effect函数来计算调整后的分组均值(calculate adjusted means)
- jsArray array copy method performance test 2207292307
- libudev manual
- Learning notes - 7 weeks as data analyst "in the first week: data analysis of thinking"
- ENVI Image Processing (6): NDVI and Vegetation Index
- Logic Vulnerability----Permission Vulnerability
- 基于反步积分滑模摩擦补偿的光电伺服转台控制
- 05 | 后台登录:基于账号密码的登录方式(下)
猜你喜欢
随机推荐
外包干了七年,废了。。。
ENVI Image Processing (6): NDVI and Vegetation Index
Hand tearing read-write lock performance test
shell脚本流程控制语句
R语言ggstatsplot包grouped_ggwithinstats函数可视化分组小提琴图、并添加假设检验结果(包含样本数、统计量、效应大小及其置信区间、显著性、组间两两比较、贝叶斯假设)
Using Baidu EasyDL to realize the recognition of the chef's hat of the bright kitchen
【23考研】408代码题参考模板——顺序表
【Advanced Mathematics】【7】Double Integral
群晖系统安装相关文件分享
【河北工业大学】考研初试复试资料分享
TaskDispatcher source code parsing
How to migrate the device data connected by RTSP of EasyCVR platform to EasyNVR?
重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践
dolphinscheduler adds hana support
dbaplus丛书丨《MySQL DBA工作笔记》限量签名版来了!
EasyNVS cloud management platform function reconstruction: support for adding users, modifying information, etc.
腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
el-table中el-table-column下的操作切换class样式
展厅全息投影所具备的三大应用特点









