当前位置:网站首页>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;
}
边栏推荐
- Hu-cang integrated e-commerce project (1): project background and structure introduction
- [PostgreSQL] - Storage structure and cache shared_buffers
- Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
- 重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(ylim、修改可视化图像y轴坐标轴数值范围)
- C语言学习练习题:汉诺塔(函数与递归)
- 如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
- 人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
- R语言ggplot2可视化时间序列数据(默认时间中断部分前后自动连接起来)、创建时间分组、使用分面图(faceting)可视化时间序列数据
- [PostgreSQL] - explain SQL analysis introduction
猜你喜欢

【ROS进阶篇】第十一讲 基于Gazebo和Rviz的机器人联合仿真(运动控制与传感器)

leetcode207.课程表(判断有向图是否有环)

jsArray array copy method performance test 2207300040

第十三天笔记

js背景切换时钟js特效代码

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

学习笔记——七周成为数据分析师《第一周:数据分析思维》

【高等数学】【7】二重积分

SyntaxError: EOL while scanning string literal

05 | login background: based on the password login mode (below)
随机推荐
深度操作系统DeepinOS安装步骤和MySQL安装测试
CF603E Pastoral Oddities
Current and voltage acquisition module DAM-6160
权威推荐!腾讯安全DDoS边缘安全产品获国际研究机构Omdia认可
学习笔记——七周成为数据分析师《第一周:数据分析思维》
cpu/CS and IP
[PostgreSQL] - explain SQL analysis introduction
ENVI图像处理(6):NDVI和植被指数
Composer安装方式
jsArray array copy method performance test 2207292307
Learning notes - 7 weeks as data analyst "in the first week: data analysis of thinking"
TaskDispatcher源码解析
R语言ggstatsplot包grouped_ggwithinstats函数可视化分组小提琴图、并添加假设检验结果(包含样本数、统计量、效应大小及其置信区间、显著性、组间两两比较、贝叶斯假设)
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)
Hand tearing read-write lock performance test
ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略
grep时排除指定的文件和目录
“封号斗罗” 程序员修炼之道:通向务实的最高境界
05 | 后台登录:基于账号密码的登录方式(下)