当前位置:网站首页>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;
}
边栏推荐
- Parallelized Quick Sort Ideas
- Decoding Redis' most overlooked high CPU and memory usage issues
- What is the level of Ali P7?
- How to migrate the device data connected by RTSP of EasyCVR platform to EasyNVR?
- R语言使用aov函数进行单因素协方差分析(One-way ANCOVA)、使用effects包中的effect函数来计算调整后的分组均值(calculate adjusted means)
- Composer安装方式
- Dolphinscheduler stand-alone transformation
- Heshu Group: Make smart cities smarter and make real life better
- SyntaxError: EOL while scanning string literal
- 第十五天笔记
猜你喜欢

What is the level of Ali P7?

shell脚本流程控制语句

Yilian: Activating the Value Potential of Data Elements and Unleashing the Innovation Dividend of SAS SSD

There is no one of the strongest kings in the surveillance world!

C语言学习练习题:汉诺塔(函数与递归)

如何判断自己是否适合IT行业?方法很简单

监控界的最强王者,没有之一!

Decoding Redis' most overlooked high CPU and memory usage issues

canvas彩虹桥动画js特效

Using Baidu EasyDL to realize the recognition of the chef's hat of the bright kitchen
随机推荐
PyQt5快速开发与实战 8.6 设置样式
自动化测试的生命周期是什么?
jsArray array copy method performance test 2207300040
434. 字符串中的单词数
Mysql batch insert transaction unique key repeated processing
【高等数学】【7】二重积分
libudev 使用说明书
dbaplus丛书丨《MySQL DBA工作笔记》限量签名版来了!
20220729 Securities, Finance
05 | login background: based on the password login mode (below)
SyntaxError: EOL while scanning string literal
curl 执行脚本时传递环境变量与参数
打破原则引入SQL,MongoDB到底想要干啥???
在 Scala 中读取整个文件
【23考研】408代码题参考模板——顺序表
for循环的3个表达式执行顺序
12、 学习MySQL 排序
智能指针实现猜想
Hand tearing read-write lock performance test
dolphinscheduler简单任务定义及复杂的跨节点传参