当前位置: 首页 > news >正文

AtCoder Beginner Contest 430

D - Neighbor Distance

set模拟

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define ft first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define int long longconst int N = 500010;
int a[N];
void solve(){
int n; cin >> n;
int ans = 0;
set<pii> s; s.insert({0, 0}); s.insert({1e18, -1});for(int i = 1; i <= n; i ++){int x; cin >> x;if(i == 1){a[0] = x; ans += x;}auto t1 = s.lower_bound({x, -1});auto t = t1; t --;int tf = (*t).ft;int t1f = (*t1).ft;int ts = (*t).se; int t1s = (*t1).se;if(ts != -1){if(a[ts] > x - tf){ans += x - tf - a[ts];a[ts] = x - tf;}}if(t1s != -1){if(a[t1s] > t1f - x){ans += t1f - x - a[t1s];a[t1s] = t1f -x;}}a[i] = min(x - tf, t1f - x);ans += a[i];s.insert({x,i});cout << ans << '\n';
}}
signed main(){std::ios::sync_with_stdio(false);int T=1;//cin>>T;while(T--){solve();}
}

F - Back and Forth Filling

每个可能的位置是[ls+1, n-rs]

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define ft first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define int long longconst int N = 500010;
int a[N];
void solve(){
int n; cin >> n;
int ans = 0;
set<pii> s; s.insert({0, 0}); s.insert({1e18, -1});for(int i = 1; i <= n; i ++){int x; cin >> x;if(i == 1){a[0] = x; ans += x;}auto t1 = s.lower_bound({x, -1});auto t = t1; t --;int tf = (*t).ft;int t1f = (*t1).ft;int ts = (*t).se; int t1s = (*t1).se;if(ts != -1){if(a[ts] > x - tf){ans += x - tf - a[ts];a[ts] = x - tf;}}if(t1s != -1){if(a[t1s] > t1f - x){ans += t1f - x - a[t1s];a[t1s] = t1f -x;}}a[i] = min(x - tf, t1f - x);ans += a[i];s.insert({x,i});cout << ans << '\n';
}}
signed main(){std::ios::sync_with_stdio(false);int T=1;//cin>>T;while(T--){solve();}
}
http://www.gsyq.cn/news/54182.html

相关文章:

  • SQL Server 2025 正式版发布 - 从本地到云端的 AI 就绪企业数据库
  • 虚拟机上redhat7.2安装oracle 11g
  • SLS 脱敏函数实践:智能化与数据安全的融合
  • PVE9安装R8125 2.5G网卡驱动、开启缓冲区、开启硬件多队列支持(基于联想来酷MiniPro)
  • 2025年吨包醋酸钠定制厂家权威推荐榜单:‌工业级乙酸钠/醋酸钠乙酸钠/醋酸钠乙酸钠源头厂家精选
  • 2025 最新钢管设备厂家权威推荐榜:3PE 防腐 / 抛丸除锈 / 涂塑喷粉设备综合测评重磅发布内壁抛丸除锈设备/涂塑设备,防腐设备,粉末喷涂设备,内外壁喷粉设备,抛丸除锈设备公司推荐
  • 2025 最新管道设备供应厂家口碑推荐榜:聚焦 3PE / 除锈 / 涂塑设备,精选品牌权威测评推荐管道除锈设备/管道涂塑设备/管道内壁喷粉设备/管道涂塑设备公司推荐
  • 2025年人参皂苷化学对照品源头厂家权威推荐榜单:维生素K2化学对照品/蜕皮激素化学对照品/麦角甾醇化学对照品源头厂家精选
  • 2025年警用指挥车供货厂家权威推荐榜单:越野应急指挥车/全顺无人机指挥车/双拓展指挥车源头厂家精选
  • 联想小新pad 2025刷机包下载(TB335FC刷机包)
  • 2025年滴灌过滤设备优质厂家权威推荐榜单:全自动砂石过滤器/农业离心过滤器/滴灌过滤器源头厂家精选
  • imu_tk阅读笔记
  • Docker 安装 Oracle 11g
  • linux do while
  • ICPC2025沈阳 游记
  • AVLT
  • 一线操作工也能管能耗?MyEMS 的 “傻瓜式仪表盘”,把专业数据变成 “大白话”
  • 2025年【口碑好的/比较好的/靠谱的】工业级/国产化/变电站/变电站/电力/机房/光伏/远动/发电厂/工业级/嵌入式机柜/通讯管理机【公司/工厂/厂家】推荐/排行榜 哪家好/强/靠谱
  • linux dmesg
  • linux dns 服务器 搭建
  • 双指针的“适用边界”:从直方图最大矩形错误,看透三大经典问题的本质差异
  • linux dia
  • linux dhcp服务器配置
  • 一文讲清,生产质量管理的10大核心指标及公式
  • CSharp_Winform控件学习_Winform 上加ToolStrip时图标大小调整
  • oracle 查看定义语句
  • linux dhcp服务器的配置
  • 2025 年 11 月碳化钨(WC/C)涂层厂家推荐排行榜,碳化钨涂层,WC/C 涂层,耐磨碳化钨涂层,耐腐蚀碳化钨涂层公司推荐
  • jenkins docker 启动记录
  • Substance Designer的通道合并(Channel Packing)自动化工作流 - 教程