当前位置:网站首页>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;
}
边栏推荐
- Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
- Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
- 腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
- 程序员修炼之道:务以己任,实则明心——通向务实的最高境界
- Scala基础:数组(Array)、映射(Map)、元组(Tuple)、集合(List)
- 判断链表是否有环
- The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism
- 域名抢注“卷”到了表情包?ENS逆势上涨的新推力
- js人均寿命和GDP散点图统计样式
- canvas彩虹桥动画js特效
猜你喜欢
随机推荐
Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
Analysis of AI recognition technology and application scenarios of TSINGSEE intelligent video analysis gateway
CF338E Optimize!
学习笔记——七周成为数据分析师《第一周:数据分析思维》
在 Scala 中读取整个文件
How to solve the problem that the page does not display the channel configuration after the EasyNVR is updated to (V5.3.0)?
ENVI图像处理(6):NDVI和植被指数
群晖系统安装相关文件分享
IDEA 重复代码快速重构(抽取重复代码快捷键)
shell 编程规范与变量
20220729 Securities, Finance
js背景切换时钟js特效代码
剑指 Offer 05. 替换空格
数据中台建设(五):打破企业数据孤岛和提取数据价值
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
AT4108 [ARC094D] Normalization
域名抢注“卷”到了表情包?ENS逆势上涨的新推力
for循环的3个表达式执行顺序
Mac Brew 安装PHP
svg波浪动画js特效代码









