当前位置:网站首页>CF338E Optimize!
CF338E Optimize!
2022-07-30 13:40:00 【With a cool moon】
CF338E Optimize!
任意匹配,考虑将 B B B 排序, B B B The largest and A A A The smallest match in , B B B medium and large with A A A Small and medium matches,依次类推.
若满足条件,等价于 B B B The largest of them can at least match A A A 中 l e n len len 个可以匹配, B B B The middle and second largest can at least match A A A 中 l e n − 1 len-1 len−1 个匹配,依次类推.
Consider line segment tree set scanline maintenance,When adding or deleting numbers, the maintenance interval is added or subtracted by one,Globally ask for the minimum value.
时间复杂度 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;
}
边栏推荐
- 20220729 证券、金融
- no matching host key type found. Their offer: ssh-rsa
- Smart pointer implementation conjecture
- 第十五天笔记
- 一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
- SQL 26 calculation under 25 years of age or older and the number of users
- Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
- 程序员修炼之道:务以己任,实则明心——通向务实的最高境界
- Decoding Redis' most overlooked high CPU and memory usage issues
- Mac Brew 安装PHP
猜你喜欢
数据中台建设(五):打破企业数据孤岛和提取数据价值
如何判断自己是否适合IT行业?方法很简单
jsArray数组复制方法性能测试2207300040
SQL 26 calculation under 25 years of age or older and the number of users
ENVI Image Processing (6): NDVI and Vegetation Index
一本通循环结构的程序设计题解(2)
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践
外包干了七年,废了。。。
TaskDispatcher源码解析
随机推荐
AT4108 [ARC094D] Normalization
R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
ARC117E Zero-Sum Ranges 2
一本通循环结构的程序设计题解(2)
缓存
如何把Excel表格显示到邮件正文里?
【Advanced Mathematics】【7】Double Integral
【Pytorch】如何在关闭batch-norm的同时保持Dropout的开启
BUUCTF刷题十一道(06)
缓存一致性
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
C语言学习练习题:汉诺塔(函数与递归)
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
判断链表是否有环
EasyNVS云管理平台功能重构:支持新增用户、修改信息等
How to solve the problem that the page does not display the channel configuration after the EasyNVR is updated to (V5.3.0)?
Hand tearing read-write lock performance test
永州动力电池实验室建设合理布局方案
DeFi 巨头进军 NFT 领域 用户怎么看?